blob: 268cb493f6a5496bf596d517b6bc62c348e6e9d9 [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
Johannes Berg7bdbe402015-08-15 22:39:49 +03006 * Copyright 2015 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Bergf84f7712013-11-14 17:14:45 +010035static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010037static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020038 struct genl_info *info);
39
Johannes Berg55682962007-09-20 13:09:35 -040040/* the netlink family */
41static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070042 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
43 .name = NL80211_GENL_NAME, /* have users key off the name instead */
44 .hdrsize = 0, /* no private header */
45 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040046 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020047 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020048 .pre_doit = nl80211_pre_doit,
49 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040050};
51
Johannes Berg2a94fe42013-11-19 15:19:39 +010052/* multicast groups */
53enum nl80211_multicast_groups {
54 NL80211_MCGRP_CONFIG,
55 NL80211_MCGRP_SCAN,
56 NL80211_MCGRP_REGULATORY,
57 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010058 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010059 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
60};
61
62static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010063 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
64 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
65 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
66 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
67 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010068#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010069 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#endif
71};
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073/* returns ERR_PTR values */
74static struct wireless_dev *
75__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040076{
Johannes Berg89a54e42012-06-15 14:33:17 +020077 struct cfg80211_registered_device *rdev;
78 struct wireless_dev *result = NULL;
79 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
80 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
81 u64 wdev_id;
82 int wiphy_idx = -1;
83 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg5fe231e2013-05-08 21:45:15 +020085 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg89a54e42012-06-15 14:33:17 +020087 if (!have_ifidx && !have_wdev_id)
88 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (have_ifidx)
91 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
92 if (have_wdev_id) {
93 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
94 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040095 }
96
Johannes Berg89a54e42012-06-15 14:33:17 +020097 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
98 struct wireless_dev *wdev;
99
100 if (wiphy_net(&rdev->wiphy) != netns)
101 continue;
102
103 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
104 continue;
105
Johannes Berg89a54e42012-06-15 14:33:17 +0200106 list_for_each_entry(wdev, &rdev->wdev_list, list) {
107 if (have_ifidx && wdev->netdev &&
108 wdev->netdev->ifindex == ifidx) {
109 result = wdev;
110 break;
111 }
112 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 result = wdev;
114 break;
115 }
116 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200117
118 if (result)
119 break;
120 }
121
122 if (result)
123 return result;
124 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400125}
126
Johannes Berga9455402012-06-15 13:32:49 +0200127static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200129{
Johannes Berg7fee4772012-06-15 14:09:58 +0200130 struct cfg80211_registered_device *rdev = NULL, *tmp;
131 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg5fe231e2013-05-08 21:45:15 +0200133 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg878d9ec2012-06-15 14:18:32 +0200135 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 !attrs[NL80211_ATTR_IFINDEX] &&
137 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200138 return ERR_PTR(-EINVAL);
139
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200141 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200143
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (attrs[NL80211_ATTR_WDEV]) {
145 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
146 struct wireless_dev *wdev;
147 bool found = false;
148
149 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
150 if (tmp) {
151 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200152 list_for_each_entry(wdev, &tmp->wdev_list, list) {
153 if (wdev->identifier != (u32)wdev_id)
154 continue;
155 found = true;
156 break;
157 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200158
159 if (!found)
160 tmp = NULL;
161
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164 rdev = tmp;
165 }
166 }
167
Johannes Berg878d9ec2012-06-15 14:18:32 +0200168 if (attrs[NL80211_ATTR_IFINDEX]) {
169 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800170 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200171 if (netdev) {
172 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800173 tmp = wiphy_to_rdev(
174 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200175 else
176 tmp = NULL;
177
Johannes Berg7fee4772012-06-15 14:09:58 +0200178 /* not wireless device -- return error */
179 if (!tmp)
180 return ERR_PTR(-EINVAL);
181
182 /* mismatch -- return error */
183 if (rdev && tmp != rdev)
184 return ERR_PTR(-EINVAL);
185
186 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
189
Johannes Berg4f7eff12012-06-15 14:14:22 +0200190 if (!rdev)
191 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200192
Johannes Berg4f7eff12012-06-15 14:14:22 +0200193 if (netns != wiphy_net(&rdev->wiphy))
194 return ERR_PTR(-ENODEV);
195
196 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200197}
198
199/*
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200202 *
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
205 */
206static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200207cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200208{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200209 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200210}
211
Johannes Berg55682962007-09-20 13:09:35 -0400212/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300213static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400214 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
215 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700216 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200217 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100218
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200219 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100221 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
224
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200225 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200230 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400231
232 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Eliad Pellere007b852011-11-24 18:13:56 +0200236 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
237 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100238
Johannes Bergb9454e82009-07-08 13:29:08 +0200239 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100240 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
241 .len = WLAN_MAX_KEY_LEN },
242 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
243 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
244 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200245 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200246 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100247
248 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
249 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
250 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
251 .len = IEEE80211_MAX_DATA_LEN },
252 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100254 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
255 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
256 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
257 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
258 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100260 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200261 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100262 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800263 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100264 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300265
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700266 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
267 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
268
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300269 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200272 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
273 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100274 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300275
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800276 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700277 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700278
Johannes Berg6c739412011-11-03 09:27:01 +0100279 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200280
281 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
282 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
283 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100284 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
285 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200286
287 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
288 .len = IEEE80211_MAX_SSID_LEN },
289 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
290 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200291 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300292 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300293 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300294 [NL80211_ATTR_STA_FLAGS2] = {
295 .len = sizeof(struct nl80211_sta_flag_update),
296 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300297 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300298 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
299 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200300 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
301 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
302 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200303 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100304 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100305 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
306 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100307 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
308 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200309 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200310 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
311 .len = IEEE80211_MAX_DATA_LEN },
312 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200313 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200314 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300315 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200316 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300317 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200319 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900320 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
321 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100322 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100323 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100324 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200325 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700326 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300327 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200328 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200329 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300330 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300331 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
332 .len = IEEE80211_MAX_DATA_LEN },
333 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530335 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300336 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530337 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300338 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
342 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300343 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100344 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200345 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
346 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700347 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800348 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
349 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
350 .len = NL80211_HT_CAPABILITY_LEN
351 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100352 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530353 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530354 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200355 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700356 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300357 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000358 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700359 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100360 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
361 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530362 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
363 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200364 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
365 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100366 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100367 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
368 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
369 .len = NL80211_VHT_CAPABILITY_LEN,
370 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200371 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
372 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
373 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300374 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200375 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
376 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
377 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300378 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
379 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530380 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
381 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200382 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100383 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100384 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800387 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
388 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200389 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
390 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530391 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200392 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300393 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300394 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300395 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
396 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
397 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300398 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200399 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200400 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200401 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200402 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500403 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200404 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400405};
406
Johannes Berge31b8212010-10-05 19:39:30 +0200407/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000408static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200409 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200410 [NL80211_KEY_IDX] = { .type = NLA_U8 },
411 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200412 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200413 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
414 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200415 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100416 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
417};
418
419/* policy for the key default flags */
420static const struct nla_policy
421nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
422 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
423 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200424};
425
Johannes Bergff1b6e62011-05-04 15:37:28 +0200426/* policy for WoWLAN attributes */
427static const struct nla_policy
428nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
429 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
431 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200433 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
435 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
436 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100437 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300438 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100439};
440
441static const struct nla_policy
442nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
443 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
444 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
445 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
446 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
447 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
448 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
449 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
450 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
451 },
452 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
453 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
454 },
455 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
456 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
457 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200458};
459
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700460/* policy for coalesce rule attributes */
461static const struct nla_policy
462nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
463 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
464 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
465 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
466};
467
Johannes Berge5497d72011-07-05 16:35:40 +0200468/* policy for GTK rekey offload attributes */
469static const struct nla_policy
470nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
471 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
472 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
473 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
474};
475
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300476static const struct nla_policy
477nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200478 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300479 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700480 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300481};
482
Avraham Stern3b06d272015-10-12 09:51:34 +0300483static const struct nla_policy
484nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
485 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
486 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
487};
488
Johannes Berg97990a02013-04-19 01:02:55 +0200489static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
490 struct netlink_callback *cb,
491 struct cfg80211_registered_device **rdev,
492 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100493{
Johannes Berg67748892010-10-04 21:14:06 +0200494 int err;
495
Johannes Berg67748892010-10-04 21:14:06 +0200496 rtnl_lock();
497
Johannes Berg97990a02013-04-19 01:02:55 +0200498 if (!cb->args[0]) {
499 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
500 nl80211_fam.attrbuf, nl80211_fam.maxattr,
501 nl80211_policy);
502 if (err)
503 goto out_unlock;
504
505 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
506 nl80211_fam.attrbuf);
507 if (IS_ERR(*wdev)) {
508 err = PTR_ERR(*wdev);
509 goto out_unlock;
510 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800511 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200512 /* 0 is the first index - add 1 to parse only once */
513 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200514 cb->args[1] = (*wdev)->identifier;
515 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200516 /* subtract the 1 again here */
517 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200518 struct wireless_dev *tmp;
519
520 if (!wiphy) {
521 err = -ENODEV;
522 goto out_unlock;
523 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800524 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200525 *wdev = NULL;
526
Johannes Berg97990a02013-04-19 01:02:55 +0200527 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
528 if (tmp->identifier == cb->args[1]) {
529 *wdev = tmp;
530 break;
531 }
532 }
Johannes Berg97990a02013-04-19 01:02:55 +0200533
534 if (!*wdev) {
535 err = -ENODEV;
536 goto out_unlock;
537 }
Johannes Berg67748892010-10-04 21:14:06 +0200538 }
539
Johannes Berg67748892010-10-04 21:14:06 +0200540 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200541 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200542 rtnl_unlock();
543 return err;
544}
545
Johannes Berg97990a02013-04-19 01:02:55 +0200546static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200547{
Johannes Berg67748892010-10-04 21:14:06 +0200548 rtnl_unlock();
549}
550
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100551/* IE validation */
552static bool is_valid_ie_attr(const struct nlattr *attr)
553{
554 const u8 *pos;
555 int len;
556
557 if (!attr)
558 return true;
559
560 pos = nla_data(attr);
561 len = nla_len(attr);
562
563 while (len) {
564 u8 elemlen;
565
566 if (len < 2)
567 return false;
568 len -= 2;
569
570 elemlen = pos[1];
571 if (elemlen > len)
572 return false;
573
574 len -= elemlen;
575 pos += 2 + elemlen;
576 }
577
578 return true;
579}
580
Johannes Berg55682962007-09-20 13:09:35 -0400581/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000582static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400583 int flags, u8 cmd)
584{
585 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000586 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400587}
588
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400589static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100590 struct ieee80211_channel *chan,
591 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400592{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200593 /* Some channels must be completely excluded from the
594 * list to protect old user-space tools from breaking
595 */
596 if (!large && chan->flags &
597 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
598 return 0;
599
David S. Miller9360ffd2012-03-29 04:41:26 -0400600 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
601 chan->center_freq))
602 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400603
David S. Miller9360ffd2012-03-29 04:41:26 -0400604 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
605 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
606 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200607 if (chan->flags & IEEE80211_CHAN_NO_IR) {
608 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
609 goto nla_put_failure;
610 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
611 goto nla_put_failure;
612 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100613 if (chan->flags & IEEE80211_CHAN_RADAR) {
614 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
615 goto nla_put_failure;
616 if (large) {
617 u32 time;
618
619 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
620
621 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
622 chan->dfs_state))
623 goto nla_put_failure;
624 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
625 time))
626 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100627 if (nla_put_u32(msg,
628 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
629 chan->dfs_cac_ms))
630 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100631 }
632 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400633
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100634 if (large) {
635 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
636 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
637 goto nla_put_failure;
638 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
639 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
640 goto nla_put_failure;
641 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
642 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
643 goto nla_put_failure;
644 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
645 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
646 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200647 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
648 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
649 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300650 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
651 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200652 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200653 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
654 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
655 goto nla_put_failure;
656 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
657 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
658 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100659 }
660
David S. Miller9360ffd2012-03-29 04:41:26 -0400661 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
662 DBM_TO_MBM(chan->max_power)))
663 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400664
665 return 0;
666
667 nla_put_failure:
668 return -ENOBUFS;
669}
670
Johannes Berg55682962007-09-20 13:09:35 -0400671/* netlink command implementations */
672
Johannes Bergb9454e82009-07-08 13:29:08 +0200673struct key_parse {
674 struct key_params p;
675 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200676 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200677 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100678 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200679};
680
681static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
682{
683 struct nlattr *tb[NL80211_KEY_MAX + 1];
684 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
685 nl80211_key_policy);
686 if (err)
687 return err;
688
689 k->def = !!tb[NL80211_KEY_DEFAULT];
690 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
691
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100692 if (k->def) {
693 k->def_uni = true;
694 k->def_multi = true;
695 }
696 if (k->defmgmt)
697 k->def_multi = true;
698
Johannes Bergb9454e82009-07-08 13:29:08 +0200699 if (tb[NL80211_KEY_IDX])
700 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
701
702 if (tb[NL80211_KEY_DATA]) {
703 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
704 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
705 }
706
707 if (tb[NL80211_KEY_SEQ]) {
708 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
709 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
710 }
711
712 if (tb[NL80211_KEY_CIPHER])
713 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
714
Johannes Berge31b8212010-10-05 19:39:30 +0200715 if (tb[NL80211_KEY_TYPE]) {
716 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
717 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
718 return -EINVAL;
719 }
720
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100721 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
722 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100723 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
724 tb[NL80211_KEY_DEFAULT_TYPES],
725 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100726 if (err)
727 return err;
728
729 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
730 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
731 }
732
Johannes Bergb9454e82009-07-08 13:29:08 +0200733 return 0;
734}
735
736static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
737{
738 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
739 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
740 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
741 }
742
743 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
744 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
745 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
746 }
747
748 if (info->attrs[NL80211_ATTR_KEY_IDX])
749 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
750
751 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
752 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
753
754 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
755 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
756
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100757 if (k->def) {
758 k->def_uni = true;
759 k->def_multi = true;
760 }
761 if (k->defmgmt)
762 k->def_multi = true;
763
Johannes Berge31b8212010-10-05 19:39:30 +0200764 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
765 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
766 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
767 return -EINVAL;
768 }
769
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100770 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
771 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
772 int err = nla_parse_nested(
773 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
774 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
775 nl80211_key_default_policy);
776 if (err)
777 return err;
778
779 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
780 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
781 }
782
Johannes Bergb9454e82009-07-08 13:29:08 +0200783 return 0;
784}
785
786static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
787{
788 int err;
789
790 memset(k, 0, sizeof(*k));
791 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200792 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200793
794 if (info->attrs[NL80211_ATTR_KEY])
795 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
796 else
797 err = nl80211_parse_key_old(info, k);
798
799 if (err)
800 return err;
801
802 if (k->def && k->defmgmt)
803 return -EINVAL;
804
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100805 if (k->defmgmt) {
806 if (k->def_uni || !k->def_multi)
807 return -EINVAL;
808 }
809
Johannes Bergb9454e82009-07-08 13:29:08 +0200810 if (k->idx != -1) {
811 if (k->defmgmt) {
812 if (k->idx < 4 || k->idx > 5)
813 return -EINVAL;
814 } else if (k->def) {
815 if (k->idx < 0 || k->idx > 3)
816 return -EINVAL;
817 } else {
818 if (k->idx < 0 || k->idx > 5)
819 return -EINVAL;
820 }
821 }
822
823 return 0;
824}
825
Johannes Bergfffd0932009-07-08 14:22:54 +0200826static struct cfg80211_cached_keys *
827nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530828 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200829{
830 struct key_parse parse;
831 struct nlattr *key;
832 struct cfg80211_cached_keys *result;
833 int rem, err, def = 0;
834
835 result = kzalloc(sizeof(*result), GFP_KERNEL);
836 if (!result)
837 return ERR_PTR(-ENOMEM);
838
839 result->def = -1;
840 result->defmgmt = -1;
841
842 nla_for_each_nested(key, keys, rem) {
843 memset(&parse, 0, sizeof(parse));
844 parse.idx = -1;
845
846 err = nl80211_parse_key_new(key, &parse);
847 if (err)
848 goto error;
849 err = -EINVAL;
850 if (!parse.p.key)
851 goto error;
852 if (parse.idx < 0 || parse.idx > 4)
853 goto error;
854 if (parse.def) {
855 if (def)
856 goto error;
857 def = 1;
858 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100859 if (!parse.def_uni || !parse.def_multi)
860 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200861 } else if (parse.defmgmt)
862 goto error;
863 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200864 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200865 if (err)
866 goto error;
867 result->params[parse.idx].cipher = parse.p.cipher;
868 result->params[parse.idx].key_len = parse.p.key_len;
869 result->params[parse.idx].key = result->data[parse.idx];
870 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530871
872 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
873 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
874 if (no_ht)
875 *no_ht = true;
876 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200877 }
878
879 return result;
880 error:
881 kfree(result);
882 return ERR_PTR(err);
883}
884
885static int nl80211_key_allowed(struct wireless_dev *wdev)
886{
887 ASSERT_WDEV_LOCK(wdev);
888
Johannes Bergfffd0932009-07-08 14:22:54 +0200889 switch (wdev->iftype) {
890 case NL80211_IFTYPE_AP:
891 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200892 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700893 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200894 break;
895 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200896 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200897 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200898 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200899 return -ENOLINK;
900 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100901 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100902 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100903 case NL80211_IFTYPE_MONITOR:
904 case NL80211_IFTYPE_P2P_DEVICE:
905 case NL80211_IFTYPE_WDS:
906 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200907 return -EINVAL;
908 }
909
910 return 0;
911}
912
Jouni Malinen664834d2014-01-15 00:01:44 +0200913static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
914 struct nlattr *tb)
915{
916 struct ieee80211_channel *chan;
917
918 if (tb == NULL)
919 return NULL;
920 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
921 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
922 return NULL;
923 return chan;
924}
925
Johannes Berg7527a782011-05-13 10:58:57 +0200926static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
927{
928 struct nlattr *nl_modes = nla_nest_start(msg, attr);
929 int i;
930
931 if (!nl_modes)
932 goto nla_put_failure;
933
934 i = 0;
935 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400936 if ((ifmodes & 1) && nla_put_flag(msg, i))
937 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200938 ifmodes >>= 1;
939 i++;
940 }
941
942 nla_nest_end(msg, nl_modes);
943 return 0;
944
945nla_put_failure:
946 return -ENOBUFS;
947}
948
949static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100950 struct sk_buff *msg,
951 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200952{
953 struct nlattr *nl_combis;
954 int i, j;
955
956 nl_combis = nla_nest_start(msg,
957 NL80211_ATTR_INTERFACE_COMBINATIONS);
958 if (!nl_combis)
959 goto nla_put_failure;
960
961 for (i = 0; i < wiphy->n_iface_combinations; i++) {
962 const struct ieee80211_iface_combination *c;
963 struct nlattr *nl_combi, *nl_limits;
964
965 c = &wiphy->iface_combinations[i];
966
967 nl_combi = nla_nest_start(msg, i + 1);
968 if (!nl_combi)
969 goto nla_put_failure;
970
971 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
972 if (!nl_limits)
973 goto nla_put_failure;
974
975 for (j = 0; j < c->n_limits; j++) {
976 struct nlattr *nl_limit;
977
978 nl_limit = nla_nest_start(msg, j + 1);
979 if (!nl_limit)
980 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400981 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
982 c->limits[j].max))
983 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200984 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
985 c->limits[j].types))
986 goto nla_put_failure;
987 nla_nest_end(msg, nl_limit);
988 }
989
990 nla_nest_end(msg, nl_limits);
991
David S. Miller9360ffd2012-03-29 04:41:26 -0400992 if (c->beacon_int_infra_match &&
993 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
994 goto nla_put_failure;
995 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
996 c->num_different_channels) ||
997 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
998 c->max_interfaces))
999 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +01001000 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001001 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1002 c->radar_detect_widths) ||
1003 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1004 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001005 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001006
1007 nla_nest_end(msg, nl_combi);
1008 }
1009
1010 nla_nest_end(msg, nl_combis);
1011
1012 return 0;
1013nla_put_failure:
1014 return -ENOBUFS;
1015}
1016
Johannes Berg3713b4e2013-02-14 16:19:38 +01001017#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001018static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1019 struct sk_buff *msg)
1020{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001021 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001022 struct nlattr *nl_tcp;
1023
1024 if (!tcp)
1025 return 0;
1026
1027 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1028 if (!nl_tcp)
1029 return -ENOBUFS;
1030
1031 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1032 tcp->data_payload_max))
1033 return -ENOBUFS;
1034
1035 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1036 tcp->data_payload_max))
1037 return -ENOBUFS;
1038
1039 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1040 return -ENOBUFS;
1041
1042 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1043 sizeof(*tcp->tok), tcp->tok))
1044 return -ENOBUFS;
1045
1046 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1047 tcp->data_interval_max))
1048 return -ENOBUFS;
1049
1050 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1051 tcp->wake_payload_max))
1052 return -ENOBUFS;
1053
1054 nla_nest_end(msg, nl_tcp);
1055 return 0;
1056}
1057
Johannes Berg3713b4e2013-02-14 16:19:38 +01001058static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001060 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001061{
1062 struct nlattr *nl_wowlan;
1063
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 return 0;
1066
1067 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1068 if (!nl_wowlan)
1069 return -ENOBUFS;
1070
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001071 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001073 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001074 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001079 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001080 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001081 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001082 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001083 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001084 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001085 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001086 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1087 return -ENOBUFS;
1088
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001089 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001090 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001091 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1092 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1093 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1094 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 };
1096
1097 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1098 sizeof(pat), &pat))
1099 return -ENOBUFS;
1100 }
1101
Luciano Coelho75453cc2015-01-09 14:06:37 +02001102 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1103 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1104 rdev->wiphy.wowlan->max_nd_match_sets))
1105 return -ENOBUFS;
1106
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001107 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001108 return -ENOBUFS;
1109
Johannes Berg3713b4e2013-02-14 16:19:38 +01001110 nla_nest_end(msg, nl_wowlan);
1111
1112 return 0;
1113}
1114#endif
1115
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001116static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001117 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001118{
1119 struct nl80211_coalesce_rule_support rule;
1120
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001121 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001122 return 0;
1123
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001124 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1125 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1126 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1127 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1128 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1129 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001130
1131 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1132 return -ENOBUFS;
1133
1134 return 0;
1135}
1136
Johannes Berg3713b4e2013-02-14 16:19:38 +01001137static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1138 struct ieee80211_supported_band *sband)
1139{
1140 struct nlattr *nl_rates, *nl_rate;
1141 struct ieee80211_rate *rate;
1142 int i;
1143
1144 /* add HT info */
1145 if (sband->ht_cap.ht_supported &&
1146 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1147 sizeof(sband->ht_cap.mcs),
1148 &sband->ht_cap.mcs) ||
1149 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1150 sband->ht_cap.cap) ||
1151 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1152 sband->ht_cap.ampdu_factor) ||
1153 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1154 sband->ht_cap.ampdu_density)))
1155 return -ENOBUFS;
1156
1157 /* add VHT info */
1158 if (sband->vht_cap.vht_supported &&
1159 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1160 sizeof(sband->vht_cap.vht_mcs),
1161 &sband->vht_cap.vht_mcs) ||
1162 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1163 sband->vht_cap.cap)))
1164 return -ENOBUFS;
1165
1166 /* add bitrates */
1167 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1168 if (!nl_rates)
1169 return -ENOBUFS;
1170
1171 for (i = 0; i < sband->n_bitrates; i++) {
1172 nl_rate = nla_nest_start(msg, i);
1173 if (!nl_rate)
1174 return -ENOBUFS;
1175
1176 rate = &sband->bitrates[i];
1177 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1178 rate->bitrate))
1179 return -ENOBUFS;
1180 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1181 nla_put_flag(msg,
1182 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1183 return -ENOBUFS;
1184
1185 nla_nest_end(msg, nl_rate);
1186 }
1187
1188 nla_nest_end(msg, nl_rates);
1189
1190 return 0;
1191}
1192
1193static int
1194nl80211_send_mgmt_stypes(struct sk_buff *msg,
1195 const struct ieee80211_txrx_stypes *mgmt_stypes)
1196{
1197 u16 stypes;
1198 struct nlattr *nl_ftypes, *nl_ifs;
1199 enum nl80211_iftype ift;
1200 int i;
1201
1202 if (!mgmt_stypes)
1203 return 0;
1204
1205 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1206 if (!nl_ifs)
1207 return -ENOBUFS;
1208
1209 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1210 nl_ftypes = nla_nest_start(msg, ift);
1211 if (!nl_ftypes)
1212 return -ENOBUFS;
1213 i = 0;
1214 stypes = mgmt_stypes[ift].tx;
1215 while (stypes) {
1216 if ((stypes & 1) &&
1217 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1218 (i << 4) | IEEE80211_FTYPE_MGMT))
1219 return -ENOBUFS;
1220 stypes >>= 1;
1221 i++;
1222 }
1223 nla_nest_end(msg, nl_ftypes);
1224 }
1225
1226 nla_nest_end(msg, nl_ifs);
1227
1228 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1229 if (!nl_ifs)
1230 return -ENOBUFS;
1231
1232 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1233 nl_ftypes = nla_nest_start(msg, ift);
1234 if (!nl_ftypes)
1235 return -ENOBUFS;
1236 i = 0;
1237 stypes = mgmt_stypes[ift].rx;
1238 while (stypes) {
1239 if ((stypes & 1) &&
1240 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1241 (i << 4) | IEEE80211_FTYPE_MGMT))
1242 return -ENOBUFS;
1243 stypes >>= 1;
1244 i++;
1245 }
1246 nla_nest_end(msg, nl_ftypes);
1247 }
1248 nla_nest_end(msg, nl_ifs);
1249
1250 return 0;
1251}
1252
Johannes Berg86e8cf92013-06-19 10:57:22 +02001253struct nl80211_dump_wiphy_state {
1254 s64 filter_wiphy;
1255 long start;
1256 long split_start, band_start, chan_start;
1257 bool split;
1258};
1259
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001260static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001261 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001262 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001263 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001264{
1265 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001266 struct nlattr *nl_bands, *nl_band;
1267 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001268 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001269 enum ieee80211_band band;
1270 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001271 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001272 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001273 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001274 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001275
Johannes Berg3bb20552014-05-26 13:52:25 +02001276 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001277 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 return -ENOBUFS;
1279
Johannes Berg86e8cf92013-06-19 10:57:22 +02001280 if (WARN_ON(!state))
1281 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001282
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001283 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001285 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001286 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001288 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001289
Johannes Berg3bb20552014-05-26 13:52:25 +02001290 if (cmd != NL80211_CMD_NEW_WIPHY)
1291 goto finish;
1292
Johannes Berg86e8cf92013-06-19 10:57:22 +02001293 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 case 0:
1295 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001304 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001307 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001308 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001310 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001312 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001314 rdev->wiphy.max_match_sets) ||
1315 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1316 rdev->wiphy.max_sched_scan_plans) ||
1317 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1318 rdev->wiphy.max_sched_scan_plan_interval) ||
1319 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1320 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001321 goto nla_put_failure;
1322
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1325 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001326 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1328 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001329 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1331 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001332 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001333 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1334 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001335 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001336 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1337 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001338 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001340 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001341 state->split_start++;
1342 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 break;
1344 case 1:
1345 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1347 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001348 goto nla_put_failure;
1349
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001351 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001352 goto nla_put_failure;
1353
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001354 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1356 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001357
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001359 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001361 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001363
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001364 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001365 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001366 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001368
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001369 if ((rdev->wiphy.available_antennas_tx ||
1370 rdev->wiphy.available_antennas_rx) &&
1371 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001372 u32 tx_ant = 0, rx_ant = 0;
1373 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001374 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 if (!res) {
1376 if (nla_put_u32(msg,
1377 NL80211_ATTR_WIPHY_ANTENNA_TX,
1378 tx_ant) ||
1379 nla_put_u32(msg,
1380 NL80211_ATTR_WIPHY_ANTENNA_RX,
1381 rx_ant))
1382 goto nla_put_failure;
1383 }
Johannes Bergee688b002008-01-24 19:38:39 +01001384 }
1385
Johannes Berg86e8cf92013-06-19 10:57:22 +02001386 state->split_start++;
1387 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001388 break;
1389 case 2:
1390 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001391 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001393 state->split_start++;
1394 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001395 break;
1396 case 3:
1397 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1398 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001399 goto nla_put_failure;
1400
Johannes Berg86e8cf92013-06-19 10:57:22 +02001401 for (band = state->band_start;
1402 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 struct ieee80211_supported_band *sband;
1404
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001405 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406
1407 if (!sband)
1408 continue;
1409
1410 nl_band = nla_nest_start(msg, band);
1411 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001412 goto nla_put_failure;
1413
Johannes Berg86e8cf92013-06-19 10:57:22 +02001414 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001415 case 0:
1416 if (nl80211_send_band_rateinfo(msg, sband))
1417 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001418 state->chan_start++;
1419 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001420 break;
1421 default:
1422 /* add frequencies */
1423 nl_freqs = nla_nest_start(
1424 msg, NL80211_BAND_ATTR_FREQS);
1425 if (!nl_freqs)
1426 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001427
Johannes Berg86e8cf92013-06-19 10:57:22 +02001428 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 i < sband->n_channels;
1430 i++) {
1431 nl_freq = nla_nest_start(msg, i);
1432 if (!nl_freq)
1433 goto nla_put_failure;
1434
1435 chan = &sband->channels[i];
1436
Johannes Berg86e8cf92013-06-19 10:57:22 +02001437 if (nl80211_msg_put_channel(
1438 msg, chan,
1439 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001440 goto nla_put_failure;
1441
1442 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001443 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 break;
1445 }
1446 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001447 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001449 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 nla_nest_end(msg, nl_freqs);
1451 }
1452
1453 nla_nest_end(msg, nl_band);
1454
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001456 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001457 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001458 band--;
1459 break;
1460 }
Johannes Bergee688b002008-01-24 19:38:39 +01001461 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001463
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001465 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001467 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001468
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001470 if (state->band_start == 0 && state->chan_start == 0)
1471 state->split_start++;
1472 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001473 break;
1474 case 4:
1475 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1476 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001477 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001478
1479 i = 0;
1480#define CMD(op, n) \
1481 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001482 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001483 i++; \
1484 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1485 goto nla_put_failure; \
1486 } \
1487 } while (0)
1488
1489 CMD(add_virtual_intf, NEW_INTERFACE);
1490 CMD(change_virtual_intf, SET_INTERFACE);
1491 CMD(add_key, NEW_KEY);
1492 CMD(start_ap, START_AP);
1493 CMD(add_station, NEW_STATION);
1494 CMD(add_mpath, NEW_MPATH);
1495 CMD(update_mesh_config, SET_MESH_CONFIG);
1496 CMD(change_bss, SET_BSS);
1497 CMD(auth, AUTHENTICATE);
1498 CMD(assoc, ASSOCIATE);
1499 CMD(deauth, DEAUTHENTICATE);
1500 CMD(disassoc, DISASSOCIATE);
1501 CMD(join_ibss, JOIN_IBSS);
1502 CMD(join_mesh, JOIN_MESH);
1503 CMD(set_pmksa, SET_PMKSA);
1504 CMD(del_pmksa, DEL_PMKSA);
1505 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1508 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1509 CMD(mgmt_tx, FRAME);
1510 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001511 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 i++;
1513 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1514 goto nla_put_failure;
1515 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001516 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1517 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 i++;
1519 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1520 goto nla_put_failure;
1521 }
1522 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001523 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001524 CMD(tdls_mgmt, TDLS_MGMT);
1525 CMD(tdls_oper, TDLS_OPER);
1526 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001527 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001528 CMD(sched_scan_start, START_SCHED_SCAN);
1529 CMD(probe_client, PROBE_CLIENT);
1530 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001531 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001532 i++;
1533 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1534 goto nla_put_failure;
1535 }
1536 CMD(start_p2p_device, START_P2P_DEVICE);
1537 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001538#ifdef CONFIG_NL80211_TESTMODE
1539 CMD(testmode_cmd, TESTMODE);
1540#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001541 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001542 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1543 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001544 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001545 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001546 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001547 if (rdev->wiphy.features &
1548 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001549 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001550 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001551 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001552#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001553
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001554 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001555 i++;
1556 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001557 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001558 }
1559
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001560 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 i++;
1562 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1563 goto nla_put_failure;
1564 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001565
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001567 state->split_start++;
1568 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569 break;
1570 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001571 if (rdev->ops->remain_on_channel &&
1572 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 nla_put_u32(msg,
1574 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001576 goto nla_put_failure;
1577
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001579 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1580 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001581
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1583 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001584 state->split_start++;
1585 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001586 break;
1587 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001588#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001591 state->split_start++;
1592 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001593 break;
1594#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001595 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596#endif
1597 case 7:
1598 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001599 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001600 goto nla_put_failure;
1601
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001602 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001603 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001604 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001605
Johannes Berg86e8cf92013-06-19 10:57:22 +02001606 state->split_start++;
1607 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001608 break;
1609 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001610 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 goto nla_put_failure;
1614
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001616 /*
1617 * We can only add the per-channel limit information if the
1618 * dump is split, otherwise it makes it too big. Therefore
1619 * only advertise it in that case.
1620 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001621 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001622 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1623 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 goto nla_put_failure;
1625
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001626 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001627 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001628 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1629 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001630 goto nla_put_failure;
1631
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1633 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001634 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001635 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001636 goto nla_put_failure;
1637
1638 /*
1639 * Any information below this point is only available to
1640 * applications that can deal with it being split. This
1641 * helps ensure that newly added capabilities don't break
1642 * older tools by overrunning their buffers.
1643 *
1644 * We still increment split_start so that in the split
1645 * case we'll continue with more data in the next round,
1646 * but break unconditionally so unsplit data stops here.
1647 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001648 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001649 break;
1650 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001651 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001652 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001653 rdev->wiphy.extended_capabilities_len,
1654 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001655 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001656 rdev->wiphy.extended_capabilities_len,
1657 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001658 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001659
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001660 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001661 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001662 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1663 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001664 goto nla_put_failure;
1665
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001666 state->split_start++;
1667 break;
1668 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001669 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001670 goto nla_put_failure;
1671
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001672 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001673 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1674 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1675 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001676
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001677 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001678 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001679 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001680 goto nla_put_failure;
1681
Johannes Bergad7e7182013-11-13 13:37:47 +01001682 state->split_start++;
1683 break;
1684 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001685 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001686 const struct nl80211_vendor_cmd_info *info;
1687 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001688
Johannes Berg567ffc32013-12-18 14:43:31 +01001689 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1690 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001691 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001692
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001693 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1694 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001695 if (nla_put(msg, i + 1, sizeof(*info), info))
1696 goto nla_put_failure;
1697 }
1698 nla_nest_end(msg, nested);
1699 }
1700
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001701 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001702 const struct nl80211_vendor_cmd_info *info;
1703 struct nlattr *nested;
1704
1705 nested = nla_nest_start(msg,
1706 NL80211_ATTR_VENDOR_EVENTS);
1707 if (!nested)
1708 goto nla_put_failure;
1709
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001710 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1711 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001712 if (nla_put(msg, i + 1, sizeof(*info), info))
1713 goto nla_put_failure;
1714 }
1715 nla_nest_end(msg, nested);
1716 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001717 state->split_start++;
1718 break;
1719 case 12:
1720 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1721 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1722 rdev->wiphy.max_num_csa_counters))
1723 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001724
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001725 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1726 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1727 goto nla_put_failure;
1728
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001729 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1730 sizeof(rdev->wiphy.ext_features),
1731 rdev->wiphy.ext_features))
1732 goto nla_put_failure;
1733
Johannes Berg3713b4e2013-02-14 16:19:38 +01001734 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001735 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001736 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001737 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001738 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001739 genlmsg_end(msg, hdr);
1740 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001741
1742 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001743 genlmsg_cancel(msg, hdr);
1744 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001745}
1746
Johannes Berg86e8cf92013-06-19 10:57:22 +02001747static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1748 struct netlink_callback *cb,
1749 struct nl80211_dump_wiphy_state *state)
1750{
1751 struct nlattr **tb = nl80211_fam.attrbuf;
1752 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1753 tb, nl80211_fam.maxattr, nl80211_policy);
1754 /* ignore parse errors for backward compatibility */
1755 if (ret)
1756 return 0;
1757
1758 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1759 if (tb[NL80211_ATTR_WIPHY])
1760 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1761 if (tb[NL80211_ATTR_WDEV])
1762 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1763 if (tb[NL80211_ATTR_IFINDEX]) {
1764 struct net_device *netdev;
1765 struct cfg80211_registered_device *rdev;
1766 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1767
Ying Xue7f2b8562014-01-15 10:23:45 +08001768 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001769 if (!netdev)
1770 return -ENODEV;
1771 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001772 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001773 netdev->ieee80211_ptr->wiphy);
1774 state->filter_wiphy = rdev->wiphy_idx;
1775 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001776 }
1777
1778 return 0;
1779}
1780
Johannes Berg55682962007-09-20 13:09:35 -04001781static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1782{
Johannes Berg645e77d2013-03-01 14:03:49 +01001783 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001784 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001785 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001786
Johannes Berg5fe231e2013-05-08 21:45:15 +02001787 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001788 if (!state) {
1789 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001790 if (!state) {
1791 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001792 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001793 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001794 state->filter_wiphy = -1;
1795 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1796 if (ret) {
1797 kfree(state);
1798 rtnl_unlock();
1799 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001800 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001801 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001802 }
1803
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001804 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1805 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001806 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001807 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001808 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001809 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001810 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001811 continue;
1812 /* attempt to fit multiple wiphy data chunks into the skb */
1813 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001814 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1815 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001816 NETLINK_CB(cb->skb).portid,
1817 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001819 if (ret < 0) {
1820 /*
1821 * If sending the wiphy data didn't fit (ENOBUFS
1822 * or EMSGSIZE returned), this SKB is still
1823 * empty (so it's not too big because another
1824 * wiphy dataset is already in the skb) and
1825 * we've not tried to adjust the dump allocation
1826 * yet ... then adjust the alloc size to be
1827 * bigger, and return 1 but with the empty skb.
1828 * This results in an empty message being RX'ed
1829 * in userspace, but that is ignored.
1830 *
1831 * We can then retry with the larger buffer.
1832 */
1833 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001834 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001835 cb->min_dump_alloc < 4096) {
1836 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001837 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001838 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001839 return 1;
1840 }
1841 idx--;
1842 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001843 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001844 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001845 break;
Johannes Berg55682962007-09-20 13:09:35 -04001846 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001847 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001848
Johannes Berg86e8cf92013-06-19 10:57:22 +02001849 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001850
1851 return skb->len;
1852}
1853
Johannes Berg86e8cf92013-06-19 10:57:22 +02001854static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1855{
1856 kfree((void *)cb->args[0]);
1857 return 0;
1858}
1859
Johannes Berg55682962007-09-20 13:09:35 -04001860static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1861{
1862 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001863 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001864 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001865
Johannes Berg645e77d2013-03-01 14:03:49 +01001866 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001867 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001868 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001869
Johannes Berg3bb20552014-05-26 13:52:25 +02001870 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1871 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001872 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001873 nlmsg_free(msg);
1874 return -ENOBUFS;
1875 }
Johannes Berg55682962007-09-20 13:09:35 -04001876
Johannes Berg134e6372009-07-10 09:51:34 +00001877 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001878}
1879
Jouni Malinen31888482008-10-30 16:59:24 +02001880static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1881 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1882 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1883 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1884 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1885 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1886};
1887
1888static int parse_txq_params(struct nlattr *tb[],
1889 struct ieee80211_txq_params *txq_params)
1890{
Johannes Berga3304b02012-03-28 11:04:24 +02001891 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001892 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1893 !tb[NL80211_TXQ_ATTR_AIFS])
1894 return -EINVAL;
1895
Johannes Berga3304b02012-03-28 11:04:24 +02001896 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001897 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1898 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1899 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1900 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1901
Johannes Berga3304b02012-03-28 11:04:24 +02001902 if (txq_params->ac >= NL80211_NUM_ACS)
1903 return -EINVAL;
1904
Jouni Malinen31888482008-10-30 16:59:24 +02001905 return 0;
1906}
1907
Johannes Bergf444de02010-05-05 15:25:02 +02001908static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1909{
1910 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001911 * You can only set the channel explicitly for WDS interfaces,
1912 * all others have their channel managed via their respective
1913 * "establish a connection" command (connect, join, ...)
1914 *
1915 * For AP/GO and mesh mode, the channel can be set with the
1916 * channel userspace API, but is only stored and passed to the
1917 * low-level driver when the AP starts or the mesh is joined.
1918 * This is for backward compatibility, userspace can also give
1919 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001920 *
1921 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001922 * whatever else is going on, so they have their own special
1923 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001924 */
1925 return !wdev ||
1926 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001927 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001928 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1929 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001930}
1931
Johannes Berg683b6d32012-11-08 21:25:48 +01001932static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1933 struct genl_info *info,
1934 struct cfg80211_chan_def *chandef)
1935{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301936 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001937
1938 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1939 return -EINVAL;
1940
1941 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1942
1943 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001944 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1945 chandef->center_freq1 = control_freq;
1946 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001947
1948 /* Primary channel not allowed */
1949 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1950 return -EINVAL;
1951
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001952 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1953 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001954
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001955 chantype = nla_get_u32(
1956 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1957
1958 switch (chantype) {
1959 case NL80211_CHAN_NO_HT:
1960 case NL80211_CHAN_HT20:
1961 case NL80211_CHAN_HT40PLUS:
1962 case NL80211_CHAN_HT40MINUS:
1963 cfg80211_chandef_create(chandef, chandef->chan,
1964 chantype);
1965 break;
1966 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001967 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001968 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001969 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1970 chandef->width =
1971 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1972 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1973 chandef->center_freq1 =
1974 nla_get_u32(
1975 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1976 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1977 chandef->center_freq2 =
1978 nla_get_u32(
1979 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1980 }
1981
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001982 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001983 return -EINVAL;
1984
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001985 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1986 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001987 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001988
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001989 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1990 chandef->width == NL80211_CHAN_WIDTH_10) &&
1991 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1992 return -EINVAL;
1993
Johannes Berg683b6d32012-11-08 21:25:48 +01001994 return 0;
1995}
1996
Johannes Bergf444de02010-05-05 15:25:02 +02001997static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001998 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001999 struct genl_info *info)
2000{
Johannes Berg683b6d32012-11-08 21:25:48 +01002001 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002002 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002003 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002004 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002005
Jouni Malinene16821b2014-04-28 11:22:08 +03002006 if (dev)
2007 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002008 if (!nl80211_can_set_dev_channel(wdev))
2009 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002010 if (wdev)
2011 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002012
Johannes Berg683b6d32012-11-08 21:25:48 +01002013 result = nl80211_parse_chandef(rdev, info, &chandef);
2014 if (result)
2015 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002016
Johannes Berge8c9bd52012-06-06 08:18:22 +02002017 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002018 case NL80211_IFTYPE_AP:
2019 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002020 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2021 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002022 result = -EINVAL;
2023 break;
2024 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002025 if (wdev->beacon_interval) {
2026 if (!dev || !rdev->ops->set_ap_chanwidth ||
2027 !(rdev->wiphy.features &
2028 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2029 result = -EBUSY;
2030 break;
2031 }
2032
2033 /* Only allow dynamic channel width changes */
2034 if (chandef.chan != wdev->preset_chandef.chan) {
2035 result = -EBUSY;
2036 break;
2037 }
2038 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2039 if (result)
2040 break;
2041 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002042 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002043 result = 0;
2044 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002045 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002046 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002047 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002048 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002049 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002050 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002051 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002052 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002053 }
Johannes Bergf444de02010-05-05 15:25:02 +02002054
2055 return result;
2056}
2057
2058static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2059{
Johannes Berg4c476992010-10-04 21:36:35 +02002060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2061 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002062
Jouni Malinene16821b2014-04-28 11:22:08 +03002063 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002064}
2065
Bill Jordane8347eb2010-10-01 13:54:28 -04002066static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2067{
Johannes Berg43b19952010-10-07 13:10:30 +02002068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2069 struct net_device *dev = info->user_ptr[1];
2070 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002071 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002072
2073 if (!info->attrs[NL80211_ATTR_MAC])
2074 return -EINVAL;
2075
Johannes Berg43b19952010-10-07 13:10:30 +02002076 if (netif_running(dev))
2077 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002078
Johannes Berg43b19952010-10-07 13:10:30 +02002079 if (!rdev->ops->set_wds_peer)
2080 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002081
Johannes Berg43b19952010-10-07 13:10:30 +02002082 if (wdev->iftype != NL80211_IFTYPE_WDS)
2083 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002084
2085 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002086 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002087}
2088
2089
Johannes Berg55682962007-09-20 13:09:35 -04002090static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2091{
2092 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002093 struct net_device *netdev = NULL;
2094 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002095 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002096 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002097 u32 changed;
2098 u8 retry_short = 0, retry_long = 0;
2099 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002100 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002101
Johannes Berg5fe231e2013-05-08 21:45:15 +02002102 ASSERT_RTNL();
2103
Johannes Bergf444de02010-05-05 15:25:02 +02002104 /*
2105 * Try to find the wiphy and netdev. Normally this
2106 * function shouldn't need the netdev, but this is
2107 * done for backward compatibility -- previously
2108 * setting the channel was done per wiphy, but now
2109 * it is per netdev. Previous userland like hostapd
2110 * also passed a netdev to set_wiphy, so that it is
2111 * possible to let that go to the right netdev!
2112 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002113
Johannes Bergf444de02010-05-05 15:25:02 +02002114 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2115 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2116
Ying Xue7f2b8562014-01-15 10:23:45 +08002117 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002118 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002119 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002120 else
Johannes Bergf444de02010-05-05 15:25:02 +02002121 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002122 }
2123
Johannes Bergf444de02010-05-05 15:25:02 +02002124 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002125 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2126 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002127 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002128 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002129 wdev = NULL;
2130 netdev = NULL;
2131 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002132 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002133 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002134
2135 /*
2136 * end workaround code, by now the rdev is available
2137 * and locked, and wdev may or may not be NULL.
2138 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002139
2140 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002141 result = cfg80211_dev_rename(
2142 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002143
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002144 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002145 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002146
Jouni Malinen31888482008-10-30 16:59:24 +02002147 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2148 struct ieee80211_txq_params txq_params;
2149 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2150
Ying Xue7f2b8562014-01-15 10:23:45 +08002151 if (!rdev->ops->set_txq_params)
2152 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002153
Ying Xue7f2b8562014-01-15 10:23:45 +08002154 if (!netdev)
2155 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002156
Johannes Berg133a3ff2011-11-03 14:50:13 +01002157 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002158 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2159 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002160
Ying Xue7f2b8562014-01-15 10:23:45 +08002161 if (!netif_running(netdev))
2162 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002163
Jouni Malinen31888482008-10-30 16:59:24 +02002164 nla_for_each_nested(nl_txq_params,
2165 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2166 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002167 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2168 nla_data(nl_txq_params),
2169 nla_len(nl_txq_params),
2170 txq_params_policy);
2171 if (result)
2172 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002173 result = parse_txq_params(tb, &txq_params);
2174 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002176
Hila Gonene35e4d22012-06-27 17:19:42 +03002177 result = rdev_set_txq_params(rdev, netdev,
2178 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002179 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002180 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002181 }
2182 }
2183
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002184 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002185 result = __nl80211_set_channel(
2186 rdev,
2187 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2188 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002189 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002190 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002191 }
2192
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002193 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002194 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002195 enum nl80211_tx_power_setting type;
2196 int idx, mbm = 0;
2197
Johannes Bergc8442112012-10-24 10:17:18 +02002198 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2199 txp_wdev = NULL;
2200
Ying Xue7f2b8562014-01-15 10:23:45 +08002201 if (!rdev->ops->set_tx_power)
2202 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002203
2204 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2205 type = nla_get_u32(info->attrs[idx]);
2206
2207 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002208 (type != NL80211_TX_POWER_AUTOMATIC))
2209 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002210
2211 if (type != NL80211_TX_POWER_AUTOMATIC) {
2212 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2213 mbm = nla_get_u32(info->attrs[idx]);
2214 }
2215
Johannes Bergc8442112012-10-24 10:17:18 +02002216 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002217 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002218 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002219 }
2220
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002221 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2222 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2223 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002224 if ((!rdev->wiphy.available_antennas_tx &&
2225 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002226 !rdev->ops->set_antenna)
2227 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002228
2229 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2230 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2231
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002232 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002233 * available antenna masks, except for the "all" mask */
2234 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002235 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2236 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002237
Bruno Randolf7f531e02010-12-16 11:30:22 +09002238 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2239 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002240
Hila Gonene35e4d22012-06-27 17:19:42 +03002241 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002242 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002243 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002244 }
2245
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002246 changed = 0;
2247
2248 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2249 retry_short = nla_get_u8(
2250 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002251 if (retry_short == 0)
2252 return -EINVAL;
2253
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002254 changed |= WIPHY_PARAM_RETRY_SHORT;
2255 }
2256
2257 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2258 retry_long = nla_get_u8(
2259 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002260 if (retry_long == 0)
2261 return -EINVAL;
2262
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002263 changed |= WIPHY_PARAM_RETRY_LONG;
2264 }
2265
2266 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2267 frag_threshold = nla_get_u32(
2268 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002269 if (frag_threshold < 256)
2270 return -EINVAL;
2271
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002272 if (frag_threshold != (u32) -1) {
2273 /*
2274 * Fragments (apart from the last one) are required to
2275 * have even length. Make the fragmentation code
2276 * simpler by stripping LSB should someone try to use
2277 * odd threshold value.
2278 */
2279 frag_threshold &= ~0x1;
2280 }
2281 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2282 }
2283
2284 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2285 rts_threshold = nla_get_u32(
2286 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2287 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2288 }
2289
Lukáš Turek81077e82009-12-21 22:50:47 +01002290 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002291 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2292 return -EINVAL;
2293
Lukáš Turek81077e82009-12-21 22:50:47 +01002294 coverage_class = nla_get_u8(
2295 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2296 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2297 }
2298
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002299 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2300 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2301 return -EOPNOTSUPP;
2302
2303 changed |= WIPHY_PARAM_DYN_ACK;
2304 }
2305
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002306 if (changed) {
2307 u8 old_retry_short, old_retry_long;
2308 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002309 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002310
Ying Xue7f2b8562014-01-15 10:23:45 +08002311 if (!rdev->ops->set_wiphy_params)
2312 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002313
2314 old_retry_short = rdev->wiphy.retry_short;
2315 old_retry_long = rdev->wiphy.retry_long;
2316 old_frag_threshold = rdev->wiphy.frag_threshold;
2317 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002318 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002319
2320 if (changed & WIPHY_PARAM_RETRY_SHORT)
2321 rdev->wiphy.retry_short = retry_short;
2322 if (changed & WIPHY_PARAM_RETRY_LONG)
2323 rdev->wiphy.retry_long = retry_long;
2324 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2325 rdev->wiphy.frag_threshold = frag_threshold;
2326 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2327 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002328 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2329 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002330
Hila Gonene35e4d22012-06-27 17:19:42 +03002331 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002332 if (result) {
2333 rdev->wiphy.retry_short = old_retry_short;
2334 rdev->wiphy.retry_long = old_retry_long;
2335 rdev->wiphy.frag_threshold = old_frag_threshold;
2336 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002337 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002338 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002339 }
2340 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002341 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002342}
2343
Johannes Berg71bbc992012-06-15 15:30:18 +02002344static inline u64 wdev_id(struct wireless_dev *wdev)
2345{
2346 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002347 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002348}
Johannes Berg55682962007-09-20 13:09:35 -04002349
Johannes Berg683b6d32012-11-08 21:25:48 +01002350static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002351 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002352{
Johannes Berg601555c2014-11-27 17:26:56 +01002353 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2354 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002355
Johannes Berg683b6d32012-11-08 21:25:48 +01002356 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2357 chandef->chan->center_freq))
2358 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002359 switch (chandef->width) {
2360 case NL80211_CHAN_WIDTH_20_NOHT:
2361 case NL80211_CHAN_WIDTH_20:
2362 case NL80211_CHAN_WIDTH_40:
2363 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2364 cfg80211_get_chandef_type(chandef)))
2365 return -ENOBUFS;
2366 break;
2367 default:
2368 break;
2369 }
2370 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2371 return -ENOBUFS;
2372 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2373 return -ENOBUFS;
2374 if (chandef->center_freq2 &&
2375 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002376 return -ENOBUFS;
2377 return 0;
2378}
2379
Eric W. Biederman15e47302012-09-07 20:12:54 +00002380static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002381 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002382 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002383{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002384 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002385 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002386 void *hdr;
2387
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002388 if (removal)
2389 cmd = NL80211_CMD_DEL_INTERFACE;
2390
2391 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002392 if (!hdr)
2393 return -1;
2394
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002395 if (dev &&
2396 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002397 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002398 goto nla_put_failure;
2399
2400 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2401 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002402 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002403 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002404 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2405 rdev->devlist_generation ^
2406 (cfg80211_rdev_list_generation << 2)))
2407 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002408
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002409 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002410 int ret;
2411 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002412
Johannes Berg683b6d32012-11-08 21:25:48 +01002413 ret = rdev_get_channel(rdev, wdev, &chandef);
2414 if (ret == 0) {
2415 if (nl80211_send_chandef(msg, &chandef))
2416 goto nla_put_failure;
2417 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002418 }
2419
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002420 if (rdev->ops->get_tx_power) {
2421 int dbm, ret;
2422
2423 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2424 if (ret == 0 &&
2425 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2426 DBM_TO_MBM(dbm)))
2427 goto nla_put_failure;
2428 }
2429
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002430 if (wdev->ssid_len) {
2431 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2432 goto nla_put_failure;
2433 }
2434
Johannes Berg053c0952015-01-16 22:09:00 +01002435 genlmsg_end(msg, hdr);
2436 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002437
2438 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002439 genlmsg_cancel(msg, hdr);
2440 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002441}
2442
2443static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2444{
2445 int wp_idx = 0;
2446 int if_idx = 0;
2447 int wp_start = cb->args[0];
2448 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002449 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002450 struct wireless_dev *wdev;
2451
Johannes Berg5fe231e2013-05-08 21:45:15 +02002452 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002453 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2454 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002455 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002456 if (wp_idx < wp_start) {
2457 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002458 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002459 }
Johannes Berg55682962007-09-20 13:09:35 -04002460 if_idx = 0;
2461
Johannes Berg89a54e42012-06-15 14:33:17 +02002462 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002463 if (if_idx < if_start) {
2464 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002465 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002466 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002467 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002468 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002469 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002470 goto out;
2471 }
2472 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002473 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002474
2475 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002476 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002477 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002478 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002479
2480 cb->args[0] = wp_idx;
2481 cb->args[1] = if_idx;
2482
2483 return skb->len;
2484}
2485
2486static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2487{
2488 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002489 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002490 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002491
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002492 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002493 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002494 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002495
Eric W. Biederman15e47302012-09-07 20:12:54 +00002496 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002497 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002498 nlmsg_free(msg);
2499 return -ENOBUFS;
2500 }
Johannes Berg55682962007-09-20 13:09:35 -04002501
Johannes Berg134e6372009-07-10 09:51:34 +00002502 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002503}
2504
Michael Wu66f7ac52008-01-31 19:48:22 +01002505static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2506 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2507 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2508 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2509 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2510 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002511 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002512};
2513
2514static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2515{
2516 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2517 int flag;
2518
2519 *mntrflags = 0;
2520
2521 if (!nla)
2522 return -EINVAL;
2523
2524 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2525 nla, mntr_flags_policy))
2526 return -EINVAL;
2527
2528 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2529 if (flags[flag])
2530 *mntrflags |= (1<<flag);
2531
2532 return 0;
2533}
2534
Johannes Berg9bc383d2009-11-19 11:55:19 +01002535static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002536 struct net_device *netdev, u8 use_4addr,
2537 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002538{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002539 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002540 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002541 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002542 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002543 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002544
2545 switch (iftype) {
2546 case NL80211_IFTYPE_AP_VLAN:
2547 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2548 return 0;
2549 break;
2550 case NL80211_IFTYPE_STATION:
2551 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2552 return 0;
2553 break;
2554 default:
2555 break;
2556 }
2557
2558 return -EOPNOTSUPP;
2559}
2560
Johannes Berg55682962007-09-20 13:09:35 -04002561static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2562{
Johannes Berg4c476992010-10-04 21:36:35 +02002563 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002564 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002565 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002566 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002567 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002568 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002569 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002570
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002571 memset(&params, 0, sizeof(params));
2572
Johannes Berg04a773a2009-04-19 21:24:32 +02002573 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002574
Johannes Berg723b0382008-09-16 20:22:09 +02002575 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002576 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002577 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002578 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002579 if (ntype > NL80211_IFTYPE_MAX)
2580 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002581 }
2582
Johannes Berg92ffe052008-09-16 20:39:36 +02002583 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002584 struct wireless_dev *wdev = dev->ieee80211_ptr;
2585
Johannes Berg4c476992010-10-04 21:36:35 +02002586 if (ntype != NL80211_IFTYPE_MESH_POINT)
2587 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002588 if (netif_running(dev))
2589 return -EBUSY;
2590
2591 wdev_lock(wdev);
2592 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2593 IEEE80211_MAX_MESH_ID_LEN);
2594 wdev->mesh_id_up_len =
2595 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2596 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2597 wdev->mesh_id_up_len);
2598 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002599 }
2600
Felix Fietkau8b787642009-11-10 18:53:10 +01002601 if (info->attrs[NL80211_ATTR_4ADDR]) {
2602 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2603 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002604 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002605 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002606 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002607 } else {
2608 params.use_4addr = -1;
2609 }
2610
Johannes Berg92ffe052008-09-16 20:39:36 +02002611 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002612 if (ntype != NL80211_IFTYPE_MONITOR)
2613 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002614 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2615 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002616 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002617 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002618
2619 flags = &_flags;
2620 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002621 }
Johannes Berg3b858752009-03-12 09:55:09 +01002622
Luciano Coelho18003292013-08-29 13:26:57 +03002623 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002624 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2625 return -EOPNOTSUPP;
2626
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002627 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002628 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002629 else
2630 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002631
Johannes Berg9bc383d2009-11-19 11:55:19 +01002632 if (!err && params.use_4addr != -1)
2633 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2634
Johannes Berg55682962007-09-20 13:09:35 -04002635 return err;
2636}
2637
2638static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2639{
Johannes Berg4c476992010-10-04 21:36:35 +02002640 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002641 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002642 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002643 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002644 int err;
2645 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002646 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002647
Johannes Berg78f22b62014-03-24 17:57:27 +01002648 /* to avoid failing a new interface creation due to pending removal */
2649 cfg80211_destroy_ifaces(rdev);
2650
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002651 memset(&params, 0, sizeof(params));
2652
Johannes Berg55682962007-09-20 13:09:35 -04002653 if (!info->attrs[NL80211_ATTR_IFNAME])
2654 return -EINVAL;
2655
2656 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2657 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2658 if (type > NL80211_IFTYPE_MAX)
2659 return -EINVAL;
2660 }
2661
Johannes Berg79c97e92009-07-07 03:56:12 +02002662 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002663 !(rdev->wiphy.interface_modes & (1 << type)))
2664 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002665
Ben Greeare8f479b2014-10-22 12:23:05 -07002666 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2667 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2668 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002669 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2670 ETH_ALEN);
2671 if (!is_valid_ether_addr(params.macaddr))
2672 return -EADDRNOTAVAIL;
2673 }
2674
Johannes Berg9bc383d2009-11-19 11:55:19 +01002675 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002676 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002677 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002678 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002679 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002680 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002681
Michael Wu66f7ac52008-01-31 19:48:22 +01002682 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2683 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2684 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002685
Luciano Coelho18003292013-08-29 13:26:57 +03002686 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002687 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2688 return -EOPNOTSUPP;
2689
Johannes Berga18c7192015-02-24 10:56:42 +01002690 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2691 if (!msg)
2692 return -ENOMEM;
2693
Hila Gonene35e4d22012-06-27 17:19:42 +03002694 wdev = rdev_add_virtual_intf(rdev,
2695 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002696 NET_NAME_USER, type, err ? NULL : &flags,
2697 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002698 if (WARN_ON(!wdev)) {
2699 nlmsg_free(msg);
2700 return -EPROTO;
2701 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002702 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002703 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002704 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002705
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002706 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002707 wdev->owner_nlportid = info->snd_portid;
2708
Johannes Berg98104fde2012-06-16 00:19:54 +02002709 switch (type) {
2710 case NL80211_IFTYPE_MESH_POINT:
2711 if (!info->attrs[NL80211_ATTR_MESH_ID])
2712 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002713 wdev_lock(wdev);
2714 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2715 IEEE80211_MAX_MESH_ID_LEN);
2716 wdev->mesh_id_up_len =
2717 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2718 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2719 wdev->mesh_id_up_len);
2720 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002721 break;
2722 case NL80211_IFTYPE_P2P_DEVICE:
2723 /*
2724 * P2P Device doesn't have a netdev, so doesn't go
2725 * through the netdev notifier and must be added here
2726 */
2727 mutex_init(&wdev->mtx);
2728 INIT_LIST_HEAD(&wdev->event_list);
2729 spin_lock_init(&wdev->event_lock);
2730 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2731 spin_lock_init(&wdev->mgmt_registrations_lock);
2732
Johannes Berg98104fde2012-06-16 00:19:54 +02002733 wdev->identifier = ++rdev->wdev_id;
2734 list_add_rcu(&wdev->list, &rdev->wdev_list);
2735 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002736 break;
2737 default:
2738 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002739 }
2740
Eric W. Biederman15e47302012-09-07 20:12:54 +00002741 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002742 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002743 nlmsg_free(msg);
2744 return -ENOBUFS;
2745 }
2746
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002747 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2748 if (event) {
2749 if (nl80211_send_iface(event, 0, 0, 0,
2750 rdev, wdev, false) < 0) {
2751 nlmsg_free(event);
2752 goto out;
2753 }
2754
2755 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2756 event, 0, NL80211_MCGRP_CONFIG,
2757 GFP_KERNEL);
2758 }
2759
2760out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002761 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002762}
2763
2764static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2765{
Johannes Berg4c476992010-10-04 21:36:35 +02002766 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002767 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002768 struct sk_buff *msg;
2769 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002770
Johannes Berg4c476992010-10-04 21:36:35 +02002771 if (!rdev->ops->del_virtual_intf)
2772 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002773
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002774 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2775 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2776 nlmsg_free(msg);
2777 msg = NULL;
2778 }
2779
Johannes Berg84efbb82012-06-16 00:00:26 +02002780 /*
2781 * If we remove a wireless device without a netdev then clear
2782 * user_ptr[1] so that nl80211_post_doit won't dereference it
2783 * to check if it needs to do dev_put(). Otherwise it crashes
2784 * since the wdev has been freed, unlike with a netdev where
2785 * we need the dev_put() for the netdev to really be freed.
2786 */
2787 if (!wdev->netdev)
2788 info->user_ptr[1] = NULL;
2789
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002790 status = rdev_del_virtual_intf(rdev, wdev);
2791 if (status >= 0 && msg)
2792 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2793 msg, 0, NL80211_MCGRP_CONFIG,
2794 GFP_KERNEL);
2795 else
2796 nlmsg_free(msg);
2797
2798 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002799}
2800
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002801static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2802{
2803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2804 struct net_device *dev = info->user_ptr[1];
2805 u16 noack_map;
2806
2807 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2808 return -EINVAL;
2809
2810 if (!rdev->ops->set_noack_map)
2811 return -EOPNOTSUPP;
2812
2813 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2814
Hila Gonene35e4d22012-06-27 17:19:42 +03002815 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002816}
2817
Johannes Berg41ade002007-12-19 02:03:29 +01002818struct get_key_cookie {
2819 struct sk_buff *msg;
2820 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002821 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002822};
2823
2824static void get_key_callback(void *c, struct key_params *params)
2825{
Johannes Bergb9454e82009-07-08 13:29:08 +02002826 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002827 struct get_key_cookie *cookie = c;
2828
David S. Miller9360ffd2012-03-29 04:41:26 -04002829 if ((params->key &&
2830 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2831 params->key_len, params->key)) ||
2832 (params->seq &&
2833 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2834 params->seq_len, params->seq)) ||
2835 (params->cipher &&
2836 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2837 params->cipher)))
2838 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002839
Johannes Bergb9454e82009-07-08 13:29:08 +02002840 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2841 if (!key)
2842 goto nla_put_failure;
2843
David S. Miller9360ffd2012-03-29 04:41:26 -04002844 if ((params->key &&
2845 nla_put(cookie->msg, NL80211_KEY_DATA,
2846 params->key_len, params->key)) ||
2847 (params->seq &&
2848 nla_put(cookie->msg, NL80211_KEY_SEQ,
2849 params->seq_len, params->seq)) ||
2850 (params->cipher &&
2851 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2852 params->cipher)))
2853 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002854
David S. Miller9360ffd2012-03-29 04:41:26 -04002855 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2856 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002857
2858 nla_nest_end(cookie->msg, key);
2859
Johannes Berg41ade002007-12-19 02:03:29 +01002860 return;
2861 nla_put_failure:
2862 cookie->error = 1;
2863}
2864
2865static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2866{
Johannes Berg4c476992010-10-04 21:36:35 +02002867 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002868 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002869 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002870 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002871 const u8 *mac_addr = NULL;
2872 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002873 struct get_key_cookie cookie = {
2874 .error = 0,
2875 };
2876 void *hdr;
2877 struct sk_buff *msg;
2878
2879 if (info->attrs[NL80211_ATTR_KEY_IDX])
2880 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2881
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002882 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002883 return -EINVAL;
2884
2885 if (info->attrs[NL80211_ATTR_MAC])
2886 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2887
Johannes Berge31b8212010-10-05 19:39:30 +02002888 pairwise = !!mac_addr;
2889 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2890 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2891 if (kt >= NUM_NL80211_KEYTYPES)
2892 return -EINVAL;
2893 if (kt != NL80211_KEYTYPE_GROUP &&
2894 kt != NL80211_KEYTYPE_PAIRWISE)
2895 return -EINVAL;
2896 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2897 }
2898
Johannes Berg4c476992010-10-04 21:36:35 +02002899 if (!rdev->ops->get_key)
2900 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002901
Johannes Berg0fa7b392015-01-23 11:10:12 +01002902 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2903 return -ENOENT;
2904
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002905 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002906 if (!msg)
2907 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002908
Eric W. Biederman15e47302012-09-07 20:12:54 +00002909 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002910 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002911 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002912 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002913
2914 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002915 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002916
David S. Miller9360ffd2012-03-29 04:41:26 -04002917 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2918 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2919 goto nla_put_failure;
2920 if (mac_addr &&
2921 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2922 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002923
Hila Gonene35e4d22012-06-27 17:19:42 +03002924 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2925 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002926
2927 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002928 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002929
2930 if (cookie.error)
2931 goto nla_put_failure;
2932
2933 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002934 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002935
2936 nla_put_failure:
2937 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002938 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002939 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002940 return err;
2941}
2942
2943static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2944{
Johannes Berg4c476992010-10-04 21:36:35 +02002945 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002946 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002947 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002948 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002949
Johannes Bergb9454e82009-07-08 13:29:08 +02002950 err = nl80211_parse_key(info, &key);
2951 if (err)
2952 return err;
2953
2954 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002955 return -EINVAL;
2956
Johannes Bergb9454e82009-07-08 13:29:08 +02002957 /* only support setting default key */
2958 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002959 return -EINVAL;
2960
Johannes Bergfffd0932009-07-08 14:22:54 +02002961 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002962
2963 if (key.def) {
2964 if (!rdev->ops->set_default_key) {
2965 err = -EOPNOTSUPP;
2966 goto out;
2967 }
2968
2969 err = nl80211_key_allowed(dev->ieee80211_ptr);
2970 if (err)
2971 goto out;
2972
Hila Gonene35e4d22012-06-27 17:19:42 +03002973 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002974 key.def_uni, key.def_multi);
2975
2976 if (err)
2977 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002978
Johannes Berg3d23e342009-09-29 23:27:28 +02002979#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002980 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002981#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002982 } else {
2983 if (key.def_uni || !key.def_multi) {
2984 err = -EINVAL;
2985 goto out;
2986 }
2987
2988 if (!rdev->ops->set_default_mgmt_key) {
2989 err = -EOPNOTSUPP;
2990 goto out;
2991 }
2992
2993 err = nl80211_key_allowed(dev->ieee80211_ptr);
2994 if (err)
2995 goto out;
2996
Hila Gonene35e4d22012-06-27 17:19:42 +03002997 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002998 if (err)
2999 goto out;
3000
3001#ifdef CONFIG_CFG80211_WEXT
3002 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3003#endif
3004 }
3005
3006 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003007 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003008
Johannes Berg41ade002007-12-19 02:03:29 +01003009 return err;
3010}
3011
3012static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3013{
Johannes Berg4c476992010-10-04 21:36:35 +02003014 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003015 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003016 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003017 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003018 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003019
Johannes Bergb9454e82009-07-08 13:29:08 +02003020 err = nl80211_parse_key(info, &key);
3021 if (err)
3022 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003023
Johannes Bergb9454e82009-07-08 13:29:08 +02003024 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003025 return -EINVAL;
3026
Johannes Berg41ade002007-12-19 02:03:29 +01003027 if (info->attrs[NL80211_ATTR_MAC])
3028 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3029
Johannes Berge31b8212010-10-05 19:39:30 +02003030 if (key.type == -1) {
3031 if (mac_addr)
3032 key.type = NL80211_KEYTYPE_PAIRWISE;
3033 else
3034 key.type = NL80211_KEYTYPE_GROUP;
3035 }
3036
3037 /* for now */
3038 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3039 key.type != NL80211_KEYTYPE_GROUP)
3040 return -EINVAL;
3041
Johannes Berg4c476992010-10-04 21:36:35 +02003042 if (!rdev->ops->add_key)
3043 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003044
Johannes Berge31b8212010-10-05 19:39:30 +02003045 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3046 key.type == NL80211_KEYTYPE_PAIRWISE,
3047 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003048 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003049
3050 wdev_lock(dev->ieee80211_ptr);
3051 err = nl80211_key_allowed(dev->ieee80211_ptr);
3052 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003053 err = rdev_add_key(rdev, dev, key.idx,
3054 key.type == NL80211_KEYTYPE_PAIRWISE,
3055 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003056 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003057
Johannes Berg41ade002007-12-19 02:03:29 +01003058 return err;
3059}
3060
3061static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3062{
Johannes Berg4c476992010-10-04 21:36:35 +02003063 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003064 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003065 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003066 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003067 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003068
Johannes Bergb9454e82009-07-08 13:29:08 +02003069 err = nl80211_parse_key(info, &key);
3070 if (err)
3071 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003072
3073 if (info->attrs[NL80211_ATTR_MAC])
3074 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3075
Johannes Berge31b8212010-10-05 19:39:30 +02003076 if (key.type == -1) {
3077 if (mac_addr)
3078 key.type = NL80211_KEYTYPE_PAIRWISE;
3079 else
3080 key.type = NL80211_KEYTYPE_GROUP;
3081 }
3082
3083 /* for now */
3084 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3085 key.type != NL80211_KEYTYPE_GROUP)
3086 return -EINVAL;
3087
Johannes Berg4c476992010-10-04 21:36:35 +02003088 if (!rdev->ops->del_key)
3089 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003090
Johannes Bergfffd0932009-07-08 14:22:54 +02003091 wdev_lock(dev->ieee80211_ptr);
3092 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003093
Johannes Berg0fa7b392015-01-23 11:10:12 +01003094 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003095 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3096 err = -ENOENT;
3097
Johannes Bergfffd0932009-07-08 14:22:54 +02003098 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003099 err = rdev_del_key(rdev, dev, key.idx,
3100 key.type == NL80211_KEYTYPE_PAIRWISE,
3101 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003102
Johannes Berg3d23e342009-09-29 23:27:28 +02003103#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003104 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003105 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003106 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003107 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003108 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3109 }
3110#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003111 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003112
Johannes Berg41ade002007-12-19 02:03:29 +01003113 return err;
3114}
3115
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303116/* This function returns an error or the number of nested attributes */
3117static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3118{
3119 struct nlattr *attr;
3120 int n_entries = 0, tmp;
3121
3122 nla_for_each_nested(attr, nl_attr, tmp) {
3123 if (nla_len(attr) != ETH_ALEN)
3124 return -EINVAL;
3125
3126 n_entries++;
3127 }
3128
3129 return n_entries;
3130}
3131
3132/*
3133 * This function parses ACL information and allocates memory for ACL data.
3134 * On successful return, the calling function is responsible to free the
3135 * ACL buffer returned by this function.
3136 */
3137static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3138 struct genl_info *info)
3139{
3140 enum nl80211_acl_policy acl_policy;
3141 struct nlattr *attr;
3142 struct cfg80211_acl_data *acl;
3143 int i = 0, n_entries, tmp;
3144
3145 if (!wiphy->max_acl_mac_addrs)
3146 return ERR_PTR(-EOPNOTSUPP);
3147
3148 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3149 return ERR_PTR(-EINVAL);
3150
3151 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3152 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3153 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3154 return ERR_PTR(-EINVAL);
3155
3156 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3157 return ERR_PTR(-EINVAL);
3158
3159 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3160 if (n_entries < 0)
3161 return ERR_PTR(n_entries);
3162
3163 if (n_entries > wiphy->max_acl_mac_addrs)
3164 return ERR_PTR(-ENOTSUPP);
3165
3166 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3167 GFP_KERNEL);
3168 if (!acl)
3169 return ERR_PTR(-ENOMEM);
3170
3171 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3172 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3173 i++;
3174 }
3175
3176 acl->n_acl_entries = n_entries;
3177 acl->acl_policy = acl_policy;
3178
3179 return acl;
3180}
3181
3182static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3183{
3184 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3185 struct net_device *dev = info->user_ptr[1];
3186 struct cfg80211_acl_data *acl;
3187 int err;
3188
3189 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3190 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3191 return -EOPNOTSUPP;
3192
3193 if (!dev->ieee80211_ptr->beacon_interval)
3194 return -EINVAL;
3195
3196 acl = parse_acl_data(&rdev->wiphy, info);
3197 if (IS_ERR(acl))
3198 return PTR_ERR(acl);
3199
3200 err = rdev_set_mac_acl(rdev, dev, acl);
3201
3202 kfree(acl);
3203
3204 return err;
3205}
3206
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003207static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003208 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003209{
Johannes Berg88600202012-02-13 15:17:18 +01003210 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003211
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003212 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3213 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3214 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3215 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003216 return -EINVAL;
3217
Johannes Berg88600202012-02-13 15:17:18 +01003218 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003219
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003220 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3221 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3222 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003223 if (!bcn->head_len)
3224 return -EINVAL;
3225 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003226 }
3227
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003228 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3229 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3230 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003231 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003232 }
3233
Johannes Berg4c476992010-10-04 21:36:35 +02003234 if (!haveinfo)
3235 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003236
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003237 if (attrs[NL80211_ATTR_IE]) {
3238 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3239 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003240 }
3241
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003242 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003243 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003244 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003245 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003246 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003247 }
3248
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003249 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003250 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003251 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003252 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003253 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003254 }
3255
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003256 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3257 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3258 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003259 }
3260
Johannes Berg88600202012-02-13 15:17:18 +01003261 return 0;
3262}
3263
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003264static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3265 struct cfg80211_ap_settings *params)
3266{
3267 struct wireless_dev *wdev;
3268 bool ret = false;
3269
Johannes Berg89a54e42012-06-15 14:33:17 +02003270 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003271 if (wdev->iftype != NL80211_IFTYPE_AP &&
3272 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3273 continue;
3274
Johannes Berg683b6d32012-11-08 21:25:48 +01003275 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003276 continue;
3277
Johannes Berg683b6d32012-11-08 21:25:48 +01003278 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003279 ret = true;
3280 break;
3281 }
3282
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003283 return ret;
3284}
3285
Jouni Malinene39e5b52012-09-30 19:29:39 +03003286static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3287 enum nl80211_auth_type auth_type,
3288 enum nl80211_commands cmd)
3289{
3290 if (auth_type > NL80211_AUTHTYPE_MAX)
3291 return false;
3292
3293 switch (cmd) {
3294 case NL80211_CMD_AUTHENTICATE:
3295 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3296 auth_type == NL80211_AUTHTYPE_SAE)
3297 return false;
3298 return true;
3299 case NL80211_CMD_CONNECT:
3300 case NL80211_CMD_START_AP:
3301 /* SAE not supported yet */
3302 if (auth_type == NL80211_AUTHTYPE_SAE)
3303 return false;
3304 return true;
3305 default:
3306 return false;
3307 }
3308}
3309
Johannes Berg88600202012-02-13 15:17:18 +01003310static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3311{
3312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3313 struct net_device *dev = info->user_ptr[1];
3314 struct wireless_dev *wdev = dev->ieee80211_ptr;
3315 struct cfg80211_ap_settings params;
3316 int err;
3317
3318 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3319 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3320 return -EOPNOTSUPP;
3321
3322 if (!rdev->ops->start_ap)
3323 return -EOPNOTSUPP;
3324
3325 if (wdev->beacon_interval)
3326 return -EALREADY;
3327
3328 memset(&params, 0, sizeof(params));
3329
3330 /* these are required for START_AP */
3331 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3332 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3333 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3334 return -EINVAL;
3335
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003336 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003337 if (err)
3338 return err;
3339
3340 params.beacon_interval =
3341 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3342 params.dtim_period =
3343 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3344
3345 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3346 if (err)
3347 return err;
3348
3349 /*
3350 * In theory, some of these attributes should be required here
3351 * but since they were not used when the command was originally
3352 * added, keep them optional for old user space programs to let
3353 * them continue to work with drivers that do not need the
3354 * additional information -- drivers must check!
3355 */
3356 if (info->attrs[NL80211_ATTR_SSID]) {
3357 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3358 params.ssid_len =
3359 nla_len(info->attrs[NL80211_ATTR_SSID]);
3360 if (params.ssid_len == 0 ||
3361 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3362 return -EINVAL;
3363 }
3364
3365 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3366 params.hidden_ssid = nla_get_u32(
3367 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3368 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3369 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3370 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3371 return -EINVAL;
3372 }
3373
3374 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3375
3376 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3377 params.auth_type = nla_get_u32(
3378 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003379 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3380 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003381 return -EINVAL;
3382 } else
3383 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3384
3385 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3386 NL80211_MAX_NR_CIPHER_SUITES);
3387 if (err)
3388 return err;
3389
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303390 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3391 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3392 return -EOPNOTSUPP;
3393 params.inactivity_timeout = nla_get_u16(
3394 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3395 }
3396
Johannes Berg53cabad2012-11-14 15:17:28 +01003397 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3398 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3399 return -EINVAL;
3400 params.p2p_ctwindow =
3401 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3402 if (params.p2p_ctwindow > 127)
3403 return -EINVAL;
3404 if (params.p2p_ctwindow != 0 &&
3405 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3406 return -EINVAL;
3407 }
3408
3409 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3410 u8 tmp;
3411
3412 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3413 return -EINVAL;
3414 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3415 if (tmp > 1)
3416 return -EINVAL;
3417 params.p2p_opp_ps = tmp;
3418 if (params.p2p_opp_ps != 0 &&
3419 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3420 return -EINVAL;
3421 }
3422
Johannes Bergaa430da2012-05-16 23:50:18 +02003423 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003424 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3425 if (err)
3426 return err;
3427 } else if (wdev->preset_chandef.chan) {
3428 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003429 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003430 return -EINVAL;
3431
Arik Nemtsov923b3522015-07-08 15:41:44 +03003432 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3433 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003434 return -EINVAL;
3435
Eliad Peller18998c32014-09-10 14:07:34 +03003436 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3437 params.smps_mode =
3438 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3439 switch (params.smps_mode) {
3440 case NL80211_SMPS_OFF:
3441 break;
3442 case NL80211_SMPS_STATIC:
3443 if (!(rdev->wiphy.features &
3444 NL80211_FEATURE_STATIC_SMPS))
3445 return -EINVAL;
3446 break;
3447 case NL80211_SMPS_DYNAMIC:
3448 if (!(rdev->wiphy.features &
3449 NL80211_FEATURE_DYNAMIC_SMPS))
3450 return -EINVAL;
3451 break;
3452 default:
3453 return -EINVAL;
3454 }
3455 } else {
3456 params.smps_mode = NL80211_SMPS_OFF;
3457 }
3458
Ola Olsson4baf6be2015-10-29 07:04:58 +01003459 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3460 params.acl = parse_acl_data(&rdev->wiphy, info);
3461 if (IS_ERR(params.acl))
3462 return PTR_ERR(params.acl);
3463 }
3464
Lior David34d50512016-01-28 10:58:25 +02003465 params.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
3466 if (params.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ])
3467 return -EOPNOTSUPP;
3468
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003469 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003470 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003471 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003472 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003473 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003474 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003475 wdev->ssid_len = params.ssid_len;
3476 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003477 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003478 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303479
3480 kfree(params.acl);
3481
Johannes Berg56d18932011-05-09 18:41:15 +02003482 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003483}
3484
Johannes Berg88600202012-02-13 15:17:18 +01003485static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3486{
3487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3488 struct net_device *dev = info->user_ptr[1];
3489 struct wireless_dev *wdev = dev->ieee80211_ptr;
3490 struct cfg80211_beacon_data params;
3491 int err;
3492
3493 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3494 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3495 return -EOPNOTSUPP;
3496
3497 if (!rdev->ops->change_beacon)
3498 return -EOPNOTSUPP;
3499
3500 if (!wdev->beacon_interval)
3501 return -EINVAL;
3502
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003503 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003504 if (err)
3505 return err;
3506
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003507 wdev_lock(wdev);
3508 err = rdev_change_beacon(rdev, dev, &params);
3509 wdev_unlock(wdev);
3510
3511 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003512}
3513
3514static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003515{
Johannes Berg4c476992010-10-04 21:36:35 +02003516 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3517 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003518
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003519 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003520}
3521
Johannes Berg5727ef12007-12-19 02:03:34 +01003522static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3523 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3524 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3525 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003526 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003527 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003528 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003529};
3530
Johannes Bergeccb8e82009-05-11 21:57:56 +03003531static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003532 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003533 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003534{
3535 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003536 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003537 int flag;
3538
Johannes Bergeccb8e82009-05-11 21:57:56 +03003539 /*
3540 * Try parsing the new attribute first so userspace
3541 * can specify both for older kernels.
3542 */
3543 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3544 if (nla) {
3545 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003546
Johannes Bergeccb8e82009-05-11 21:57:56 +03003547 sta_flags = nla_data(nla);
3548 params->sta_flags_mask = sta_flags->mask;
3549 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003550 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003551 if ((params->sta_flags_mask |
3552 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3553 return -EINVAL;
3554 return 0;
3555 }
3556
3557 /* if present, parse the old attribute */
3558
3559 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003560 if (!nla)
3561 return 0;
3562
3563 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3564 nla, sta_flags_policy))
3565 return -EINVAL;
3566
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003567 /*
3568 * Only allow certain flags for interface types so that
3569 * other attributes are silently ignored. Remember that
3570 * this is backward compatibility code with old userspace
3571 * and shouldn't be hit in other cases anyway.
3572 */
3573 switch (iftype) {
3574 case NL80211_IFTYPE_AP:
3575 case NL80211_IFTYPE_AP_VLAN:
3576 case NL80211_IFTYPE_P2P_GO:
3577 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3578 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3579 BIT(NL80211_STA_FLAG_WME) |
3580 BIT(NL80211_STA_FLAG_MFP);
3581 break;
3582 case NL80211_IFTYPE_P2P_CLIENT:
3583 case NL80211_IFTYPE_STATION:
3584 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3585 BIT(NL80211_STA_FLAG_TDLS_PEER);
3586 break;
3587 case NL80211_IFTYPE_MESH_POINT:
3588 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3589 BIT(NL80211_STA_FLAG_MFP) |
3590 BIT(NL80211_STA_FLAG_AUTHORIZED);
3591 default:
3592 return -EINVAL;
3593 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003594
Johannes Berg3383b5a2012-05-10 20:14:43 +02003595 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3596 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003597 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003598
Johannes Berg3383b5a2012-05-10 20:14:43 +02003599 /* no longer support new API additions in old API */
3600 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3601 return -EINVAL;
3602 }
3603 }
3604
Johannes Berg5727ef12007-12-19 02:03:34 +01003605 return 0;
3606}
3607
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003608static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3609 int attr)
3610{
3611 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003612 u32 bitrate;
3613 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003614 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003615
3616 rate = nla_nest_start(msg, attr);
3617 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003618 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003619
3620 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3621 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003622 /* report 16-bit bitrate only if we can */
3623 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003624 if (bitrate > 0 &&
3625 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3626 return false;
3627 if (bitrate_compat > 0 &&
3628 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3629 return false;
3630
Johannes Bergb51f3be2015-01-15 16:14:02 +01003631 switch (info->bw) {
3632 case RATE_INFO_BW_5:
3633 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3634 break;
3635 case RATE_INFO_BW_10:
3636 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3637 break;
3638 default:
3639 WARN_ON(1);
3640 /* fall through */
3641 case RATE_INFO_BW_20:
3642 rate_flg = 0;
3643 break;
3644 case RATE_INFO_BW_40:
3645 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3646 break;
3647 case RATE_INFO_BW_80:
3648 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3649 break;
3650 case RATE_INFO_BW_160:
3651 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3652 break;
3653 }
3654
3655 if (rate_flg && nla_put_flag(msg, rate_flg))
3656 return false;
3657
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003658 if (info->flags & RATE_INFO_FLAGS_MCS) {
3659 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3660 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003661 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3662 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3663 return false;
3664 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3665 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3666 return false;
3667 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3668 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003669 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3670 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3671 return false;
3672 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003673
3674 nla_nest_end(msg, rate);
3675 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003676}
3677
Felix Fietkau119363c2013-04-22 16:29:30 +02003678static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3679 int id)
3680{
3681 void *attr;
3682 int i = 0;
3683
3684 if (!mask)
3685 return true;
3686
3687 attr = nla_nest_start(msg, id);
3688 if (!attr)
3689 return false;
3690
3691 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3692 if (!(mask & BIT(i)))
3693 continue;
3694
3695 if (nla_put_u8(msg, i, signal[i]))
3696 return false;
3697 }
3698
3699 nla_nest_end(msg, attr);
3700
3701 return true;
3702}
3703
Johannes Bergcf5ead82014-11-14 17:14:00 +01003704static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3705 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003706 struct cfg80211_registered_device *rdev,
3707 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003708 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003709{
3710 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003711 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003712
Johannes Bergcf5ead82014-11-14 17:14:00 +01003713 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003714 if (!hdr)
3715 return -1;
3716
David S. Miller9360ffd2012-03-29 04:41:26 -04003717 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3718 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3719 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3720 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003721
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003722 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3723 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003724 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003725
3726#define PUT_SINFO(attr, memb, type) do { \
3727 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3728 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3729 sinfo->memb)) \
3730 goto nla_put_failure; \
3731 } while (0)
3732
3733 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3734 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3735
3736 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3737 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003738 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003739 (u32)sinfo->rx_bytes))
3740 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003741
3742 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3743 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003744 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3745 (u32)sinfo->tx_bytes))
3746 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003747
3748 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3749 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3750 PUT_SINFO(LLID, llid, u16);
3751 PUT_SINFO(PLID, plid, u16);
3752 PUT_SINFO(PLINK_STATE, plink_state, u8);
3753
John W. Linville66266b32012-03-15 13:25:41 -04003754 switch (rdev->wiphy.signal_type) {
3755 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003756 PUT_SINFO(SIGNAL, signal, u8);
3757 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003758 break;
3759 default:
3760 break;
3761 }
Johannes Berg319090b2014-11-17 14:08:11 +01003762 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003763 if (!nl80211_put_signal(msg, sinfo->chains,
3764 sinfo->chain_signal,
3765 NL80211_STA_INFO_CHAIN_SIGNAL))
3766 goto nla_put_failure;
3767 }
Johannes Berg319090b2014-11-17 14:08:11 +01003768 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003769 if (!nl80211_put_signal(msg, sinfo->chains,
3770 sinfo->chain_signal_avg,
3771 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3772 goto nla_put_failure;
3773 }
Johannes Berg319090b2014-11-17 14:08:11 +01003774 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003775 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3776 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003777 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003778 }
Johannes Berg319090b2014-11-17 14:08:11 +01003779 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003780 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3781 NL80211_STA_INFO_RX_BITRATE))
3782 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003783 }
Johannes Berg319090b2014-11-17 14:08:11 +01003784
3785 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3786 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3787 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3788 PUT_SINFO(TX_FAILED, tx_failed, u32);
3789 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3790 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3791 PUT_SINFO(LOCAL_PM, local_pm, u32);
3792 PUT_SINFO(PEER_PM, peer_pm, u32);
3793 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3794
3795 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003796 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3797 if (!bss_param)
3798 goto nla_put_failure;
3799
David S. Miller9360ffd2012-03-29 04:41:26 -04003800 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3801 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3802 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3803 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3804 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3805 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3806 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3807 sinfo->bss_param.dtim_period) ||
3808 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3809 sinfo->bss_param.beacon_interval))
3810 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003811
3812 nla_nest_end(msg, bss_param);
3813 }
Johannes Berg319090b2014-11-17 14:08:11 +01003814 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003815 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3816 sizeof(struct nl80211_sta_flag_update),
3817 &sinfo->sta_flags))
3818 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003819
3820 PUT_SINFO(T_OFFSET, t_offset, u64);
3821 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003822 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3823 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003824
3825#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003826
3827 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3828 struct nlattr *tidsattr;
3829 int tid;
3830
3831 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3832 if (!tidsattr)
3833 goto nla_put_failure;
3834
3835 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3836 struct cfg80211_tid_stats *tidstats;
3837 struct nlattr *tidattr;
3838
3839 tidstats = &sinfo->pertid[tid];
3840
3841 if (!tidstats->filled)
3842 continue;
3843
3844 tidattr = nla_nest_start(msg, tid + 1);
3845 if (!tidattr)
3846 goto nla_put_failure;
3847
3848#define PUT_TIDVAL(attr, memb, type) do { \
3849 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3850 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3851 tidstats->memb)) \
3852 goto nla_put_failure; \
3853 } while (0)
3854
3855 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3856 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3857 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3858 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3859
3860#undef PUT_TIDVAL
3861 nla_nest_end(msg, tidattr);
3862 }
3863
3864 nla_nest_end(msg, tidsattr);
3865 }
3866
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003867 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003868
Johannes Berg319090b2014-11-17 14:08:11 +01003869 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003870 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3871 sinfo->assoc_req_ies))
3872 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003873
Johannes Berg053c0952015-01-16 22:09:00 +01003874 genlmsg_end(msg, hdr);
3875 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003876
3877 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003878 genlmsg_cancel(msg, hdr);
3879 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003880}
3881
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003882static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003883 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003884{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003885 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003886 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003887 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003888 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003889 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003890 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003891
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003892 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003893 if (err)
3894 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003895
Johannes Berg97990a02013-04-19 01:02:55 +02003896 if (!wdev->netdev) {
3897 err = -EINVAL;
3898 goto out_err;
3899 }
3900
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003901 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003902 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003903 goto out_err;
3904 }
3905
Johannes Bergbba95fe2008-07-29 13:22:51 +02003906 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003907 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003908 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003909 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003910 if (err == -ENOENT)
3911 break;
3912 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003913 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003914
Johannes Bergcf5ead82014-11-14 17:14:00 +01003915 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003916 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003917 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003918 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003919 &sinfo) < 0)
3920 goto out;
3921
3922 sta_idx++;
3923 }
3924
3925
3926 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003927 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003928 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003929 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003930 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003931
3932 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003933}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003934
Johannes Berg5727ef12007-12-19 02:03:34 +01003935static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3936{
Johannes Berg4c476992010-10-04 21:36:35 +02003937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3938 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003939 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003940 struct sk_buff *msg;
3941 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003942 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003943
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003944 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003945
3946 if (!info->attrs[NL80211_ATTR_MAC])
3947 return -EINVAL;
3948
3949 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3950
Johannes Berg4c476992010-10-04 21:36:35 +02003951 if (!rdev->ops->get_station)
3952 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003953
Hila Gonene35e4d22012-06-27 17:19:42 +03003954 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003955 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003956 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003957
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003958 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003959 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003960 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003961
Johannes Bergcf5ead82014-11-14 17:14:00 +01003962 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3963 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003964 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003965 nlmsg_free(msg);
3966 return -ENOBUFS;
3967 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003968
Johannes Berg4c476992010-10-04 21:36:35 +02003969 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003970}
3971
Johannes Berg77ee7c82013-02-15 00:48:33 +01003972int cfg80211_check_station_change(struct wiphy *wiphy,
3973 struct station_parameters *params,
3974 enum cfg80211_station_type statype)
3975{
Ayala Bekere4208422015-10-23 11:20:06 +03003976 if (params->listen_interval != -1 &&
3977 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01003978 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03003979
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003980 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03003981 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
3982 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01003983 return -EINVAL;
3984
3985 /* When you run into this, adjust the code below for the new flag */
3986 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3987
3988 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003989 case CFG80211_STA_MESH_PEER_KERNEL:
3990 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003991 /*
3992 * No ignoring the TDLS flag here -- the userspace mesh
3993 * code doesn't have the bug of including TDLS in the
3994 * mask everywhere.
3995 */
3996 if (params->sta_flags_mask &
3997 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3998 BIT(NL80211_STA_FLAG_MFP) |
3999 BIT(NL80211_STA_FLAG_AUTHORIZED)))
4000 return -EINVAL;
4001 break;
4002 case CFG80211_STA_TDLS_PEER_SETUP:
4003 case CFG80211_STA_TDLS_PEER_ACTIVE:
4004 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4005 return -EINVAL;
4006 /* ignore since it can't change */
4007 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4008 break;
4009 default:
4010 /* disallow mesh-specific things */
4011 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4012 return -EINVAL;
4013 if (params->local_pm)
4014 return -EINVAL;
4015 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4016 return -EINVAL;
4017 }
4018
4019 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4020 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4021 /* TDLS can't be set, ... */
4022 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4023 return -EINVAL;
4024 /*
4025 * ... but don't bother the driver with it. This works around
4026 * a hostapd/wpa_supplicant issue -- it always includes the
4027 * TLDS_PEER flag in the mask even for AP mode.
4028 */
4029 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4030 }
4031
Ayala Beker47edb112015-09-21 15:49:53 +03004032 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4033 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004034 /* reject other things that can't change */
4035 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4036 return -EINVAL;
4037 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4038 return -EINVAL;
4039 if (params->supported_rates)
4040 return -EINVAL;
4041 if (params->ext_capab || params->ht_capa || params->vht_capa)
4042 return -EINVAL;
4043 }
4044
Ayala Beker47edb112015-09-21 15:49:53 +03004045 if (statype != CFG80211_STA_AP_CLIENT &&
4046 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004047 if (params->vlan)
4048 return -EINVAL;
4049 }
4050
4051 switch (statype) {
4052 case CFG80211_STA_AP_MLME_CLIENT:
4053 /* Use this only for authorizing/unauthorizing a station */
4054 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4055 return -EOPNOTSUPP;
4056 break;
4057 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004058 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004059 /* accept only the listed bits */
4060 if (params->sta_flags_mask &
4061 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4062 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4063 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4064 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4065 BIT(NL80211_STA_FLAG_WME) |
4066 BIT(NL80211_STA_FLAG_MFP)))
4067 return -EINVAL;
4068
4069 /* but authenticated/associated only if driver handles it */
4070 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4071 params->sta_flags_mask &
4072 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4073 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4074 return -EINVAL;
4075 break;
4076 case CFG80211_STA_IBSS:
4077 case CFG80211_STA_AP_STA:
4078 /* reject any changes other than AUTHORIZED */
4079 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4080 return -EINVAL;
4081 break;
4082 case CFG80211_STA_TDLS_PEER_SETUP:
4083 /* reject any changes other than AUTHORIZED or WME */
4084 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4085 BIT(NL80211_STA_FLAG_WME)))
4086 return -EINVAL;
4087 /* force (at least) rates when authorizing */
4088 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4089 !params->supported_rates)
4090 return -EINVAL;
4091 break;
4092 case CFG80211_STA_TDLS_PEER_ACTIVE:
4093 /* reject any changes */
4094 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004095 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004096 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4097 return -EINVAL;
4098 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004099 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004100 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4101 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004102 return -EINVAL;
4103 break;
4104 }
4105
4106 return 0;
4107}
4108EXPORT_SYMBOL(cfg80211_check_station_change);
4109
Johannes Berg5727ef12007-12-19 02:03:34 +01004110/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004111 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004112 */
Johannes Berg80b99892011-11-18 16:23:01 +01004113static struct net_device *get_vlan(struct genl_info *info,
4114 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004115{
Johannes Berg463d0182009-07-14 00:33:35 +02004116 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004117 struct net_device *v;
4118 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004119
Johannes Berg80b99892011-11-18 16:23:01 +01004120 if (!vlanattr)
4121 return NULL;
4122
4123 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4124 if (!v)
4125 return ERR_PTR(-ENODEV);
4126
4127 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4128 ret = -EINVAL;
4129 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004130 }
Johannes Berg80b99892011-11-18 16:23:01 +01004131
Johannes Berg77ee7c82013-02-15 00:48:33 +01004132 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4133 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4134 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4135 ret = -EINVAL;
4136 goto error;
4137 }
4138
Johannes Berg80b99892011-11-18 16:23:01 +01004139 if (!netif_running(v)) {
4140 ret = -ENETDOWN;
4141 goto error;
4142 }
4143
4144 return v;
4145 error:
4146 dev_put(v);
4147 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004148}
4149
Johannes Berg94e860f2014-01-20 23:58:15 +01004150static const struct nla_policy
4151nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004152 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4153 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4154};
4155
Johannes Bergff276692013-02-15 00:09:01 +01004156static int nl80211_parse_sta_wme(struct genl_info *info,
4157 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004158{
Jouni Malinendf881292013-02-14 21:10:54 +02004159 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4160 struct nlattr *nla;
4161 int err;
4162
Jouni Malinendf881292013-02-14 21:10:54 +02004163 /* parse WME attributes if present */
4164 if (!info->attrs[NL80211_ATTR_STA_WME])
4165 return 0;
4166
4167 nla = info->attrs[NL80211_ATTR_STA_WME];
4168 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4169 nl80211_sta_wme_policy);
4170 if (err)
4171 return err;
4172
4173 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4174 params->uapsd_queues = nla_get_u8(
4175 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4176 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4177 return -EINVAL;
4178
4179 if (tb[NL80211_STA_WME_MAX_SP])
4180 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4181
4182 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4183 return -EINVAL;
4184
4185 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4186
4187 return 0;
4188}
4189
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304190static int nl80211_parse_sta_channel_info(struct genl_info *info,
4191 struct station_parameters *params)
4192{
4193 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4194 params->supported_channels =
4195 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4196 params->supported_channels_len =
4197 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4198 /*
4199 * Need to include at least one (first channel, number of
4200 * channels) tuple for each subband, and must have proper
4201 * tuples for the rest of the data as well.
4202 */
4203 if (params->supported_channels_len < 2)
4204 return -EINVAL;
4205 if (params->supported_channels_len % 2)
4206 return -EINVAL;
4207 }
4208
4209 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4210 params->supported_oper_classes =
4211 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4212 params->supported_oper_classes_len =
4213 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4214 /*
4215 * The value of the Length field of the Supported Operating
4216 * Classes element is between 2 and 253.
4217 */
4218 if (params->supported_oper_classes_len < 2 ||
4219 params->supported_oper_classes_len > 253)
4220 return -EINVAL;
4221 }
4222 return 0;
4223}
4224
Johannes Bergff276692013-02-15 00:09:01 +01004225static int nl80211_set_station_tdls(struct genl_info *info,
4226 struct station_parameters *params)
4227{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304228 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004229 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004230 if (info->attrs[NL80211_ATTR_PEER_AID])
4231 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004232 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4233 params->ht_capa =
4234 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4235 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4236 params->vht_capa =
4237 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4238
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304239 err = nl80211_parse_sta_channel_info(info, params);
4240 if (err)
4241 return err;
4242
Johannes Bergff276692013-02-15 00:09:01 +01004243 return nl80211_parse_sta_wme(info, params);
4244}
4245
Johannes Berg5727ef12007-12-19 02:03:34 +01004246static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4247{
Johannes Berg4c476992010-10-04 21:36:35 +02004248 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004249 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004250 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004251 u8 *mac_addr;
4252 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004253
4254 memset(&params, 0, sizeof(params));
4255
Johannes Berg77ee7c82013-02-15 00:48:33 +01004256 if (!rdev->ops->change_station)
4257 return -EOPNOTSUPP;
4258
Ayala Bekere4208422015-10-23 11:20:06 +03004259 /*
4260 * AID and listen_interval properties can be set only for unassociated
4261 * station. Include these parameters here and will check them in
4262 * cfg80211_check_station_change().
4263 */
Ayala Bekera9bc31e2015-11-26 16:26:12 +01004264 if (info->attrs[NL80211_ATTR_STA_AID])
4265 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Ayala Bekere4208422015-10-23 11:20:06 +03004266
4267 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4268 params.listen_interval =
4269 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4270 else
4271 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004272
4273 if (!info->attrs[NL80211_ATTR_MAC])
4274 return -EINVAL;
4275
4276 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4277
4278 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4279 params.supported_rates =
4280 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4281 params.supported_rates_len =
4282 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4283 }
4284
Jouni Malinen9d62a982013-02-14 21:10:13 +02004285 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4286 params.capability =
4287 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4288 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4289 }
4290
4291 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4292 params.ext_capab =
4293 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4294 params.ext_capab_len =
4295 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4296 }
4297
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004298 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004299 return -EINVAL;
4300
Johannes Bergf8bacc22013-02-14 23:27:01 +01004301 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004302 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004303 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4304 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4305 return -EINVAL;
4306 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004307
Johannes Bergf8bacc22013-02-14 23:27:01 +01004308 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004309 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004310 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4311 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4312 return -EINVAL;
4313 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4314 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004315
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004316 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4317 enum nl80211_mesh_power_mode pm = nla_get_u32(
4318 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4319
4320 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4321 pm > NL80211_MESH_POWER_MAX)
4322 return -EINVAL;
4323
4324 params.local_pm = pm;
4325 }
4326
Johannes Berg77ee7c82013-02-15 00:48:33 +01004327 /* Include parameters for TDLS peer (will check later) */
4328 err = nl80211_set_station_tdls(info, &params);
4329 if (err)
4330 return err;
4331
4332 params.vlan = get_vlan(info, rdev);
4333 if (IS_ERR(params.vlan))
4334 return PTR_ERR(params.vlan);
4335
Johannes Berga97f4422009-06-18 17:23:43 +02004336 switch (dev->ieee80211_ptr->iftype) {
4337 case NL80211_IFTYPE_AP:
4338 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004339 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004340 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004341 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004342 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004343 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004344 break;
4345 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004346 err = -EOPNOTSUPP;
4347 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004348 }
4349
Johannes Berg77ee7c82013-02-15 00:48:33 +01004350 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004351 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004352
Johannes Berg77ee7c82013-02-15 00:48:33 +01004353 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004354 if (params.vlan)
4355 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004356
Johannes Berg5727ef12007-12-19 02:03:34 +01004357 return err;
4358}
4359
4360static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4361{
Johannes Berg4c476992010-10-04 21:36:35 +02004362 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004363 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004364 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004365 struct station_parameters params;
4366 u8 *mac_addr = NULL;
Johannes Bergbda95eb2015-11-26 16:26:13 +01004367 u32 auth_assoc = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4368 BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg5727ef12007-12-19 02:03:34 +01004369
4370 memset(&params, 0, sizeof(params));
4371
Johannes Berg984c3112013-02-14 23:43:25 +01004372 if (!rdev->ops->add_station)
4373 return -EOPNOTSUPP;
4374
Johannes Berg5727ef12007-12-19 02:03:34 +01004375 if (!info->attrs[NL80211_ATTR_MAC])
4376 return -EINVAL;
4377
Johannes Berg5727ef12007-12-19 02:03:34 +01004378 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4379 return -EINVAL;
4380
4381 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4382 return -EINVAL;
4383
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004384 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4385 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004386 return -EINVAL;
4387
Johannes Berg5727ef12007-12-19 02:03:34 +01004388 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4389 params.supported_rates =
4390 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4391 params.supported_rates_len =
4392 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4393 params.listen_interval =
4394 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004395
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004396 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004397 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004398 else
4399 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004400 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4401 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004402
Jouni Malinen9d62a982013-02-14 21:10:13 +02004403 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4404 params.capability =
4405 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4406 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4407 }
4408
4409 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4410 params.ext_capab =
4411 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4412 params.ext_capab_len =
4413 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4414 }
4415
Jouni Malinen36aedc92008-08-25 11:58:58 +03004416 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4417 params.ht_capa =
4418 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004419
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004420 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4421 params.vht_capa =
4422 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4423
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004424 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4425 params.opmode_notif_used = true;
4426 params.opmode_notif =
4427 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4428 }
4429
Johannes Bergf8bacc22013-02-14 23:27:01 +01004430 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004431 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004432 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4433 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4434 return -EINVAL;
4435 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004436
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304437 err = nl80211_parse_sta_channel_info(info, &params);
4438 if (err)
4439 return err;
4440
Johannes Bergff276692013-02-15 00:09:01 +01004441 err = nl80211_parse_sta_wme(info, &params);
4442 if (err)
4443 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004444
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004445 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004446 return -EINVAL;
4447
Johannes Berg496fcc22015-03-12 08:53:27 +02004448 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4449 * as userspace might just pass through the capabilities from the IEs
4450 * directly, rather than enforcing this restriction and returning an
4451 * error in this case.
4452 */
4453 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4454 params.ht_capa = NULL;
4455 params.vht_capa = NULL;
4456 }
4457
Johannes Berg77ee7c82013-02-15 00:48:33 +01004458 /* When you run into this, adjust the code below for the new flag */
4459 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4460
Johannes Bergbdd90d52011-12-14 12:20:27 +01004461 switch (dev->ieee80211_ptr->iftype) {
4462 case NL80211_IFTYPE_AP:
4463 case NL80211_IFTYPE_AP_VLAN:
4464 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004465 /* ignore WME attributes if iface/sta is not capable */
4466 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4467 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4468 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004469
Johannes Bergbdd90d52011-12-14 12:20:27 +01004470 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004471 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4472 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004473 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004474 /* but don't bother the driver with it */
4475 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004476
Johannes Bergd582cff2012-10-26 17:53:44 +02004477 /* allow authenticated/associated only if driver handles it */
4478 if (!(rdev->wiphy.features &
4479 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
Johannes Bergbda95eb2015-11-26 16:26:13 +01004480 params.sta_flags_mask & auth_assoc)
Johannes Bergd582cff2012-10-26 17:53:44 +02004481 return -EINVAL;
4482
Johannes Bergbda95eb2015-11-26 16:26:13 +01004483 /* Older userspace, or userspace wanting to be compatible with
4484 * !NL80211_FEATURE_FULL_AP_CLIENT_STATE, will not set the auth
4485 * and assoc flags in the mask, but assumes the station will be
4486 * added as associated anyway since this was the required driver
4487 * behaviour before NL80211_FEATURE_FULL_AP_CLIENT_STATE was
4488 * introduced.
4489 * In order to not bother drivers with this quirk in the API
4490 * set the flags in both the mask and set for new stations in
4491 * this case.
4492 */
4493 if (!(params.sta_flags_mask & auth_assoc)) {
4494 params.sta_flags_mask |= auth_assoc;
4495 params.sta_flags_set |= auth_assoc;
4496 }
4497
Johannes Bergbdd90d52011-12-14 12:20:27 +01004498 /* must be last in here for error handling */
4499 params.vlan = get_vlan(info, rdev);
4500 if (IS_ERR(params.vlan))
4501 return PTR_ERR(params.vlan);
4502 break;
4503 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004504 /* ignore uAPSD data */
4505 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4506
Johannes Bergd582cff2012-10-26 17:53:44 +02004507 /* associated is disallowed */
4508 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4509 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004510 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004511 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4512 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004513 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004514 break;
4515 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004516 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004517 /* ignore uAPSD data */
4518 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4519
Johannes Berg77ee7c82013-02-15 00:48:33 +01004520 /* these are disallowed */
4521 if (params.sta_flags_mask &
4522 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4523 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004524 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004525 /* Only TDLS peers can be added */
4526 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4527 return -EINVAL;
4528 /* Can only add if TDLS ... */
4529 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4530 return -EOPNOTSUPP;
4531 /* ... with external setup is supported */
4532 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4533 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004534 /*
4535 * Older wpa_supplicant versions always mark the TDLS peer
4536 * as authorized, but it shouldn't yet be.
4537 */
4538 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004539 break;
4540 default:
4541 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004542 }
4543
Johannes Bergbdd90d52011-12-14 12:20:27 +01004544 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004545
Hila Gonene35e4d22012-06-27 17:19:42 +03004546 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004547
Johannes Berg5727ef12007-12-19 02:03:34 +01004548 if (params.vlan)
4549 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004550 return err;
4551}
4552
4553static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4554{
Johannes Berg4c476992010-10-04 21:36:35 +02004555 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4556 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004557 struct station_del_parameters params;
4558
4559 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004560
4561 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004562 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004563
Johannes Berge80cf852009-05-11 14:43:13 +02004564 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004565 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004566 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004567 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4568 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004569
Johannes Berg4c476992010-10-04 21:36:35 +02004570 if (!rdev->ops->del_station)
4571 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004572
Jouni Malinen98856862014-10-20 13:20:45 +03004573 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4574 params.subtype =
4575 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4576 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4577 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4578 return -EINVAL;
4579 } else {
4580 /* Default to Deauthentication frame */
4581 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4582 }
4583
4584 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4585 params.reason_code =
4586 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4587 if (params.reason_code == 0)
4588 return -EINVAL; /* 0 is reserved */
4589 } else {
4590 /* Default to reason code 2 */
4591 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4592 }
4593
Jouni Malinen89c771e2014-10-10 20:52:40 +03004594 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004595}
4596
Eric W. Biederman15e47302012-09-07 20:12:54 +00004597static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004598 int flags, struct net_device *dev,
4599 u8 *dst, u8 *next_hop,
4600 struct mpath_info *pinfo)
4601{
4602 void *hdr;
4603 struct nlattr *pinfoattr;
4604
Henning Rogge1ef4c852014-11-04 16:14:58 +01004605 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004606 if (!hdr)
4607 return -1;
4608
David S. Miller9360ffd2012-03-29 04:41:26 -04004609 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4610 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4611 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4612 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4613 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004614
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004615 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4616 if (!pinfoattr)
4617 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004618 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4619 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4620 pinfo->frame_qlen))
4621 goto nla_put_failure;
4622 if (((pinfo->filled & MPATH_INFO_SN) &&
4623 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4624 ((pinfo->filled & MPATH_INFO_METRIC) &&
4625 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4626 pinfo->metric)) ||
4627 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4628 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4629 pinfo->exptime)) ||
4630 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4631 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4632 pinfo->flags)) ||
4633 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4634 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4635 pinfo->discovery_timeout)) ||
4636 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4637 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4638 pinfo->discovery_retries)))
4639 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004640
4641 nla_nest_end(msg, pinfoattr);
4642
Johannes Berg053c0952015-01-16 22:09:00 +01004643 genlmsg_end(msg, hdr);
4644 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004645
4646 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004647 genlmsg_cancel(msg, hdr);
4648 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004649}
4650
4651static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004652 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004653{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004654 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004655 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004656 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004657 u8 dst[ETH_ALEN];
4658 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004659 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004660 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004661
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004662 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004663 if (err)
4664 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004665
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004666 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004667 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004668 goto out_err;
4669 }
4670
Johannes Berg97990a02013-04-19 01:02:55 +02004671 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004672 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004673 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004674 }
4675
Johannes Bergbba95fe2008-07-29 13:22:51 +02004676 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004677 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004678 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004679 if (err == -ENOENT)
4680 break;
4681 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004682 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004683
Eric W. Biederman15e47302012-09-07 20:12:54 +00004684 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004685 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004686 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004687 &pinfo) < 0)
4688 goto out;
4689
4690 path_idx++;
4691 }
4692
4693
4694 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004695 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004696 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004697 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004698 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004699 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004700}
4701
4702static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4703{
Johannes Berg4c476992010-10-04 21:36:35 +02004704 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004705 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004706 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004707 struct mpath_info pinfo;
4708 struct sk_buff *msg;
4709 u8 *dst = NULL;
4710 u8 next_hop[ETH_ALEN];
4711
4712 memset(&pinfo, 0, sizeof(pinfo));
4713
4714 if (!info->attrs[NL80211_ATTR_MAC])
4715 return -EINVAL;
4716
4717 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4718
Johannes Berg4c476992010-10-04 21:36:35 +02004719 if (!rdev->ops->get_mpath)
4720 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004721
Johannes Berg4c476992010-10-04 21:36:35 +02004722 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4723 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004724
Hila Gonene35e4d22012-06-27 17:19:42 +03004725 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004726 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004727 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004728
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004729 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004730 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004731 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004732
Eric W. Biederman15e47302012-09-07 20:12:54 +00004733 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004734 dev, dst, next_hop, &pinfo) < 0) {
4735 nlmsg_free(msg);
4736 return -ENOBUFS;
4737 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004738
Johannes Berg4c476992010-10-04 21:36:35 +02004739 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004740}
4741
4742static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4743{
Johannes Berg4c476992010-10-04 21:36:35 +02004744 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4745 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004746 u8 *dst = NULL;
4747 u8 *next_hop = NULL;
4748
4749 if (!info->attrs[NL80211_ATTR_MAC])
4750 return -EINVAL;
4751
4752 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4753 return -EINVAL;
4754
4755 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4756 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4757
Johannes Berg4c476992010-10-04 21:36:35 +02004758 if (!rdev->ops->change_mpath)
4759 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004760
Johannes Berg4c476992010-10-04 21:36:35 +02004761 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4762 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004763
Hila Gonene35e4d22012-06-27 17:19:42 +03004764 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004765}
Johannes Berg4c476992010-10-04 21:36:35 +02004766
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004767static int nl80211_new_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];
4770 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004771 u8 *dst = NULL;
4772 u8 *next_hop = NULL;
4773
4774 if (!info->attrs[NL80211_ATTR_MAC])
4775 return -EINVAL;
4776
4777 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4778 return -EINVAL;
4779
4780 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4781 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4782
Johannes Berg4c476992010-10-04 21:36:35 +02004783 if (!rdev->ops->add_mpath)
4784 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004785
Johannes Berg4c476992010-10-04 21:36:35 +02004786 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4787 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004788
Hila Gonene35e4d22012-06-27 17:19:42 +03004789 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004790}
4791
4792static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4793{
Johannes Berg4c476992010-10-04 21:36:35 +02004794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4795 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004796 u8 *dst = NULL;
4797
4798 if (info->attrs[NL80211_ATTR_MAC])
4799 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4800
Johannes Berg4c476992010-10-04 21:36:35 +02004801 if (!rdev->ops->del_mpath)
4802 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004803
Hila Gonene35e4d22012-06-27 17:19:42 +03004804 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004805}
4806
Henning Rogge66be7d22014-09-12 08:58:49 +02004807static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4808{
4809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4810 int err;
4811 struct net_device *dev = info->user_ptr[1];
4812 struct mpath_info pinfo;
4813 struct sk_buff *msg;
4814 u8 *dst = NULL;
4815 u8 mpp[ETH_ALEN];
4816
4817 memset(&pinfo, 0, sizeof(pinfo));
4818
4819 if (!info->attrs[NL80211_ATTR_MAC])
4820 return -EINVAL;
4821
4822 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4823
4824 if (!rdev->ops->get_mpp)
4825 return -EOPNOTSUPP;
4826
4827 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4828 return -EOPNOTSUPP;
4829
4830 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4831 if (err)
4832 return err;
4833
4834 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4835 if (!msg)
4836 return -ENOMEM;
4837
4838 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4839 dev, dst, mpp, &pinfo) < 0) {
4840 nlmsg_free(msg);
4841 return -ENOBUFS;
4842 }
4843
4844 return genlmsg_reply(msg, info);
4845}
4846
4847static int nl80211_dump_mpp(struct sk_buff *skb,
4848 struct netlink_callback *cb)
4849{
4850 struct mpath_info pinfo;
4851 struct cfg80211_registered_device *rdev;
4852 struct wireless_dev *wdev;
4853 u8 dst[ETH_ALEN];
4854 u8 mpp[ETH_ALEN];
4855 int path_idx = cb->args[2];
4856 int err;
4857
4858 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4859 if (err)
4860 return err;
4861
4862 if (!rdev->ops->dump_mpp) {
4863 err = -EOPNOTSUPP;
4864 goto out_err;
4865 }
4866
4867 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4868 err = -EOPNOTSUPP;
4869 goto out_err;
4870 }
4871
4872 while (1) {
4873 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4874 mpp, &pinfo);
4875 if (err == -ENOENT)
4876 break;
4877 if (err)
4878 goto out_err;
4879
4880 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4881 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4882 wdev->netdev, dst, mpp,
4883 &pinfo) < 0)
4884 goto out;
4885
4886 path_idx++;
4887 }
4888
4889 out:
4890 cb->args[2] = path_idx;
4891 err = skb->len;
4892 out_err:
4893 nl80211_finish_wdev_dump(rdev);
4894 return err;
4895}
4896
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004897static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4898{
Johannes Berg4c476992010-10-04 21:36:35 +02004899 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4900 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004901 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004902 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004903 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004904
4905 memset(&params, 0, sizeof(params));
4906 /* default to not changing parameters */
4907 params.use_cts_prot = -1;
4908 params.use_short_preamble = -1;
4909 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004910 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004911 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004912 params.p2p_ctwindow = -1;
4913 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004914
4915 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4916 params.use_cts_prot =
4917 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4918 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4919 params.use_short_preamble =
4920 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4921 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4922 params.use_short_slot_time =
4923 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004924 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4925 params.basic_rates =
4926 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4927 params.basic_rates_len =
4928 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4929 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004930 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4931 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004932 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4933 params.ht_opmode =
4934 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004935
Johannes Berg53cabad2012-11-14 15:17:28 +01004936 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4937 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4938 return -EINVAL;
4939 params.p2p_ctwindow =
4940 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4941 if (params.p2p_ctwindow < 0)
4942 return -EINVAL;
4943 if (params.p2p_ctwindow != 0 &&
4944 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4945 return -EINVAL;
4946 }
4947
4948 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4949 u8 tmp;
4950
4951 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4952 return -EINVAL;
4953 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4954 if (tmp > 1)
4955 return -EINVAL;
4956 params.p2p_opp_ps = tmp;
4957 if (params.p2p_opp_ps &&
4958 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4959 return -EINVAL;
4960 }
4961
Johannes Berg4c476992010-10-04 21:36:35 +02004962 if (!rdev->ops->change_bss)
4963 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004964
Johannes Berg074ac8d2010-09-16 14:58:22 +02004965 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004966 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4967 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004968
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004969 wdev_lock(wdev);
4970 err = rdev_change_bss(rdev, dev, &params);
4971 wdev_unlock(wdev);
4972
4973 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004974}
4975
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004976static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4977{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004978 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05004979 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004980 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05004981 u32 owner_nlportid;
4982
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004983
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004984 /*
4985 * You should only get this when cfg80211 hasn't yet initialized
4986 * completely when built-in to the kernel right between the time
4987 * window between nl80211_init() and regulatory_init(), if that is
4988 * even possible.
4989 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004990 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004991 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004992
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004993 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4994 user_reg_hint_type =
4995 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4996 else
4997 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4998
4999 switch (user_reg_hint_type) {
5000 case NL80211_USER_REG_HINT_USER:
5001 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005002 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5003 return -EINVAL;
5004
5005 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5006 return regulatory_hint_user(data, user_reg_hint_type);
5007 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005008 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5009 owner_nlportid = info->snd_portid;
5010 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5011 } else {
5012 owner_nlportid = 0;
5013 is_indoor = true;
5014 }
5015
5016 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005017 default:
5018 return -EINVAL;
5019 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005020}
5021
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005022static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005023 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005024{
Johannes Berg4c476992010-10-04 21:36:35 +02005025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005026 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005027 struct wireless_dev *wdev = dev->ieee80211_ptr;
5028 struct mesh_config cur_params;
5029 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005030 void *hdr;
5031 struct nlattr *pinfoattr;
5032 struct sk_buff *msg;
5033
Johannes Berg29cbe682010-12-03 09:20:44 +01005034 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5035 return -EOPNOTSUPP;
5036
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005037 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005038 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005039
Johannes Berg29cbe682010-12-03 09:20:44 +01005040 wdev_lock(wdev);
5041 /* If not connected, get default parameters */
5042 if (!wdev->mesh_id_len)
5043 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5044 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005045 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005046 wdev_unlock(wdev);
5047
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005048 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005049 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005050
5051 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005052 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005053 if (!msg)
5054 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005055 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005056 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005057 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005058 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005059 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005060 if (!pinfoattr)
5061 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005062 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5063 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5064 cur_params.dot11MeshRetryTimeout) ||
5065 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5066 cur_params.dot11MeshConfirmTimeout) ||
5067 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5068 cur_params.dot11MeshHoldingTimeout) ||
5069 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5070 cur_params.dot11MeshMaxPeerLinks) ||
5071 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5072 cur_params.dot11MeshMaxRetries) ||
5073 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5074 cur_params.dot11MeshTTL) ||
5075 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5076 cur_params.element_ttl) ||
5077 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5078 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005079 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5080 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005081 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5082 cur_params.dot11MeshHWMPmaxPREQretries) ||
5083 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5084 cur_params.path_refresh_time) ||
5085 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5086 cur_params.min_discovery_timeout) ||
5087 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5088 cur_params.dot11MeshHWMPactivePathTimeout) ||
5089 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5090 cur_params.dot11MeshHWMPpreqMinInterval) ||
5091 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5092 cur_params.dot11MeshHWMPperrMinInterval) ||
5093 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5094 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5095 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5096 cur_params.dot11MeshHWMPRootMode) ||
5097 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5098 cur_params.dot11MeshHWMPRannInterval) ||
5099 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5100 cur_params.dot11MeshGateAnnouncementProtocol) ||
5101 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5102 cur_params.dot11MeshForwarding) ||
5103 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005104 cur_params.rssi_threshold) ||
5105 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005106 cur_params.ht_opmode) ||
5107 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5108 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5109 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005110 cur_params.dot11MeshHWMProotInterval) ||
5111 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005112 cur_params.dot11MeshHWMPconfirmationInterval) ||
5113 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5114 cur_params.power_mode) ||
5115 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005116 cur_params.dot11MeshAwakeWindowDuration) ||
5117 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5118 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005119 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005120 nla_nest_end(msg, pinfoattr);
5121 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005122 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005123
Johannes Berg3b858752009-03-12 09:55:09 +01005124 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005125 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005126 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005127 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005128 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005129}
5130
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005131static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005132 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5133 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5134 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5135 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5136 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5137 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005138 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005139 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005140 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005141 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5142 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5143 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5144 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5145 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005146 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005147 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005148 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005149 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005150 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005151 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005152 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5153 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005154 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5155 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005156 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005157 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5158 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005159 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005160};
5161
Javier Cardonac80d5452010-12-16 17:37:49 -08005162static const struct nla_policy
5163 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005164 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005165 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5166 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005167 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005168 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005169 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005170 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005171 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005172 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005173};
5174
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005175static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005176 struct mesh_config *cfg,
5177 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005178{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005179 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005180 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005181
Marco Porschea54fba2013-01-07 16:04:48 +01005182#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5183do { \
5184 if (tb[attr]) { \
5185 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5186 return -EINVAL; \
5187 cfg->param = fn(tb[attr]); \
5188 mask |= (1 << (attr - 1)); \
5189 } \
5190} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005191
5192
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005193 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005194 return -EINVAL;
5195 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005196 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005197 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005198 return -EINVAL;
5199
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005200 /* This makes sure that there aren't more than 32 mesh config
5201 * parameters (otherwise our bitfield scheme would not work.) */
5202 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5203
5204 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005205 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005206 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5207 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005208 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005209 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5210 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005211 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005212 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5213 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005214 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005215 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5216 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005217 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005218 mask, NL80211_MESHCONF_MAX_RETRIES,
5219 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005220 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005221 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005222 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005223 mask, NL80211_MESHCONF_ELEMENT_TTL,
5224 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005225 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005226 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5227 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005228 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5229 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005230 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5231 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005233 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5234 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005235 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005236 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5237 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005239 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5240 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005241 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5242 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005243 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5244 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005245 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005246 1, 65535, mask,
5247 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005248 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005249 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005250 1, 65535, mask,
5251 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005252 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005253 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005254 dot11MeshHWMPnetDiameterTraversalTime,
5255 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005256 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5257 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005258 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5259 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5260 nla_get_u8);
5261 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5262 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005263 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005264 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005265 dot11MeshGateAnnouncementProtocol, 0, 1,
5266 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005267 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005268 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005269 mask, NL80211_MESHCONF_FORWARDING,
5270 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005271 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005272 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005273 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005274 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005275 mask, NL80211_MESHCONF_HT_OPMODE,
5276 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005277 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005278 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005279 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5280 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005281 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005282 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5283 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005284 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005285 dot11MeshHWMPconfirmationInterval,
5286 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005287 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5288 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005289 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5290 NL80211_MESH_POWER_ACTIVE,
5291 NL80211_MESH_POWER_MAX,
5292 mask, NL80211_MESHCONF_POWER_MODE,
5293 nla_get_u32);
5294 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5295 0, 65535, mask,
5296 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005297 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005298 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5299 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005300 if (mask_out)
5301 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005302
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005303 return 0;
5304
5305#undef FILL_IN_MESH_PARAM_IF_SET
5306}
5307
Javier Cardonac80d5452010-12-16 17:37:49 -08005308static int nl80211_parse_mesh_setup(struct genl_info *info,
5309 struct mesh_setup *setup)
5310{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005312 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5313
5314 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5315 return -EINVAL;
5316 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5317 info->attrs[NL80211_ATTR_MESH_SETUP],
5318 nl80211_mesh_setup_params_policy))
5319 return -EINVAL;
5320
Javier Cardonad299a1f2012-03-31 11:31:33 -07005321 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5322 setup->sync_method =
5323 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5324 IEEE80211_SYNC_METHOD_VENDOR :
5325 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5326
Javier Cardonac80d5452010-12-16 17:37:49 -08005327 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5328 setup->path_sel_proto =
5329 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5330 IEEE80211_PATH_PROTOCOL_VENDOR :
5331 IEEE80211_PATH_PROTOCOL_HWMP;
5332
5333 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5334 setup->path_metric =
5335 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5336 IEEE80211_PATH_METRIC_VENDOR :
5337 IEEE80211_PATH_METRIC_AIRTIME;
5338
Javier Cardona581a8b02011-04-07 15:08:27 -07005339
5340 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005341 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005342 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005343 if (!is_valid_ie_attr(ieattr))
5344 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005345 setup->ie = nla_data(ieattr);
5346 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005347 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005348 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5349 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5350 return -EINVAL;
5351 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005352 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5353 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005354 if (setup->is_secure)
5355 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005356
Colleen Twitty6e16d902013-05-08 11:45:59 -07005357 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5358 if (!setup->user_mpm)
5359 return -EINVAL;
5360 setup->auth_id =
5361 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5362 }
5363
Javier Cardonac80d5452010-12-16 17:37:49 -08005364 return 0;
5365}
5366
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005367static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005368 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005369{
5370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5371 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005372 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005373 struct mesh_config cfg;
5374 u32 mask;
5375 int err;
5376
Johannes Berg29cbe682010-12-03 09:20:44 +01005377 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5378 return -EOPNOTSUPP;
5379
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005380 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005381 return -EOPNOTSUPP;
5382
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005383 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005384 if (err)
5385 return err;
5386
Johannes Berg29cbe682010-12-03 09:20:44 +01005387 wdev_lock(wdev);
5388 if (!wdev->mesh_id_len)
5389 err = -ENOLINK;
5390
5391 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005392 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005393
5394 wdev_unlock(wdev);
5395
5396 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005397}
5398
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005399static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5400 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005401{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005402 struct nlattr *nl_reg_rules;
5403 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005404
Johannes Berg458f4f92012-12-06 15:47:38 +01005405 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5406 (regdom->dfs_region &&
5407 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005408 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005409
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005410 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5411 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005412 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005413
Johannes Berg458f4f92012-12-06 15:47:38 +01005414 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005415 struct nlattr *nl_reg_rule;
5416 const struct ieee80211_reg_rule *reg_rule;
5417 const struct ieee80211_freq_range *freq_range;
5418 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005419 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005420
Johannes Berg458f4f92012-12-06 15:47:38 +01005421 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005422 freq_range = &reg_rule->freq_range;
5423 power_rule = &reg_rule->power_rule;
5424
5425 nl_reg_rule = nla_nest_start(msg, i);
5426 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005427 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005428
Janusz Dziedzic97524822014-01-30 09:52:20 +01005429 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5430 if (!max_bandwidth_khz)
5431 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5432 reg_rule);
5433
David S. Miller9360ffd2012-03-29 04:41:26 -04005434 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5435 reg_rule->flags) ||
5436 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5437 freq_range->start_freq_khz) ||
5438 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5439 freq_range->end_freq_khz) ||
5440 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005441 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005442 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5443 power_rule->max_antenna_gain) ||
5444 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005445 power_rule->max_eirp) ||
5446 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5447 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005448 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005449
5450 nla_nest_end(msg, nl_reg_rule);
5451 }
5452
5453 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005454 return 0;
5455
5456nla_put_failure:
5457 return -EMSGSIZE;
5458}
5459
5460static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5461{
5462 const struct ieee80211_regdomain *regdom = NULL;
5463 struct cfg80211_registered_device *rdev;
5464 struct wiphy *wiphy = NULL;
5465 struct sk_buff *msg;
5466 void *hdr;
5467
5468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5469 if (!msg)
5470 return -ENOBUFS;
5471
5472 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5473 NL80211_CMD_GET_REG);
5474 if (!hdr)
5475 goto put_failure;
5476
5477 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005478 bool self_managed;
5479
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005480 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5481 if (IS_ERR(rdev)) {
5482 nlmsg_free(msg);
5483 return PTR_ERR(rdev);
5484 }
5485
5486 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005487 self_managed = wiphy->regulatory_flags &
5488 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005489 regdom = get_wiphy_regdom(wiphy);
5490
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005491 /* a self-managed-reg device must have a private regdom */
5492 if (WARN_ON(!regdom && self_managed)) {
5493 nlmsg_free(msg);
5494 return -EINVAL;
5495 }
5496
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005497 if (regdom &&
5498 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5499 goto nla_put_failure;
5500 }
5501
5502 if (!wiphy && reg_last_request_cell_base() &&
5503 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5504 NL80211_USER_REG_HINT_CELL_BASE))
5505 goto nla_put_failure;
5506
5507 rcu_read_lock();
5508
5509 if (!regdom)
5510 regdom = rcu_dereference(cfg80211_regdomain);
5511
5512 if (nl80211_put_regdom(regdom, msg))
5513 goto nla_put_failure_rcu;
5514
5515 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005516
5517 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005518 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005519
Johannes Berg458f4f92012-12-06 15:47:38 +01005520nla_put_failure_rcu:
5521 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005522nla_put_failure:
5523 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005524put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005525 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005526 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005527}
5528
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005529static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5530 u32 seq, int flags, struct wiphy *wiphy,
5531 const struct ieee80211_regdomain *regdom)
5532{
5533 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5534 NL80211_CMD_GET_REG);
5535
5536 if (!hdr)
5537 return -1;
5538
5539 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5540
5541 if (nl80211_put_regdom(regdom, msg))
5542 goto nla_put_failure;
5543
5544 if (!wiphy && reg_last_request_cell_base() &&
5545 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5546 NL80211_USER_REG_HINT_CELL_BASE))
5547 goto nla_put_failure;
5548
5549 if (wiphy &&
5550 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5551 goto nla_put_failure;
5552
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005553 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5554 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5555 goto nla_put_failure;
5556
Johannes Berg053c0952015-01-16 22:09:00 +01005557 genlmsg_end(msg, hdr);
5558 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005559
5560nla_put_failure:
5561 genlmsg_cancel(msg, hdr);
5562 return -EMSGSIZE;
5563}
5564
5565static int nl80211_get_reg_dump(struct sk_buff *skb,
5566 struct netlink_callback *cb)
5567{
5568 const struct ieee80211_regdomain *regdom = NULL;
5569 struct cfg80211_registered_device *rdev;
5570 int err, reg_idx, start = cb->args[2];
5571
5572 rtnl_lock();
5573
5574 if (cfg80211_regdomain && start == 0) {
5575 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5576 NLM_F_MULTI, NULL,
5577 rtnl_dereference(cfg80211_regdomain));
5578 if (err < 0)
5579 goto out_err;
5580 }
5581
5582 /* the global regdom is idx 0 */
5583 reg_idx = 1;
5584 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5585 regdom = get_wiphy_regdom(&rdev->wiphy);
5586 if (!regdom)
5587 continue;
5588
5589 if (++reg_idx <= start)
5590 continue;
5591
5592 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5593 NLM_F_MULTI, &rdev->wiphy, regdom);
5594 if (err < 0) {
5595 reg_idx--;
5596 break;
5597 }
5598 }
5599
5600 cb->args[2] = reg_idx;
5601 err = skb->len;
5602out_err:
5603 rtnl_unlock();
5604 return err;
5605}
5606
Johannes Bergb6863032015-10-15 09:25:18 +02005607#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5608static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5609 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5610 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5611 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5612 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5613 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5614 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5615 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5616};
5617
5618static int parse_reg_rule(struct nlattr *tb[],
5619 struct ieee80211_reg_rule *reg_rule)
5620{
5621 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5622 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5623
5624 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5625 return -EINVAL;
5626 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5627 return -EINVAL;
5628 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5629 return -EINVAL;
5630 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5631 return -EINVAL;
5632 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5633 return -EINVAL;
5634
5635 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5636
5637 freq_range->start_freq_khz =
5638 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5639 freq_range->end_freq_khz =
5640 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5641 freq_range->max_bandwidth_khz =
5642 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5643
5644 power_rule->max_eirp =
5645 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5646
5647 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5648 power_rule->max_antenna_gain =
5649 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5650
5651 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5652 reg_rule->dfs_cac_ms =
5653 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5654
5655 return 0;
5656}
5657
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005658static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5659{
5660 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5661 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005662 char *alpha2;
5663 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005664 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005665 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005666 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005667
5668 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5669 return -EINVAL;
5670
5671 if (!info->attrs[NL80211_ATTR_REG_RULES])
5672 return -EINVAL;
5673
5674 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5675
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005676 if (info->attrs[NL80211_ATTR_DFS_REGION])
5677 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5678
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005679 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005680 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005681 num_rules++;
5682 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005683 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005684 }
5685
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005686 if (!reg_is_valid_request(alpha2))
5687 return -EINVAL;
5688
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005689 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005690 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005691
5692 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005693 if (!rd)
5694 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005695
5696 rd->n_reg_rules = num_rules;
5697 rd->alpha2[0] = alpha2[0];
5698 rd->alpha2[1] = alpha2[1];
5699
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005700 /*
5701 * Disable DFS master mode if the DFS region was
5702 * not supported or known on this kernel.
5703 */
5704 if (reg_supported_dfs_region(dfs_region))
5705 rd->dfs_region = dfs_region;
5706
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005707 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005708 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005709 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5710 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5711 reg_rule_policy);
5712 if (r)
5713 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005714 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5715 if (r)
5716 goto bad_reg;
5717
5718 rule_idx++;
5719
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005720 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5721 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005722 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005723 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005724 }
5725
Ilan peerc37722b2015-03-30 15:15:49 +03005726 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005727 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005728 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005729
Johannes Bergd2372b32008-10-24 20:32:20 +02005730 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005731 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005732 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005733}
Johannes Bergb6863032015-10-15 09:25:18 +02005734#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005735
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005736static int validate_scan_freqs(struct nlattr *freqs)
5737{
5738 struct nlattr *attr1, *attr2;
5739 int n_channels = 0, tmp1, tmp2;
5740
5741 nla_for_each_nested(attr1, freqs, tmp1) {
5742 n_channels++;
5743 /*
5744 * Some hardware has a limited channel list for
5745 * scanning, and it is pretty much nonsensical
5746 * to scan for a channel twice, so disallow that
5747 * and don't require drivers to check that the
5748 * channel list they get isn't longer than what
5749 * they can scan, as long as they can scan all
5750 * the channels they registered at once.
5751 */
5752 nla_for_each_nested(attr2, freqs, tmp2)
5753 if (attr1 != attr2 &&
5754 nla_get_u32(attr1) == nla_get_u32(attr2))
5755 return 0;
5756 }
5757
5758 return n_channels;
5759}
5760
Johannes Bergad2b26a2014-06-12 21:39:05 +02005761static int nl80211_parse_random_mac(struct nlattr **attrs,
5762 u8 *mac_addr, u8 *mac_addr_mask)
5763{
5764 int i;
5765
5766 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005767 eth_zero_addr(mac_addr);
5768 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005769 mac_addr[0] = 0x2;
5770 mac_addr_mask[0] = 0x3;
5771
5772 return 0;
5773 }
5774
5775 /* need both or none */
5776 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5777 return -EINVAL;
5778
5779 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5780 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5781
5782 /* don't allow or configure an mcast address */
5783 if (!is_multicast_ether_addr(mac_addr_mask) ||
5784 is_multicast_ether_addr(mac_addr))
5785 return -EINVAL;
5786
5787 /*
5788 * allow users to pass a MAC address that has bits set outside
5789 * of the mask, but don't bother drivers with having to deal
5790 * with such bits
5791 */
5792 for (i = 0; i < ETH_ALEN; i++)
5793 mac_addr[i] &= mac_addr_mask[i];
5794
5795 return 0;
5796}
5797
Johannes Berg2a519312009-02-10 21:25:55 +01005798static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5799{
Johannes Berg4c476992010-10-04 21:36:35 +02005800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005801 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005802 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005803 struct nlattr *attr;
5804 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005805 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005806 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005807
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005808 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5809 return -EINVAL;
5810
Johannes Berg79c97e92009-07-07 03:56:12 +02005811 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005812
Johannes Berg4c476992010-10-04 21:36:35 +02005813 if (!rdev->ops->scan)
5814 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005815
Johannes Bergf9d15d12014-01-22 11:14:19 +02005816 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005817 err = -EBUSY;
5818 goto unlock;
5819 }
Johannes Berg2a519312009-02-10 21:25:55 +01005820
5821 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005822 n_channels = validate_scan_freqs(
5823 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005824 if (!n_channels) {
5825 err = -EINVAL;
5826 goto unlock;
5827 }
Johannes Berg2a519312009-02-10 21:25:55 +01005828 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005829 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005830 }
5831
5832 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5833 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5834 n_ssids++;
5835
Johannes Bergf9f47522013-03-19 15:04:07 +01005836 if (n_ssids > wiphy->max_scan_ssids) {
5837 err = -EINVAL;
5838 goto unlock;
5839 }
Johannes Berg2a519312009-02-10 21:25:55 +01005840
Jouni Malinen70692ad2009-02-16 19:39:13 +02005841 if (info->attrs[NL80211_ATTR_IE])
5842 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5843 else
5844 ie_len = 0;
5845
Johannes Bergf9f47522013-03-19 15:04:07 +01005846 if (ie_len > wiphy->max_scan_ie_len) {
5847 err = -EINVAL;
5848 goto unlock;
5849 }
Johannes Berg18a83652009-03-31 12:12:05 +02005850
Johannes Berg2a519312009-02-10 21:25:55 +01005851 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005852 + sizeof(*request->ssids) * n_ssids
5853 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005854 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005855 if (!request) {
5856 err = -ENOMEM;
5857 goto unlock;
5858 }
Johannes Berg2a519312009-02-10 21:25:55 +01005859
Johannes Berg2a519312009-02-10 21:25:55 +01005860 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005861 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005862 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005863 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005864 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005865 request->ie = (void *)(request->ssids + n_ssids);
5866 else
5867 request->ie = (void *)(request->channels + n_channels);
5868 }
Johannes Berg2a519312009-02-10 21:25:55 +01005869
Johannes Berg584991d2009-11-02 13:32:03 +01005870 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005871 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5872 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005873 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005874 struct ieee80211_channel *chan;
5875
5876 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5877
5878 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005879 err = -EINVAL;
5880 goto out_free;
5881 }
Johannes Berg584991d2009-11-02 13:32:03 +01005882
5883 /* ignore disabled channels */
5884 if (chan->flags & IEEE80211_CHAN_DISABLED)
5885 continue;
5886
5887 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005888 i++;
5889 }
5890 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005891 enum ieee80211_band band;
5892
Johannes Berg2a519312009-02-10 21:25:55 +01005893 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005894 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5895 int j;
5896 if (!wiphy->bands[band])
5897 continue;
5898 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005899 struct ieee80211_channel *chan;
5900
5901 chan = &wiphy->bands[band]->channels[j];
5902
5903 if (chan->flags & IEEE80211_CHAN_DISABLED)
5904 continue;
5905
5906 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005907 i++;
5908 }
5909 }
5910 }
5911
Johannes Berg584991d2009-11-02 13:32:03 +01005912 if (!i) {
5913 err = -EINVAL;
5914 goto out_free;
5915 }
5916
5917 request->n_channels = i;
5918
Johannes Berg2a519312009-02-10 21:25:55 +01005919 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005920 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005921 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005922 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005923 err = -EINVAL;
5924 goto out_free;
5925 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005926 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005927 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005928 i++;
5929 }
5930 }
5931
Jouni Malinen70692ad2009-02-16 19:39:13 +02005932 if (info->attrs[NL80211_ATTR_IE]) {
5933 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005934 memcpy((void *)request->ie,
5935 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005936 request->ie_len);
5937 }
5938
Johannes Berg34850ab2011-07-18 18:08:35 +02005939 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005940 if (wiphy->bands[i])
5941 request->rates[i] =
5942 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005943
5944 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5945 nla_for_each_nested(attr,
5946 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5947 tmp) {
5948 enum ieee80211_band band = nla_type(attr);
5949
Dan Carpenter84404622011-07-29 11:52:18 +03005950 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005951 err = -EINVAL;
5952 goto out_free;
5953 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005954
5955 if (!wiphy->bands[band])
5956 continue;
5957
Johannes Berg34850ab2011-07-18 18:08:35 +02005958 err = ieee80211_get_ratemask(wiphy->bands[band],
5959 nla_data(attr),
5960 nla_len(attr),
5961 &request->rates[band]);
5962 if (err)
5963 goto out_free;
5964 }
5965 }
5966
Sam Leffler46856bb2012-10-11 21:03:32 -07005967 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005968 request->flags = nla_get_u32(
5969 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005970 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5971 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005972 err = -EOPNOTSUPP;
5973 goto out_free;
5974 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005975
5976 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5977 if (!(wiphy->features &
5978 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5979 err = -EOPNOTSUPP;
5980 goto out_free;
5981 }
5982
5983 if (wdev->current_bss) {
5984 err = -EOPNOTSUPP;
5985 goto out_free;
5986 }
5987
5988 err = nl80211_parse_random_mac(info->attrs,
5989 request->mac_addr,
5990 request->mac_addr_mask);
5991 if (err)
5992 goto out_free;
5993 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005994 }
Sam Lefflered4737712012-10-11 21:03:31 -07005995
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305996 request->no_cck =
5997 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5998
Johannes Bergfd014282012-06-18 19:17:03 +02005999 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02006000 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07006001 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01006002
Johannes Berg79c97e92009-07-07 03:56:12 +02006003 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03006004 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01006005
Johannes Berg463d0182009-07-14 00:33:35 +02006006 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02006007 nl80211_send_scan_start(rdev, wdev);
6008 if (wdev->netdev)
6009 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02006010 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01006011 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02006012 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01006013 kfree(request);
6014 }
Johannes Berg3b858752009-03-12 09:55:09 +01006015
Johannes Bergf9f47522013-03-19 15:04:07 +01006016 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01006017 return err;
6018}
6019
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +05306020static int nl80211_abort_scan(struct sk_buff *skb, struct genl_info *info)
6021{
6022 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6023 struct wireless_dev *wdev = info->user_ptr[1];
6024
6025 if (!rdev->ops->abort_scan)
6026 return -EOPNOTSUPP;
6027
6028 if (rdev->scan_msg)
6029 return 0;
6030
6031 if (!rdev->scan_req)
6032 return -ENOENT;
6033
6034 rdev_abort_scan(rdev, wdev);
6035 return 0;
6036}
6037
Avraham Stern3b06d272015-10-12 09:51:34 +03006038static int
6039nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6040 struct cfg80211_sched_scan_request *request,
6041 struct nlattr **attrs)
6042{
6043 int tmp, err, i = 0;
6044 struct nlattr *attr;
6045
6046 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6047 u32 interval;
6048
6049 /*
6050 * If scan plans are not specified,
6051 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6052 * case one scan plan will be set with the specified scan
6053 * interval and infinite number of iterations.
6054 */
6055 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6056 return -EINVAL;
6057
6058 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6059 if (!interval)
6060 return -EINVAL;
6061
6062 request->scan_plans[0].interval =
6063 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6064 if (!request->scan_plans[0].interval)
6065 return -EINVAL;
6066
6067 if (request->scan_plans[0].interval >
6068 wiphy->max_sched_scan_plan_interval)
6069 request->scan_plans[0].interval =
6070 wiphy->max_sched_scan_plan_interval;
6071
6072 return 0;
6073 }
6074
6075 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6076 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6077
6078 if (WARN_ON(i >= n_plans))
6079 return -EINVAL;
6080
6081 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6082 nla_data(attr), nla_len(attr),
6083 nl80211_plan_policy);
6084 if (err)
6085 return err;
6086
6087 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6088 return -EINVAL;
6089
6090 request->scan_plans[i].interval =
6091 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6092 if (!request->scan_plans[i].interval ||
6093 request->scan_plans[i].interval >
6094 wiphy->max_sched_scan_plan_interval)
6095 return -EINVAL;
6096
6097 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6098 request->scan_plans[i].iterations =
6099 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6100 if (!request->scan_plans[i].iterations ||
6101 (request->scan_plans[i].iterations >
6102 wiphy->max_sched_scan_plan_iterations))
6103 return -EINVAL;
6104 } else if (i < n_plans - 1) {
6105 /*
6106 * All scan plans but the last one must specify
6107 * a finite number of iterations
6108 */
6109 return -EINVAL;
6110 }
6111
6112 i++;
6113 }
6114
6115 /*
6116 * The last scan plan must not specify the number of
6117 * iterations, it is supposed to run infinitely
6118 */
6119 if (request->scan_plans[n_plans - 1].iterations)
6120 return -EINVAL;
6121
6122 return 0;
6123}
6124
Luciano Coelho256da022014-11-10 16:13:46 +02006125static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006126nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006127 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006128{
6129 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006130 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006131 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006132 enum ieee80211_band band;
6133 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006134 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006135 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006136
Luciano Coelho256da022014-11-10 16:13:46 +02006137 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6138 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006139
Luciano Coelho256da022014-11-10 16:13:46 +02006140 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006141 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006142 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006143 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006144 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006145 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006146 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006147 }
6148
Luciano Coelho256da022014-11-10 16:13:46 +02006149 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6150 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006151 tmp)
6152 n_ssids++;
6153
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006154 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006155 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006156
Johannes Bergea73cbc2014-01-24 10:53:53 +01006157 /*
6158 * First, count the number of 'real' matchsets. Due to an issue with
6159 * the old implementation, matchsets containing only the RSSI attribute
6160 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6161 * RSSI for all matchsets, rather than their own matchset for reporting
6162 * all APs with a strong RSSI. This is needed to be compatible with
6163 * older userspace that treated a matchset with only the RSSI as the
6164 * global RSSI for all other matchsets - if there are other matchsets.
6165 */
Luciano Coelho256da022014-11-10 16:13:46 +02006166 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006167 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006168 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006169 tmp) {
6170 struct nlattr *rssi;
6171
6172 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6173 nla_data(attr), nla_len(attr),
6174 nl80211_match_policy);
6175 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006176 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006177 /* add other standalone attributes here */
6178 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6179 n_match_sets++;
6180 continue;
6181 }
6182 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6183 if (rssi)
6184 default_match_rssi = nla_get_s32(rssi);
6185 }
6186 }
6187
6188 /* However, if there's no other matchset, add the RSSI one */
6189 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6190 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006191
6192 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006193 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006194
Luciano Coelho256da022014-11-10 16:13:46 +02006195 if (attrs[NL80211_ATTR_IE])
6196 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006197 else
6198 ie_len = 0;
6199
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006200 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006201 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006202
Avraham Stern3b06d272015-10-12 09:51:34 +03006203 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6204 /*
6205 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6206 * each scan plan already specifies its own interval
6207 */
6208 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6209 return ERR_PTR(-EINVAL);
6210
6211 nla_for_each_nested(attr,
6212 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6213 n_plans++;
6214 } else {
6215 /*
6216 * The scan interval attribute is kept for backward
6217 * compatibility. If no scan plans are specified and sched scan
6218 * interval is specified, one scan plan will be set with this
6219 * scan interval and infinite number of iterations.
6220 */
6221 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6222 return ERR_PTR(-EINVAL);
6223
6224 n_plans = 1;
6225 }
6226
6227 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6228 return ERR_PTR(-EINVAL);
6229
Luciano Coelho807f8a82011-05-11 17:09:35 +03006230 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006231 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006232 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006233 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006234 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006235 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006236 if (!request)
6237 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006238
6239 if (n_ssids)
6240 request->ssids = (void *)&request->channels[n_channels];
6241 request->n_ssids = n_ssids;
6242 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006243 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006244 request->ie = (void *)(request->ssids + n_ssids);
6245 else
6246 request->ie = (void *)(request->channels + n_channels);
6247 }
6248
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006249 if (n_match_sets) {
6250 if (request->ie)
6251 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006252 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006253 request->match_sets =
6254 (void *)(request->ssids + n_ssids);
6255 else
6256 request->match_sets =
6257 (void *)(request->channels + n_channels);
6258 }
6259 request->n_match_sets = n_match_sets;
6260
Avraham Stern3b06d272015-10-12 09:51:34 +03006261 if (n_match_sets)
6262 request->scan_plans = (void *)(request->match_sets +
6263 n_match_sets);
6264 else if (request->ie)
6265 request->scan_plans = (void *)(request->ie + ie_len);
6266 else if (n_ssids)
6267 request->scan_plans = (void *)(request->ssids + n_ssids);
6268 else
6269 request->scan_plans = (void *)(request->channels + n_channels);
6270
6271 request->n_scan_plans = n_plans;
6272
Luciano Coelho807f8a82011-05-11 17:09:35 +03006273 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006274 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006275 /* user specified, bail out if channel not found */
6276 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006277 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006278 tmp) {
6279 struct ieee80211_channel *chan;
6280
6281 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6282
6283 if (!chan) {
6284 err = -EINVAL;
6285 goto out_free;
6286 }
6287
6288 /* ignore disabled channels */
6289 if (chan->flags & IEEE80211_CHAN_DISABLED)
6290 continue;
6291
6292 request->channels[i] = chan;
6293 i++;
6294 }
6295 } else {
6296 /* all channels */
6297 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6298 int j;
6299 if (!wiphy->bands[band])
6300 continue;
6301 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6302 struct ieee80211_channel *chan;
6303
6304 chan = &wiphy->bands[band]->channels[j];
6305
6306 if (chan->flags & IEEE80211_CHAN_DISABLED)
6307 continue;
6308
6309 request->channels[i] = chan;
6310 i++;
6311 }
6312 }
6313 }
6314
6315 if (!i) {
6316 err = -EINVAL;
6317 goto out_free;
6318 }
6319
6320 request->n_channels = i;
6321
6322 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006323 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006324 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006325 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006326 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006327 err = -EINVAL;
6328 goto out_free;
6329 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006330 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006331 memcpy(request->ssids[i].ssid, nla_data(attr),
6332 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006333 i++;
6334 }
6335 }
6336
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006337 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006338 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006339 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006340 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006341 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006342 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006343
Johannes Bergae811e22014-01-24 10:17:47 +01006344 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6345 nla_data(attr), nla_len(attr),
6346 nl80211_match_policy);
6347 if (err)
6348 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006349 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006350 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006351 if (WARN_ON(i >= n_match_sets)) {
6352 /* this indicates a programming error,
6353 * the loop above should have verified
6354 * things properly
6355 */
6356 err = -EINVAL;
6357 goto out_free;
6358 }
6359
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006360 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6361 err = -EINVAL;
6362 goto out_free;
6363 }
6364 memcpy(request->match_sets[i].ssid.ssid,
6365 nla_data(ssid), nla_len(ssid));
6366 request->match_sets[i].ssid.ssid_len =
6367 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006368 /* special attribute - old implemenation w/a */
6369 request->match_sets[i].rssi_thold =
6370 default_match_rssi;
6371 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6372 if (rssi)
6373 request->match_sets[i].rssi_thold =
6374 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006375 }
6376 i++;
6377 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006378
6379 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006380 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006381 request->match_sets[0].rssi_thold = default_match_rssi;
6382
6383 request->min_rssi_thold = INT_MAX;
6384 for (i = 0; i < n_match_sets; i++)
6385 request->min_rssi_thold =
6386 min(request->match_sets[i].rssi_thold,
6387 request->min_rssi_thold);
6388 } else {
6389 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006390 }
6391
Johannes Berg9900e482014-02-04 21:01:25 +01006392 if (ie_len) {
6393 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006394 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006395 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006396 request->ie_len);
6397 }
6398
Luciano Coelho256da022014-11-10 16:13:46 +02006399 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006400 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006401 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006402 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6403 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006404 err = -EOPNOTSUPP;
6405 goto out_free;
6406 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006407
6408 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6409 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6410
6411 if (!wdev) /* must be net-detect */
6412 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6413
6414 if (!(wiphy->features & flg)) {
6415 err = -EOPNOTSUPP;
6416 goto out_free;
6417 }
6418
6419 if (wdev && wdev->current_bss) {
6420 err = -EOPNOTSUPP;
6421 goto out_free;
6422 }
6423
6424 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6425 request->mac_addr_mask);
6426 if (err)
6427 goto out_free;
6428 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006429 }
Sam Lefflered4737712012-10-11 21:03:31 -07006430
Luciano Coelho9c748932015-01-16 16:04:09 +02006431 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6432 request->delay =
6433 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6434
Avraham Stern3b06d272015-10-12 09:51:34 +03006435 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6436 if (err)
6437 goto out_free;
6438
Sam Leffler15d60302012-10-11 21:03:34 -07006439 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006440
Luciano Coelho256da022014-11-10 16:13:46 +02006441 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006442
6443out_free:
6444 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006445 return ERR_PTR(err);
6446}
6447
6448static int nl80211_start_sched_scan(struct sk_buff *skb,
6449 struct genl_info *info)
6450{
6451 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6452 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006453 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006454 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006455 int err;
6456
6457 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6458 !rdev->ops->sched_scan_start)
6459 return -EOPNOTSUPP;
6460
6461 if (rdev->sched_scan_req)
6462 return -EINPROGRESS;
6463
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006464 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6465 info->attrs);
6466
6467 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006468 if (err)
6469 goto out_err;
6470
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006471 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006472 if (err)
6473 goto out_free;
6474
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006475 sched_scan_req->dev = dev;
6476 sched_scan_req->wiphy = &rdev->wiphy;
6477
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006478 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6479 sched_scan_req->owner_nlportid = info->snd_portid;
6480
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006481 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006482
6483 nl80211_send_sched_scan(rdev, dev,
6484 NL80211_CMD_START_SCHED_SCAN);
6485 return 0;
6486
6487out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006488 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006489out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006490 return err;
6491}
6492
6493static int nl80211_stop_sched_scan(struct sk_buff *skb,
6494 struct genl_info *info)
6495{
6496 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6497
6498 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6499 !rdev->ops->sched_scan_stop)
6500 return -EOPNOTSUPP;
6501
Johannes Berg5fe231e2013-05-08 21:45:15 +02006502 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006503}
6504
Simon Wunderlich04f39042013-02-08 18:16:19 +01006505static int nl80211_start_radar_detection(struct sk_buff *skb,
6506 struct genl_info *info)
6507{
6508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6509 struct net_device *dev = info->user_ptr[1];
6510 struct wireless_dev *wdev = dev->ieee80211_ptr;
6511 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006512 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006513 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006514 int err;
6515
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006516 dfs_region = reg_get_dfs_region(wdev->wiphy);
6517 if (dfs_region == NL80211_DFS_UNSET)
6518 return -EINVAL;
6519
Simon Wunderlich04f39042013-02-08 18:16:19 +01006520 err = nl80211_parse_chandef(rdev, info, &chandef);
6521 if (err)
6522 return err;
6523
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006524 if (netif_carrier_ok(dev))
6525 return -EBUSY;
6526
Simon Wunderlich04f39042013-02-08 18:16:19 +01006527 if (wdev->cac_started)
6528 return -EBUSY;
6529
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006530 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006531 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006532 if (err < 0)
6533 return err;
6534
6535 if (err == 0)
6536 return -EINVAL;
6537
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006538 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006539 return -EINVAL;
6540
6541 if (!rdev->ops->start_radar_detection)
6542 return -EOPNOTSUPP;
6543
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006544 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6545 if (WARN_ON(!cac_time_ms))
6546 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6547
Ilan Peera1056b12015-10-22 22:27:46 +03006548 err = rdev_start_radar_detection(rdev, dev, &chandef, cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006549 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006550 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006551 wdev->cac_started = true;
6552 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006553 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006554 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006555 return err;
6556}
6557
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006558static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6559{
6560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6561 struct net_device *dev = info->user_ptr[1];
6562 struct wireless_dev *wdev = dev->ieee80211_ptr;
6563 struct cfg80211_csa_settings params;
6564 /* csa_attrs is defined static to avoid waste of stack size - this
6565 * function is called under RTNL lock, so this should not be a problem.
6566 */
6567 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006568 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006569 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006570 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006571 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006572
6573 if (!rdev->ops->channel_switch ||
6574 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6575 return -EOPNOTSUPP;
6576
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006577 switch (dev->ieee80211_ptr->iftype) {
6578 case NL80211_IFTYPE_AP:
6579 case NL80211_IFTYPE_P2P_GO:
6580 need_new_beacon = true;
6581
6582 /* useless if AP is not running */
6583 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006584 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006585 break;
6586 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006587 if (!wdev->ssid_len)
6588 return -ENOTCONN;
6589 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006590 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006591 if (!wdev->mesh_id_len)
6592 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006593 break;
6594 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006595 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006596 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006597
6598 memset(&params, 0, sizeof(params));
6599
6600 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6601 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6602 return -EINVAL;
6603
6604 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006605 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006606 return -EINVAL;
6607
Luciano Coelho252e07c2014-10-08 09:48:34 +03006608 /* Even though the attribute is u32, the specification says
6609 * u8, so let's make sure we don't overflow.
6610 */
6611 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6612 if (cs_count > 255)
6613 return -EINVAL;
6614
6615 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006616
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006617 if (!need_new_beacon)
6618 goto skip_beacons;
6619
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006620 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6621 if (err)
6622 return err;
6623
6624 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6625 info->attrs[NL80211_ATTR_CSA_IES],
6626 nl80211_policy);
6627 if (err)
6628 return err;
6629
6630 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6631 if (err)
6632 return err;
6633
6634 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6635 return -EINVAL;
6636
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006637 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6638 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006639 return -EINVAL;
6640
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006641 params.n_counter_offsets_beacon = len / sizeof(u16);
6642 if (rdev->wiphy.max_num_csa_counters &&
6643 (params.n_counter_offsets_beacon >
6644 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006645 return -EINVAL;
6646
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006647 params.counter_offsets_beacon =
6648 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6649
6650 /* sanity checks - counters should fit and be the same */
6651 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6652 u16 offset = params.counter_offsets_beacon[i];
6653
6654 if (offset >= params.beacon_csa.tail_len)
6655 return -EINVAL;
6656
6657 if (params.beacon_csa.tail[offset] != params.count)
6658 return -EINVAL;
6659 }
6660
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006661 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006662 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6663 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006664 return -EINVAL;
6665
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006666 params.n_counter_offsets_presp = len / sizeof(u16);
6667 if (rdev->wiphy.max_num_csa_counters &&
6668 (params.n_counter_offsets_beacon >
6669 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006670 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006671
6672 params.counter_offsets_presp =
6673 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6674
6675 /* sanity checks - counters should fit and be the same */
6676 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6677 u16 offset = params.counter_offsets_presp[i];
6678
6679 if (offset >= params.beacon_csa.probe_resp_len)
6680 return -EINVAL;
6681
6682 if (params.beacon_csa.probe_resp[offset] !=
6683 params.count)
6684 return -EINVAL;
6685 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006686 }
6687
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006688skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006689 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6690 if (err)
6691 return err;
6692
Arik Nemtsov923b3522015-07-08 15:41:44 +03006693 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6694 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006695 return -EINVAL;
6696
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006697 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6698 &params.chandef,
6699 wdev->iftype);
6700 if (err < 0)
6701 return err;
6702
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006703 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006704 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006705
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006706 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6707 params.block_tx = true;
6708
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006709 wdev_lock(wdev);
6710 err = rdev_channel_switch(rdev, dev, &params);
6711 wdev_unlock(wdev);
6712
6713 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006714}
6715
Johannes Berg9720bb32011-06-21 09:45:33 +02006716static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6717 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006718 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006719 struct wireless_dev *wdev,
6720 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006721{
Johannes Berg48ab9052009-07-10 18:42:31 +02006722 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006723 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006724 void *hdr;
6725 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006726
6727 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006728
Eric W. Biederman15e47302012-09-07 20:12:54 +00006729 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006730 NL80211_CMD_NEW_SCAN_RESULTS);
6731 if (!hdr)
6732 return -1;
6733
Johannes Berg9720bb32011-06-21 09:45:33 +02006734 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6735
Johannes Berg97990a02013-04-19 01:02:55 +02006736 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6737 goto nla_put_failure;
6738 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006739 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6740 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006741 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6742 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006743
6744 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6745 if (!bss)
6746 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006747 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006748 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006749 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006750
6751 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006752 /* indicate whether we have probe response data or not */
6753 if (rcu_access_pointer(res->proberesp_ies) &&
6754 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6755 goto fail_unlock_rcu;
6756
6757 /* this pointer prefers to be pointed to probe response data
6758 * but is always valid
6759 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006760 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006761 if (ies) {
6762 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6763 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006764 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6765 ies->len, ies->data))
6766 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006767 }
Johannes Berg0e227082014-08-12 20:34:30 +02006768
6769 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006770 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006771 if (ies && ies->from_beacon) {
6772 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006773 goto fail_unlock_rcu;
6774 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6775 ies->len, ies->data))
6776 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006777 }
6778 rcu_read_unlock();
6779
David S. Miller9360ffd2012-03-29 04:41:26 -04006780 if (res->beacon_interval &&
6781 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6782 goto nla_put_failure;
6783 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6784 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006785 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006786 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6787 jiffies_to_msecs(jiffies - intbss->ts)))
6788 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006789
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006790 if (intbss->ts_boottime &&
6791 nla_put_u64(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6792 intbss->ts_boottime))
6793 goto nla_put_failure;
6794
Johannes Berg77965c92009-02-18 18:45:06 +01006795 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006796 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006797 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6798 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006799 break;
6800 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006801 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6802 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006803 break;
6804 default:
6805 break;
6806 }
6807
Johannes Berg48ab9052009-07-10 18:42:31 +02006808 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006809 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006810 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006811 if (intbss == wdev->current_bss &&
6812 nla_put_u32(msg, NL80211_BSS_STATUS,
6813 NL80211_BSS_STATUS_ASSOCIATED))
6814 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006815 break;
6816 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006817 if (intbss == wdev->current_bss &&
6818 nla_put_u32(msg, NL80211_BSS_STATUS,
6819 NL80211_BSS_STATUS_IBSS_JOINED))
6820 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006821 break;
6822 default:
6823 break;
6824 }
6825
Johannes Berg2a519312009-02-10 21:25:55 +01006826 nla_nest_end(msg, bss);
6827
Johannes Berg053c0952015-01-16 22:09:00 +01006828 genlmsg_end(msg, hdr);
6829 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006830
Johannes Berg8cef2c92013-02-05 16:54:31 +01006831 fail_unlock_rcu:
6832 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006833 nla_put_failure:
6834 genlmsg_cancel(msg, hdr);
6835 return -EMSGSIZE;
6836}
6837
Johannes Berg97990a02013-04-19 01:02:55 +02006838static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006839{
Johannes Berg48ab9052009-07-10 18:42:31 +02006840 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006841 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006842 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006843 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006844 int err;
6845
Johannes Berg97990a02013-04-19 01:02:55 +02006846 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006847 if (err)
6848 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006849
Johannes Berg48ab9052009-07-10 18:42:31 +02006850 wdev_lock(wdev);
6851 spin_lock_bh(&rdev->bss_lock);
6852 cfg80211_bss_expire(rdev);
6853
Johannes Berg9720bb32011-06-21 09:45:33 +02006854 cb->seq = rdev->bss_generation;
6855
Johannes Berg48ab9052009-07-10 18:42:31 +02006856 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006857 if (++idx <= start)
6858 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006859 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006860 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006861 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006862 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006863 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006864 }
6865 }
6866
Johannes Berg48ab9052009-07-10 18:42:31 +02006867 spin_unlock_bh(&rdev->bss_lock);
6868 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006869
Johannes Berg97990a02013-04-19 01:02:55 +02006870 cb->args[2] = idx;
6871 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006872
Johannes Berg67748892010-10-04 21:14:06 +02006873 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006874}
6875
Eric W. Biederman15e47302012-09-07 20:12:54 +00006876static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006877 int flags, struct net_device *dev,
6878 bool allow_radio_stats,
6879 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006880{
6881 void *hdr;
6882 struct nlattr *infoattr;
6883
Johannes Berg11f78ac2014-11-14 16:43:50 +01006884 /* skip radio stats if userspace didn't request them */
6885 if (!survey->channel && !allow_radio_stats)
6886 return 0;
6887
Eric W. Biederman15e47302012-09-07 20:12:54 +00006888 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006889 NL80211_CMD_NEW_SURVEY_RESULTS);
6890 if (!hdr)
6891 return -ENOMEM;
6892
David S. Miller9360ffd2012-03-29 04:41:26 -04006893 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6894 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006895
6896 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6897 if (!infoattr)
6898 goto nla_put_failure;
6899
Johannes Berg11f78ac2014-11-14 16:43:50 +01006900 if (survey->channel &&
6901 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006902 survey->channel->center_freq))
6903 goto nla_put_failure;
6904
6905 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6906 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6907 goto nla_put_failure;
6908 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6909 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6910 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006911 if ((survey->filled & SURVEY_INFO_TIME) &&
6912 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6913 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006914 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006915 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6916 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6917 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006918 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006919 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6920 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6921 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006922 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006923 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6924 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6925 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006926 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006927 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6928 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6929 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006930 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006931 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6932 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6933 survey->time_scan))
6934 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006935
6936 nla_nest_end(msg, infoattr);
6937
Johannes Berg053c0952015-01-16 22:09:00 +01006938 genlmsg_end(msg, hdr);
6939 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006940
6941 nla_put_failure:
6942 genlmsg_cancel(msg, hdr);
6943 return -EMSGSIZE;
6944}
6945
Johannes Berg11f78ac2014-11-14 16:43:50 +01006946static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006947{
6948 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006949 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006950 struct wireless_dev *wdev;
6951 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006952 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006953 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006954
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006955 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006956 if (res)
6957 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006958
Johannes Berg11f78ac2014-11-14 16:43:50 +01006959 /* prepare_wdev_dump parsed the attributes */
6960 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6961
Johannes Berg97990a02013-04-19 01:02:55 +02006962 if (!wdev->netdev) {
6963 res = -EINVAL;
6964 goto out_err;
6965 }
6966
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006967 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006968 res = -EOPNOTSUPP;
6969 goto out_err;
6970 }
6971
6972 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006973 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006974 if (res == -ENOENT)
6975 break;
6976 if (res)
6977 goto out_err;
6978
Johannes Berg11f78ac2014-11-14 16:43:50 +01006979 /* don't send disabled channels, but do send non-channel data */
6980 if (survey.channel &&
6981 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006982 survey_idx++;
6983 continue;
6984 }
6985
Holger Schurig61fa7132009-11-11 12:25:40 +01006986 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006987 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006988 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006989 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006990 goto out;
6991 survey_idx++;
6992 }
6993
6994 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006995 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006996 res = skb->len;
6997 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006998 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006999 return res;
7000}
7001
Samuel Ortizb23aa672009-07-01 21:26:54 +02007002static bool nl80211_valid_wpa_versions(u32 wpa_versions)
7003{
7004 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
7005 NL80211_WPA_VERSION_2));
7006}
7007
Jouni Malinen636a5d32009-03-19 13:39:22 +02007008static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
7009{
Johannes Berg4c476992010-10-04 21:36:35 +02007010 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7011 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007012 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03007013 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
7014 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02007015 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02007016 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007017 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007018
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007019 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7020 return -EINVAL;
7021
7022 if (!info->attrs[NL80211_ATTR_MAC])
7023 return -EINVAL;
7024
Jouni Malinen17780922009-03-27 20:52:47 +02007025 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
7026 return -EINVAL;
7027
Johannes Berg19957bb2009-07-02 17:20:43 +02007028 if (!info->attrs[NL80211_ATTR_SSID])
7029 return -EINVAL;
7030
7031 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
7032 return -EINVAL;
7033
Johannes Bergfffd0932009-07-08 14:22:54 +02007034 err = nl80211_parse_key(info, &key);
7035 if (err)
7036 return err;
7037
7038 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007039 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7040 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007041 if (!key.p.key || !key.p.key_len)
7042 return -EINVAL;
7043 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7044 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7045 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7046 key.p.key_len != WLAN_KEY_LEN_WEP104))
7047 return -EINVAL;
7048 if (key.idx > 4)
7049 return -EINVAL;
7050 } else {
7051 key.p.key_len = 0;
7052 key.p.key = NULL;
7053 }
7054
Johannes Bergafea0b72010-08-10 09:46:42 +02007055 if (key.idx >= 0) {
7056 int i;
7057 bool ok = false;
7058 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7059 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7060 ok = true;
7061 break;
7062 }
7063 }
Johannes Berg4c476992010-10-04 21:36:35 +02007064 if (!ok)
7065 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007066 }
7067
Johannes Berg4c476992010-10-04 21:36:35 +02007068 if (!rdev->ops->auth)
7069 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007070
Johannes Berg074ac8d2010-09-16 14:58:22 +02007071 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007072 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7073 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007074
Johannes Berg19957bb2009-07-02 17:20:43 +02007075 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007076 chan = nl80211_get_valid_chan(&rdev->wiphy,
7077 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7078 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007079 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007080
Johannes Berg19957bb2009-07-02 17:20:43 +02007081 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7082 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7083
7084 if (info->attrs[NL80211_ATTR_IE]) {
7085 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7086 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7087 }
7088
7089 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007090 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007091 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007092
Jouni Malinene39e5b52012-09-30 19:29:39 +03007093 if (auth_type == NL80211_AUTHTYPE_SAE &&
7094 !info->attrs[NL80211_ATTR_SAE_DATA])
7095 return -EINVAL;
7096
7097 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7098 if (auth_type != NL80211_AUTHTYPE_SAE)
7099 return -EINVAL;
7100 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7101 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7102 /* need to include at least Auth Transaction and Status Code */
7103 if (sae_data_len < 4)
7104 return -EINVAL;
7105 }
7106
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007107 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7108
Johannes Berg95de8172012-01-20 13:55:25 +01007109 /*
7110 * Since we no longer track auth state, ignore
7111 * requests to only change local state.
7112 */
7113 if (local_state_change)
7114 return 0;
7115
Johannes Berg91bf9b22013-05-15 17:44:01 +02007116 wdev_lock(dev->ieee80211_ptr);
7117 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7118 ssid, ssid_len, ie, ie_len,
7119 key.p.key, key.p.key_len, key.idx,
7120 sae_data, sae_data_len);
7121 wdev_unlock(dev->ieee80211_ptr);
7122 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007123}
7124
Johannes Bergc0692b82010-08-27 14:26:53 +03007125static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7126 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007127 struct cfg80211_crypto_settings *settings,
7128 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007129{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007130 memset(settings, 0, sizeof(*settings));
7131
Samuel Ortizb23aa672009-07-01 21:26:54 +02007132 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7133
Johannes Bergc0692b82010-08-27 14:26:53 +03007134 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7135 u16 proto;
7136 proto = nla_get_u16(
7137 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7138 settings->control_port_ethertype = cpu_to_be16(proto);
7139 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7140 proto != ETH_P_PAE)
7141 return -EINVAL;
7142 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7143 settings->control_port_no_encrypt = true;
7144 } else
7145 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7146
Samuel Ortizb23aa672009-07-01 21:26:54 +02007147 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7148 void *data;
7149 int len, i;
7150
7151 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7152 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7153 settings->n_ciphers_pairwise = len / sizeof(u32);
7154
7155 if (len % sizeof(u32))
7156 return -EINVAL;
7157
Johannes Berg3dc27d22009-07-02 21:36:37 +02007158 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007159 return -EINVAL;
7160
7161 memcpy(settings->ciphers_pairwise, data, len);
7162
7163 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007164 if (!cfg80211_supported_cipher_suite(
7165 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007166 settings->ciphers_pairwise[i]))
7167 return -EINVAL;
7168 }
7169
7170 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7171 settings->cipher_group =
7172 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007173 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7174 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007175 return -EINVAL;
7176 }
7177
7178 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7179 settings->wpa_versions =
7180 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7181 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7182 return -EINVAL;
7183 }
7184
7185 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7186 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007187 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007188
7189 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7190 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7191 settings->n_akm_suites = len / sizeof(u32);
7192
7193 if (len % sizeof(u32))
7194 return -EINVAL;
7195
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007196 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7197 return -EINVAL;
7198
Samuel Ortizb23aa672009-07-01 21:26:54 +02007199 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007200 }
7201
7202 return 0;
7203}
7204
Jouni Malinen636a5d32009-03-19 13:39:22 +02007205static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7206{
Johannes Berg4c476992010-10-04 21:36:35 +02007207 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7208 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007209 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007210 struct cfg80211_assoc_request req = {};
7211 const u8 *bssid, *ssid;
7212 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007213
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007214 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7215 return -EINVAL;
7216
7217 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007218 !info->attrs[NL80211_ATTR_SSID] ||
7219 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007220 return -EINVAL;
7221
Johannes Berg4c476992010-10-04 21:36:35 +02007222 if (!rdev->ops->assoc)
7223 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007224
Johannes Berg074ac8d2010-09-16 14:58:22 +02007225 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007226 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7227 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007228
Johannes Berg19957bb2009-07-02 17:20:43 +02007229 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007230
Jouni Malinen664834d2014-01-15 00:01:44 +02007231 chan = nl80211_get_valid_chan(&rdev->wiphy,
7232 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7233 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007234 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007235
Johannes Berg19957bb2009-07-02 17:20:43 +02007236 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7237 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007238
7239 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007240 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7241 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007242 }
7243
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007244 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007245 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007246 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007247 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007248 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007249 else if (mfp != NL80211_MFP_NO)
7250 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007251 }
7252
Johannes Berg3e5d7642009-07-07 14:37:26 +02007253 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007254 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007255
Ben Greear7e7c8922011-11-18 11:31:59 -08007256 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007257 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007258
7259 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007260 memcpy(&req.ht_capa_mask,
7261 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7262 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007263
7264 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007265 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007266 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007267 memcpy(&req.ht_capa,
7268 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7269 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007270 }
7271
Johannes Bergee2aca32013-02-21 17:36:01 +01007272 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007273 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007274
7275 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007276 memcpy(&req.vht_capa_mask,
7277 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7278 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007279
7280 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007281 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007282 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007283 memcpy(&req.vht_capa,
7284 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7285 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007286 }
7287
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007288 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7289 if (!(rdev->wiphy.features &
7290 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7291 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7292 return -EINVAL;
7293 req.flags |= ASSOC_REQ_USE_RRM;
7294 }
7295
Johannes Bergf62fab72013-02-21 20:09:09 +01007296 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007297 if (!err) {
7298 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007299 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7300 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007301 wdev_unlock(dev->ieee80211_ptr);
7302 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007303
Jouni Malinen636a5d32009-03-19 13:39:22 +02007304 return err;
7305}
7306
7307static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7308{
Johannes Berg4c476992010-10-04 21:36:35 +02007309 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7310 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007311 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007312 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007313 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007314 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007315
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007316 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7317 return -EINVAL;
7318
7319 if (!info->attrs[NL80211_ATTR_MAC])
7320 return -EINVAL;
7321
7322 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7323 return -EINVAL;
7324
Johannes Berg4c476992010-10-04 21:36:35 +02007325 if (!rdev->ops->deauth)
7326 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007327
Johannes Berg074ac8d2010-09-16 14:58:22 +02007328 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007329 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7330 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007331
Johannes Berg19957bb2009-07-02 17:20:43 +02007332 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007333
Johannes Berg19957bb2009-07-02 17:20:43 +02007334 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7335 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007336 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007337 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007338 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007339
7340 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007341 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7342 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007343 }
7344
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007345 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7346
Johannes Berg91bf9b22013-05-15 17:44:01 +02007347 wdev_lock(dev->ieee80211_ptr);
7348 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7349 local_state_change);
7350 wdev_unlock(dev->ieee80211_ptr);
7351 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007352}
7353
7354static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7355{
Johannes Berg4c476992010-10-04 21:36:35 +02007356 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7357 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007358 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007359 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007360 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007361 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007362
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007363 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7364 return -EINVAL;
7365
7366 if (!info->attrs[NL80211_ATTR_MAC])
7367 return -EINVAL;
7368
7369 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7370 return -EINVAL;
7371
Johannes Berg4c476992010-10-04 21:36:35 +02007372 if (!rdev->ops->disassoc)
7373 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007374
Johannes Berg074ac8d2010-09-16 14:58:22 +02007375 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007376 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7377 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007378
Johannes Berg19957bb2009-07-02 17:20:43 +02007379 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007380
Johannes Berg19957bb2009-07-02 17:20:43 +02007381 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7382 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007383 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007384 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007385 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007386
7387 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007388 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7389 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007390 }
7391
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007392 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7393
Johannes Berg91bf9b22013-05-15 17:44:01 +02007394 wdev_lock(dev->ieee80211_ptr);
7395 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7396 local_state_change);
7397 wdev_unlock(dev->ieee80211_ptr);
7398 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007399}
7400
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007401static bool
7402nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7403 int mcast_rate[IEEE80211_NUM_BANDS],
7404 int rateval)
7405{
7406 struct wiphy *wiphy = &rdev->wiphy;
7407 bool found = false;
7408 int band, i;
7409
7410 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7411 struct ieee80211_supported_band *sband;
7412
7413 sband = wiphy->bands[band];
7414 if (!sband)
7415 continue;
7416
7417 for (i = 0; i < sband->n_bitrates; i++) {
7418 if (sband->bitrates[i].bitrate == rateval) {
7419 mcast_rate[band] = i + 1;
7420 found = true;
7421 break;
7422 }
7423 }
7424 }
7425
7426 return found;
7427}
7428
Johannes Berg04a773a2009-04-19 21:24:32 +02007429static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7430{
Johannes Berg4c476992010-10-04 21:36:35 +02007431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7432 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007433 struct cfg80211_ibss_params ibss;
7434 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007435 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007436 int err;
7437
Johannes Berg8e30bc52009-04-22 17:45:38 +02007438 memset(&ibss, 0, sizeof(ibss));
7439
Johannes Berg04a773a2009-04-19 21:24:32 +02007440 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7441 return -EINVAL;
7442
Johannes Berg683b6d32012-11-08 21:25:48 +01007443 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007444 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7445 return -EINVAL;
7446
Johannes Berg8e30bc52009-04-22 17:45:38 +02007447 ibss.beacon_interval = 100;
7448
7449 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7450 ibss.beacon_interval =
7451 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7452 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7453 return -EINVAL;
7454 }
7455
Johannes Berg4c476992010-10-04 21:36:35 +02007456 if (!rdev->ops->join_ibss)
7457 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007458
Johannes Berg4c476992010-10-04 21:36:35 +02007459 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7460 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007461
Johannes Berg79c97e92009-07-07 03:56:12 +02007462 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007463
Johannes Berg39193492011-09-16 13:45:25 +02007464 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007465 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007466
7467 if (!is_valid_ether_addr(ibss.bssid))
7468 return -EINVAL;
7469 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007470 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7471 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7472
7473 if (info->attrs[NL80211_ATTR_IE]) {
7474 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7475 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7476 }
7477
Johannes Berg683b6d32012-11-08 21:25:48 +01007478 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7479 if (err)
7480 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007481
Ilan Peer174e0cd2014-02-23 09:13:01 +02007482 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7483 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007484 return -EINVAL;
7485
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007486 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007487 case NL80211_CHAN_WIDTH_5:
7488 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007489 case NL80211_CHAN_WIDTH_20_NOHT:
7490 break;
7491 case NL80211_CHAN_WIDTH_20:
7492 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007493 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7494 return -EINVAL;
7495 break;
7496 case NL80211_CHAN_WIDTH_80:
7497 case NL80211_CHAN_WIDTH_80P80:
7498 case NL80211_CHAN_WIDTH_160:
7499 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7500 return -EINVAL;
7501 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7502 NL80211_EXT_FEATURE_VHT_IBSS))
7503 return -EINVAL;
7504 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007505 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007506 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007507 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007508
Johannes Berg04a773a2009-04-19 21:24:32 +02007509 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007510 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007511
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007512 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7513 u8 *rates =
7514 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7515 int n_rates =
7516 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7517 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007518 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007519
Johannes Berg34850ab2011-07-18 18:08:35 +02007520 err = ieee80211_get_ratemask(sband, rates, n_rates,
7521 &ibss.basic_rates);
7522 if (err)
7523 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007524 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007525
Simon Wunderlich803768f2013-06-28 10:39:58 +02007526 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7527 memcpy(&ibss.ht_capa_mask,
7528 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7529 sizeof(ibss.ht_capa_mask));
7530
7531 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7532 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7533 return -EINVAL;
7534 memcpy(&ibss.ht_capa,
7535 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7536 sizeof(ibss.ht_capa));
7537 }
7538
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007539 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7540 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7541 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7542 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007543
Johannes Berg4c476992010-10-04 21:36:35 +02007544 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307545 bool no_ht = false;
7546
Johannes Berg4c476992010-10-04 21:36:35 +02007547 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307548 info->attrs[NL80211_ATTR_KEYS],
7549 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007550 if (IS_ERR(connkeys))
7551 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307552
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007553 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7554 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307555 kfree(connkeys);
7556 return -EINVAL;
7557 }
Johannes Berg4c476992010-10-04 21:36:35 +02007558 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007559
Antonio Quartulli267335d2012-01-31 20:25:47 +01007560 ibss.control_port =
7561 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7562
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007563 ibss.userspace_handles_dfs =
7564 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7565
Johannes Berg4c476992010-10-04 21:36:35 +02007566 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007567 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007568 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007569 return err;
7570}
7571
7572static int nl80211_leave_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
Johannes Berg4c476992010-10-04 21:36:35 +02007577 if (!rdev->ops->leave_ibss)
7578 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007579
Johannes Berg4c476992010-10-04 21:36:35 +02007580 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7581 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007582
Johannes Berg4c476992010-10-04 21:36:35 +02007583 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007584}
7585
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007586static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7587{
7588 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7589 struct net_device *dev = info->user_ptr[1];
7590 int mcast_rate[IEEE80211_NUM_BANDS];
7591 u32 nla_rate;
7592 int err;
7593
7594 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007595 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7596 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007597 return -EOPNOTSUPP;
7598
7599 if (!rdev->ops->set_mcast_rate)
7600 return -EOPNOTSUPP;
7601
7602 memset(mcast_rate, 0, sizeof(mcast_rate));
7603
7604 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7605 return -EINVAL;
7606
7607 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7608 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7609 return -EINVAL;
7610
Ilan Peera1056b12015-10-22 22:27:46 +03007611 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007612
7613 return err;
7614}
7615
Johannes Bergad7e7182013-11-13 13:37:47 +01007616static struct sk_buff *
7617__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007618 struct wireless_dev *wdev, int approxlen,
7619 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007620 enum nl80211_attrs attr,
7621 const struct nl80211_vendor_cmd_info *info,
7622 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007623{
7624 struct sk_buff *skb;
7625 void *hdr;
7626 struct nlattr *data;
7627
7628 skb = nlmsg_new(approxlen + 100, gfp);
7629 if (!skb)
7630 return NULL;
7631
7632 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7633 if (!hdr) {
7634 kfree_skb(skb);
7635 return NULL;
7636 }
7637
7638 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7639 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007640
7641 if (info) {
7642 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7643 info->vendor_id))
7644 goto nla_put_failure;
7645 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7646 info->subcmd))
7647 goto nla_put_failure;
7648 }
7649
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007650 if (wdev) {
7651 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7652 wdev_id(wdev)))
7653 goto nla_put_failure;
7654 if (wdev->netdev &&
7655 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7656 wdev->netdev->ifindex))
7657 goto nla_put_failure;
7658 }
7659
Johannes Bergad7e7182013-11-13 13:37:47 +01007660 data = nla_nest_start(skb, attr);
7661
7662 ((void **)skb->cb)[0] = rdev;
7663 ((void **)skb->cb)[1] = hdr;
7664 ((void **)skb->cb)[2] = data;
7665
7666 return skb;
7667
7668 nla_put_failure:
7669 kfree_skb(skb);
7670 return NULL;
7671}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007672
Johannes Berge03ad6e2014-01-01 17:22:30 +01007673struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007674 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007675 enum nl80211_commands cmd,
7676 enum nl80211_attrs attr,
7677 int vendor_event_idx,
7678 int approxlen, gfp_t gfp)
7679{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007680 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007681 const struct nl80211_vendor_cmd_info *info;
7682
7683 switch (cmd) {
7684 case NL80211_CMD_TESTMODE:
7685 if (WARN_ON(vendor_event_idx != -1))
7686 return NULL;
7687 info = NULL;
7688 break;
7689 case NL80211_CMD_VENDOR:
7690 if (WARN_ON(vendor_event_idx < 0 ||
7691 vendor_event_idx >= wiphy->n_vendor_events))
7692 return NULL;
7693 info = &wiphy->vendor_events[vendor_event_idx];
7694 break;
7695 default:
7696 WARN_ON(1);
7697 return NULL;
7698 }
7699
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007700 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007701 cmd, attr, info, gfp);
7702}
7703EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7704
7705void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7706{
7707 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7708 void *hdr = ((void **)skb->cb)[1];
7709 struct nlattr *data = ((void **)skb->cb)[2];
7710 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7711
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007712 /* clear CB data for netlink core to own from now on */
7713 memset(skb->cb, 0, sizeof(skb->cb));
7714
Johannes Berge03ad6e2014-01-01 17:22:30 +01007715 nla_nest_end(skb, data);
7716 genlmsg_end(skb, hdr);
7717
7718 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7719 mcgrp = NL80211_MCGRP_VENDOR;
7720
7721 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7722 mcgrp, gfp);
7723}
7724EXPORT_SYMBOL(__cfg80211_send_event_skb);
7725
Johannes Bergaff89a92009-07-01 21:26:51 +02007726#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007727static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7728{
Johannes Berg4c476992010-10-04 21:36:35 +02007729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007730 struct wireless_dev *wdev =
7731 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007732 int err;
7733
David Spinadelfc73f112013-07-31 18:04:15 +03007734 if (!rdev->ops->testmode_cmd)
7735 return -EOPNOTSUPP;
7736
7737 if (IS_ERR(wdev)) {
7738 err = PTR_ERR(wdev);
7739 if (err != -EINVAL)
7740 return err;
7741 wdev = NULL;
7742 } else if (wdev->wiphy != &rdev->wiphy) {
7743 return -EINVAL;
7744 }
7745
Johannes Bergaff89a92009-07-01 21:26:51 +02007746 if (!info->attrs[NL80211_ATTR_TESTDATA])
7747 return -EINVAL;
7748
Johannes Bergad7e7182013-11-13 13:37:47 +01007749 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007750 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007751 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7752 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007753 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007754
Johannes Bergaff89a92009-07-01 21:26:51 +02007755 return err;
7756}
7757
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007758static int nl80211_testmode_dump(struct sk_buff *skb,
7759 struct netlink_callback *cb)
7760{
Johannes Berg00918d32011-12-13 17:22:05 +01007761 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007762 int err;
7763 long phy_idx;
7764 void *data = NULL;
7765 int data_len = 0;
7766
Johannes Berg5fe231e2013-05-08 21:45:15 +02007767 rtnl_lock();
7768
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007769 if (cb->args[0]) {
7770 /*
7771 * 0 is a valid index, but not valid for args[0],
7772 * so we need to offset by 1.
7773 */
7774 phy_idx = cb->args[0] - 1;
7775 } else {
7776 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7777 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7778 nl80211_policy);
7779 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007780 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007781
Johannes Berg2bd7e352012-06-15 14:23:16 +02007782 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7783 nl80211_fam.attrbuf);
7784 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007785 err = PTR_ERR(rdev);
7786 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007787 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007788 phy_idx = rdev->wiphy_idx;
7789 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007790
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007791 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7792 cb->args[1] =
7793 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7794 }
7795
7796 if (cb->args[1]) {
7797 data = nla_data((void *)cb->args[1]);
7798 data_len = nla_len((void *)cb->args[1]);
7799 }
7800
Johannes Berg00918d32011-12-13 17:22:05 +01007801 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7802 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007803 err = -ENOENT;
7804 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007805 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007806
Johannes Berg00918d32011-12-13 17:22:05 +01007807 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007808 err = -EOPNOTSUPP;
7809 goto out_err;
7810 }
7811
7812 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007813 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007814 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7815 NL80211_CMD_TESTMODE);
7816 struct nlattr *tmdata;
7817
Dan Carpentercb35fba2013-08-14 14:50:01 +03007818 if (!hdr)
7819 break;
7820
David S. Miller9360ffd2012-03-29 04:41:26 -04007821 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007822 genlmsg_cancel(skb, hdr);
7823 break;
7824 }
7825
7826 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7827 if (!tmdata) {
7828 genlmsg_cancel(skb, hdr);
7829 break;
7830 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007831 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007832 nla_nest_end(skb, tmdata);
7833
7834 if (err == -ENOBUFS || err == -ENOENT) {
7835 genlmsg_cancel(skb, hdr);
7836 break;
7837 } else if (err) {
7838 genlmsg_cancel(skb, hdr);
7839 goto out_err;
7840 }
7841
7842 genlmsg_end(skb, hdr);
7843 }
7844
7845 err = skb->len;
7846 /* see above */
7847 cb->args[0] = phy_idx + 1;
7848 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007849 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007850 return err;
7851}
Johannes Bergaff89a92009-07-01 21:26:51 +02007852#endif
7853
Samuel Ortizb23aa672009-07-01 21:26:54 +02007854static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7855{
Johannes Berg4c476992010-10-04 21:36:35 +02007856 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7857 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007858 struct cfg80211_connect_params connect;
7859 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007860 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007861 int err;
7862
7863 memset(&connect, 0, sizeof(connect));
7864
7865 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7866 return -EINVAL;
7867
7868 if (!info->attrs[NL80211_ATTR_SSID] ||
7869 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7870 return -EINVAL;
7871
7872 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7873 connect.auth_type =
7874 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007875 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7876 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007877 return -EINVAL;
7878 } else
7879 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7880
7881 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7882
Johannes Bergc0692b82010-08-27 14:26:53 +03007883 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007884 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007885 if (err)
7886 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007887
Johannes Berg074ac8d2010-09-16 14:58:22 +02007888 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007889 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7890 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007891
Johannes Berg79c97e92009-07-07 03:56:12 +02007892 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007893
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307894 connect.bg_scan_period = -1;
7895 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7896 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7897 connect.bg_scan_period =
7898 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7899 }
7900
Samuel Ortizb23aa672009-07-01 21:26:54 +02007901 if (info->attrs[NL80211_ATTR_MAC])
7902 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007903 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7904 connect.bssid_hint =
7905 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007906 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7907 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7908
7909 if (info->attrs[NL80211_ATTR_IE]) {
7910 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7911 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7912 }
7913
Jouni Malinencee00a92013-01-15 17:15:57 +02007914 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7915 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7916 if (connect.mfp != NL80211_MFP_REQUIRED &&
7917 connect.mfp != NL80211_MFP_NO)
7918 return -EINVAL;
7919 } else {
7920 connect.mfp = NL80211_MFP_NO;
7921 }
7922
Samuel Ortizb23aa672009-07-01 21:26:54 +02007923 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007924 connect.channel = nl80211_get_valid_chan(
7925 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7926 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007927 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007928 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007929 connect.channel_hint = nl80211_get_valid_chan(
7930 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7931 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007932 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007933 }
7934
Johannes Bergfffd0932009-07-08 14:22:54 +02007935 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7936 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307937 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007938 if (IS_ERR(connkeys))
7939 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007940 }
7941
Ben Greear7e7c8922011-11-18 11:31:59 -08007942 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7943 connect.flags |= ASSOC_REQ_DISABLE_HT;
7944
7945 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7946 memcpy(&connect.ht_capa_mask,
7947 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7948 sizeof(connect.ht_capa_mask));
7949
7950 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007951 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007952 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007953 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007954 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007955 memcpy(&connect.ht_capa,
7956 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7957 sizeof(connect.ht_capa));
7958 }
7959
Johannes Bergee2aca32013-02-21 17:36:01 +01007960 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7961 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7962
7963 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7964 memcpy(&connect.vht_capa_mask,
7965 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7966 sizeof(connect.vht_capa_mask));
7967
7968 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7969 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007970 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007971 return -EINVAL;
7972 }
7973 memcpy(&connect.vht_capa,
7974 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7975 sizeof(connect.vht_capa));
7976 }
7977
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007978 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7979 if (!(rdev->wiphy.features &
7980 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
Ola Olsson707554b2015-12-11 21:04:52 +01007981 !(rdev->wiphy.features & NL80211_FEATURE_QUIET)) {
7982 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007983 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01007984 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007985 connect.flags |= ASSOC_REQ_USE_RRM;
7986 }
7987
Lior David34d50512016-01-28 10:58:25 +02007988 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
7989 if (connect.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ]) {
7990 kzfree(connkeys);
7991 return -EOPNOTSUPP;
7992 }
7993
Johannes Berg83739b02013-05-15 17:44:01 +02007994 wdev_lock(dev->ieee80211_ptr);
7995 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7996 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007997 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007998 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007999 return err;
8000}
8001
8002static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8003{
Johannes Berg4c476992010-10-04 21:36:35 +02008004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8005 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008006 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008007 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008008
8009 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8010 reason = WLAN_REASON_DEAUTH_LEAVING;
8011 else
8012 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8013
8014 if (reason == 0)
8015 return -EINVAL;
8016
Johannes Berg074ac8d2010-09-16 14:58:22 +02008017 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008018 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8019 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008020
Johannes Berg83739b02013-05-15 17:44:01 +02008021 wdev_lock(dev->ieee80211_ptr);
8022 ret = cfg80211_disconnect(rdev, dev, reason, true);
8023 wdev_unlock(dev->ieee80211_ptr);
8024 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008025}
8026
Johannes Berg463d0182009-07-14 00:33:35 +02008027static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8028{
Johannes Berg4c476992010-10-04 21:36:35 +02008029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008030 struct net *net;
8031 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008032
Vadim Kochan4b681c82015-01-12 16:34:05 +02008033 if (info->attrs[NL80211_ATTR_PID]) {
8034 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8035
8036 net = get_net_ns_by_pid(pid);
8037 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8038 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8039
8040 net = get_net_ns_by_fd(fd);
8041 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008042 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008043 }
Johannes Berg463d0182009-07-14 00:33:35 +02008044
Johannes Berg4c476992010-10-04 21:36:35 +02008045 if (IS_ERR(net))
8046 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008047
8048 err = 0;
8049
8050 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008051 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8052 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008053
Johannes Berg463d0182009-07-14 00:33:35 +02008054 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008055 return err;
8056}
8057
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008058static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8059{
Johannes Berg4c476992010-10-04 21:36:35 +02008060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008061 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8062 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008063 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008064 struct cfg80211_pmksa pmksa;
8065
8066 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8067
8068 if (!info->attrs[NL80211_ATTR_MAC])
8069 return -EINVAL;
8070
8071 if (!info->attrs[NL80211_ATTR_PMKID])
8072 return -EINVAL;
8073
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008074 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8075 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8076
Johannes Berg074ac8d2010-09-16 14:58:22 +02008077 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008078 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8079 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008080
8081 switch (info->genlhdr->cmd) {
8082 case NL80211_CMD_SET_PMKSA:
8083 rdev_ops = rdev->ops->set_pmksa;
8084 break;
8085 case NL80211_CMD_DEL_PMKSA:
8086 rdev_ops = rdev->ops->del_pmksa;
8087 break;
8088 default:
8089 WARN_ON(1);
8090 break;
8091 }
8092
Johannes Berg4c476992010-10-04 21:36:35 +02008093 if (!rdev_ops)
8094 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008095
Johannes Berg4c476992010-10-04 21:36:35 +02008096 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008097}
8098
8099static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8100{
Johannes Berg4c476992010-10-04 21:36:35 +02008101 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8102 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008103
Johannes Berg074ac8d2010-09-16 14:58:22 +02008104 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008105 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8106 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008107
Johannes Berg4c476992010-10-04 21:36:35 +02008108 if (!rdev->ops->flush_pmksa)
8109 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008110
Hila Gonene35e4d22012-06-27 17:19:42 +03008111 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008112}
8113
Arik Nemtsov109086c2011-09-28 14:12:50 +03008114static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8115{
8116 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8117 struct net_device *dev = info->user_ptr[1];
8118 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308119 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008120 u16 status_code;
8121 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008122 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008123
8124 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8125 !rdev->ops->tdls_mgmt)
8126 return -EOPNOTSUPP;
8127
8128 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8129 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8130 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8131 !info->attrs[NL80211_ATTR_IE] ||
8132 !info->attrs[NL80211_ATTR_MAC])
8133 return -EINVAL;
8134
8135 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8136 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8137 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8138 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008139 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308140 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8141 peer_capability =
8142 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008143
Hila Gonene35e4d22012-06-27 17:19:42 +03008144 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308145 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008146 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008147 nla_data(info->attrs[NL80211_ATTR_IE]),
8148 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008149}
8150
8151static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8152{
8153 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8154 struct net_device *dev = info->user_ptr[1];
8155 enum nl80211_tdls_operation operation;
8156 u8 *peer;
8157
8158 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8159 !rdev->ops->tdls_oper)
8160 return -EOPNOTSUPP;
8161
8162 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8163 !info->attrs[NL80211_ATTR_MAC])
8164 return -EINVAL;
8165
8166 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8167 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8168
Hila Gonene35e4d22012-06-27 17:19:42 +03008169 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008170}
8171
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008172static int nl80211_remain_on_channel(struct sk_buff *skb,
8173 struct genl_info *info)
8174{
Johannes Berg4c476992010-10-04 21:36:35 +02008175 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008176 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008177 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008178 struct sk_buff *msg;
8179 void *hdr;
8180 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008181 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008182 int err;
8183
8184 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8185 !info->attrs[NL80211_ATTR_DURATION])
8186 return -EINVAL;
8187
8188 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8189
Johannes Berg7c4ef712011-11-18 15:33:48 +01008190 if (!rdev->ops->remain_on_channel ||
8191 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008192 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008193
Johannes Bergebf348f2012-06-01 12:50:54 +02008194 /*
8195 * We should be on that channel for at least a minimum amount of
8196 * time (10ms) but no longer than the driver supports.
8197 */
8198 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8199 duration > rdev->wiphy.max_remain_on_channel_duration)
8200 return -EINVAL;
8201
Johannes Berg683b6d32012-11-08 21:25:48 +01008202 err = nl80211_parse_chandef(rdev, info, &chandef);
8203 if (err)
8204 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008205
8206 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008207 if (!msg)
8208 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008209
Eric W. Biederman15e47302012-09-07 20:12:54 +00008210 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008211 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008212 if (!hdr) {
8213 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008214 goto free_msg;
8215 }
8216
Johannes Berg683b6d32012-11-08 21:25:48 +01008217 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8218 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008219
8220 if (err)
8221 goto free_msg;
8222
David S. Miller9360ffd2012-03-29 04:41:26 -04008223 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8224 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008225
8226 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008227
8228 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008229
8230 nla_put_failure:
8231 err = -ENOBUFS;
8232 free_msg:
8233 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008234 return err;
8235}
8236
8237static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8238 struct genl_info *info)
8239{
Johannes Berg4c476992010-10-04 21:36:35 +02008240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008241 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008242 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008243
8244 if (!info->attrs[NL80211_ATTR_COOKIE])
8245 return -EINVAL;
8246
Johannes Berg4c476992010-10-04 21:36:35 +02008247 if (!rdev->ops->cancel_remain_on_channel)
8248 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008249
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008250 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8251
Hila Gonene35e4d22012-06-27 17:19:42 +03008252 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008253}
8254
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008255static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8256 u8 *rates, u8 rates_len)
8257{
8258 u8 i;
8259 u32 mask = 0;
8260
8261 for (i = 0; i < rates_len; i++) {
8262 int rate = (rates[i] & 0x7f) * 5;
8263 int ridx;
8264 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8265 struct ieee80211_rate *srate =
8266 &sband->bitrates[ridx];
8267 if (rate == srate->bitrate) {
8268 mask |= 1 << ridx;
8269 break;
8270 }
8271 }
8272 if (ridx == sband->n_bitrates)
8273 return 0; /* rate not found */
8274 }
8275
8276 return mask;
8277}
8278
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008279static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8280 u8 *rates, u8 rates_len,
8281 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8282{
8283 u8 i;
8284
8285 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8286
8287 for (i = 0; i < rates_len; i++) {
8288 int ridx, rbit;
8289
8290 ridx = rates[i] / 8;
8291 rbit = BIT(rates[i] % 8);
8292
8293 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008294 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008295 return false;
8296
8297 /* check availability */
8298 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8299 mcs[ridx] |= rbit;
8300 else
8301 return false;
8302 }
8303
8304 return true;
8305}
8306
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008307static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8308{
8309 u16 mcs_mask = 0;
8310
8311 switch (vht_mcs_map) {
8312 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8313 break;
8314 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8315 mcs_mask = 0x00FF;
8316 break;
8317 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8318 mcs_mask = 0x01FF;
8319 break;
8320 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8321 mcs_mask = 0x03FF;
8322 break;
8323 default:
8324 break;
8325 }
8326
8327 return mcs_mask;
8328}
8329
8330static void vht_build_mcs_mask(u16 vht_mcs_map,
8331 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8332{
8333 u8 nss;
8334
8335 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8336 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8337 vht_mcs_map >>= 2;
8338 }
8339}
8340
8341static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8342 struct nl80211_txrate_vht *txrate,
8343 u16 mcs[NL80211_VHT_NSS_MAX])
8344{
8345 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8346 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8347 u8 i;
8348
8349 if (!sband->vht_cap.vht_supported)
8350 return false;
8351
8352 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8353
8354 /* Build vht_mcs_mask from VHT capabilities */
8355 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8356
8357 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8358 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8359 mcs[i] = txrate->mcs[i];
8360 else
8361 return false;
8362 }
8363
8364 return true;
8365}
8366
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008367static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008368 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8369 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008370 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8371 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008372 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008373 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008374};
8375
8376static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8377 struct genl_info *info)
8378{
8379 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008380 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008381 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008382 int rem, i;
8383 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008384 struct nlattr *tx_rates;
8385 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008386 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008387
Johannes Berg4c476992010-10-04 21:36:35 +02008388 if (!rdev->ops->set_bitrate_mask)
8389 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008390
8391 memset(&mask, 0, sizeof(mask));
8392 /* Default to all rates enabled */
8393 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8394 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008395
8396 if (!sband)
8397 continue;
8398
8399 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008400 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008401 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008402 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008403
8404 if (!sband->vht_cap.vht_supported)
8405 continue;
8406
8407 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8408 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008409 }
8410
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008411 /* if no rates are given set it back to the defaults */
8412 if (!info->attrs[NL80211_ATTR_TX_RATES])
8413 goto out;
8414
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008415 /*
8416 * The nested attribute uses enum nl80211_band as the index. This maps
8417 * directly to the enum ieee80211_band values used in cfg80211.
8418 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008419 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008420 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008421 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008422 int err;
8423
Johannes Berg4c476992010-10-04 21:36:35 +02008424 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8425 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008426 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008427 if (sband == NULL)
8428 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008429 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8430 nla_len(tx_rates), nl80211_txattr_policy);
8431 if (err)
8432 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008433 if (tb[NL80211_TXRATE_LEGACY]) {
8434 mask.control[band].legacy = rateset_to_mask(
8435 sband,
8436 nla_data(tb[NL80211_TXRATE_LEGACY]),
8437 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308438 if ((mask.control[band].legacy == 0) &&
8439 nla_len(tb[NL80211_TXRATE_LEGACY]))
8440 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008441 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008442 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008443 if (!ht_rateset_to_mask(
8444 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008445 nla_data(tb[NL80211_TXRATE_HT]),
8446 nla_len(tb[NL80211_TXRATE_HT]),
8447 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008448 return -EINVAL;
8449 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008450 if (tb[NL80211_TXRATE_VHT]) {
8451 if (!vht_set_mcs_mask(
8452 sband,
8453 nla_data(tb[NL80211_TXRATE_VHT]),
8454 mask.control[band].vht_mcs))
8455 return -EINVAL;
8456 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008457 if (tb[NL80211_TXRATE_GI]) {
8458 mask.control[band].gi =
8459 nla_get_u8(tb[NL80211_TXRATE_GI]);
8460 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8461 return -EINVAL;
8462 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008463
8464 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008465 /* don't allow empty legacy rates if HT or VHT
8466 * are not even supported.
8467 */
8468 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8469 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008470 return -EINVAL;
8471
8472 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008473 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008474 goto out;
8475
8476 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8477 if (mask.control[band].vht_mcs[i])
8478 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008479
8480 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008481 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008482 }
8483 }
8484
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008485out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008486 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008487}
8488
Johannes Berg2e161f72010-08-12 15:38:38 +02008489static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008490{
Johannes Berg4c476992010-10-04 21:36:35 +02008491 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008492 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008493 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008494
8495 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8496 return -EINVAL;
8497
Johannes Berg2e161f72010-08-12 15:38:38 +02008498 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8499 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008500
Johannes Berg71bbc992012-06-15 15:30:18 +02008501 switch (wdev->iftype) {
8502 case NL80211_IFTYPE_STATION:
8503 case NL80211_IFTYPE_ADHOC:
8504 case NL80211_IFTYPE_P2P_CLIENT:
8505 case NL80211_IFTYPE_AP:
8506 case NL80211_IFTYPE_AP_VLAN:
8507 case NL80211_IFTYPE_MESH_POINT:
8508 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008509 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008510 break;
8511 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008512 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008513 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008514
8515 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008516 if (!rdev->ops->mgmt_tx)
8517 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008518
Eric W. Biederman15e47302012-09-07 20:12:54 +00008519 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008520 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8521 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008522}
8523
Johannes Berg2e161f72010-08-12 15:38:38 +02008524static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008525{
Johannes Berg4c476992010-10-04 21:36:35 +02008526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008527 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008528 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008529 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008530 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008531 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008532 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008533 struct cfg80211_mgmt_tx_params params = {
8534 .dont_wait_for_ack =
8535 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8536 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008537
Johannes Berg683b6d32012-11-08 21:25:48 +01008538 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008539 return -EINVAL;
8540
Johannes Berg4c476992010-10-04 21:36:35 +02008541 if (!rdev->ops->mgmt_tx)
8542 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008543
Johannes Berg71bbc992012-06-15 15:30:18 +02008544 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008545 case NL80211_IFTYPE_P2P_DEVICE:
8546 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8547 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008548 case NL80211_IFTYPE_STATION:
8549 case NL80211_IFTYPE_ADHOC:
8550 case NL80211_IFTYPE_P2P_CLIENT:
8551 case NL80211_IFTYPE_AP:
8552 case NL80211_IFTYPE_AP_VLAN:
8553 case NL80211_IFTYPE_MESH_POINT:
8554 case NL80211_IFTYPE_P2P_GO:
8555 break;
8556 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008557 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008558 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008559
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008560 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008561 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008562 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008563 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008564
8565 /*
8566 * We should wait on the channel for at least a minimum amount
8567 * of time (10ms) but no longer than the driver supports.
8568 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008569 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8570 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008571 return -EINVAL;
8572
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008573 }
8574
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008575 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008576
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008577 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008578 return -EINVAL;
8579
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008580 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308581
Antonio Quartulliea141b752013-06-11 14:20:03 +02008582 /* get the channel if any has been specified, otherwise pass NULL to
8583 * the driver. The latter will use the current one
8584 */
8585 chandef.chan = NULL;
8586 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8587 err = nl80211_parse_chandef(rdev, info, &chandef);
8588 if (err)
8589 return err;
8590 }
8591
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008592 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008593 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008594
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008595 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8596 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8597
8598 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8599 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8600 int i;
8601
8602 if (len % sizeof(u16))
8603 return -EINVAL;
8604
8605 params.n_csa_offsets = len / sizeof(u16);
8606 params.csa_offsets =
8607 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8608
8609 /* check that all the offsets fit the frame */
8610 for (i = 0; i < params.n_csa_offsets; i++) {
8611 if (params.csa_offsets[i] >= params.len)
8612 return -EINVAL;
8613 }
8614 }
8615
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008616 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008617 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8618 if (!msg)
8619 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008620
Eric W. Biederman15e47302012-09-07 20:12:54 +00008621 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008622 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008623 if (!hdr) {
8624 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008625 goto free_msg;
8626 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008627 }
Johannes Berge247bd902011-11-04 11:18:21 +01008628
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008629 params.chan = chandef.chan;
8630 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008631 if (err)
8632 goto free_msg;
8633
Johannes Berge247bd902011-11-04 11:18:21 +01008634 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008635 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8636 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008637
Johannes Berge247bd902011-11-04 11:18:21 +01008638 genlmsg_end(msg, hdr);
8639 return genlmsg_reply(msg, info);
8640 }
8641
8642 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008643
8644 nla_put_failure:
8645 err = -ENOBUFS;
8646 free_msg:
8647 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008648 return err;
8649}
8650
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008651static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8652{
8653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008654 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008655 u64 cookie;
8656
8657 if (!info->attrs[NL80211_ATTR_COOKIE])
8658 return -EINVAL;
8659
8660 if (!rdev->ops->mgmt_tx_cancel_wait)
8661 return -EOPNOTSUPP;
8662
Johannes Berg71bbc992012-06-15 15:30:18 +02008663 switch (wdev->iftype) {
8664 case NL80211_IFTYPE_STATION:
8665 case NL80211_IFTYPE_ADHOC:
8666 case NL80211_IFTYPE_P2P_CLIENT:
8667 case NL80211_IFTYPE_AP:
8668 case NL80211_IFTYPE_AP_VLAN:
8669 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008670 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008671 break;
8672 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008673 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008674 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008675
8676 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8677
Hila Gonene35e4d22012-06-27 17:19:42 +03008678 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008679}
8680
Kalle Valoffb9eb32010-02-17 17:58:10 +02008681static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8682{
Johannes Berg4c476992010-10-04 21:36:35 +02008683 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008684 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008685 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008686 u8 ps_state;
8687 bool state;
8688 int err;
8689
Johannes Berg4c476992010-10-04 21:36:35 +02008690 if (!info->attrs[NL80211_ATTR_PS_STATE])
8691 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008692
8693 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8694
Johannes Berg4c476992010-10-04 21:36:35 +02008695 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8696 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008697
8698 wdev = dev->ieee80211_ptr;
8699
Johannes Berg4c476992010-10-04 21:36:35 +02008700 if (!rdev->ops->set_power_mgmt)
8701 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008702
8703 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8704
8705 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008706 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008707
Hila Gonene35e4d22012-06-27 17:19:42 +03008708 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008709 if (!err)
8710 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008711 return err;
8712}
8713
8714static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8715{
Johannes Berg4c476992010-10-04 21:36:35 +02008716 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008717 enum nl80211_ps_state ps_state;
8718 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008719 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008720 struct sk_buff *msg;
8721 void *hdr;
8722 int err;
8723
Kalle Valoffb9eb32010-02-17 17:58:10 +02008724 wdev = dev->ieee80211_ptr;
8725
Johannes Berg4c476992010-10-04 21:36:35 +02008726 if (!rdev->ops->set_power_mgmt)
8727 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008728
8729 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008730 if (!msg)
8731 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008732
Eric W. Biederman15e47302012-09-07 20:12:54 +00008733 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008734 NL80211_CMD_GET_POWER_SAVE);
8735 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008736 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008737 goto free_msg;
8738 }
8739
8740 if (wdev->ps)
8741 ps_state = NL80211_PS_ENABLED;
8742 else
8743 ps_state = NL80211_PS_DISABLED;
8744
David S. Miller9360ffd2012-03-29 04:41:26 -04008745 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8746 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008747
8748 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008749 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008750
Johannes Berg4c476992010-10-04 21:36:35 +02008751 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008752 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008753 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008754 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008755 return err;
8756}
8757
Johannes Berg94e860f2014-01-20 23:58:15 +01008758static const struct nla_policy
8759nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008760 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8761 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8762 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008763 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8764 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8765 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008766};
8767
Thomas Pedersen84f10702012-07-12 16:17:33 -07008768static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008769 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008770{
8771 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008772 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008773 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008774
Johannes Bergd9d8b012012-11-26 12:51:52 +01008775 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008776 return -EINVAL;
8777
Thomas Pedersen84f10702012-07-12 16:17:33 -07008778 if (!rdev->ops->set_cqm_txe_config)
8779 return -EOPNOTSUPP;
8780
8781 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8782 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8783 return -EOPNOTSUPP;
8784
Hila Gonene35e4d22012-06-27 17:19:42 +03008785 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008786}
8787
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008788static int nl80211_set_cqm_rssi(struct genl_info *info,
8789 s32 threshold, u32 hysteresis)
8790{
Johannes Berg4c476992010-10-04 21:36:35 +02008791 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008792 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008793 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008794
8795 if (threshold > 0)
8796 return -EINVAL;
8797
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008798 /* disabling - hysteresis should also be zero then */
8799 if (threshold == 0)
8800 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008801
Johannes Berg4c476992010-10-04 21:36:35 +02008802 if (!rdev->ops->set_cqm_rssi_config)
8803 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008804
Johannes Berg074ac8d2010-09-16 14:58:22 +02008805 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008806 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8807 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008808
Hila Gonene35e4d22012-06-27 17:19:42 +03008809 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008810}
8811
8812static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8813{
8814 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8815 struct nlattr *cqm;
8816 int err;
8817
8818 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008819 if (!cqm)
8820 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008821
8822 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8823 nl80211_attr_cqm_policy);
8824 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008825 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008826
8827 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8828 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008829 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8830 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008831
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008832 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8833 }
8834
8835 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8836 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8837 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8838 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8839 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8840 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8841
8842 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8843 }
8844
8845 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008846}
8847
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008848static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8849{
8850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8851 struct net_device *dev = info->user_ptr[1];
8852 struct ocb_setup setup = {};
8853 int err;
8854
8855 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8856 if (err)
8857 return err;
8858
8859 return cfg80211_join_ocb(rdev, dev, &setup);
8860}
8861
8862static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8863{
8864 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8865 struct net_device *dev = info->user_ptr[1];
8866
8867 return cfg80211_leave_ocb(rdev, dev);
8868}
8869
Johannes Berg29cbe682010-12-03 09:20:44 +01008870static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8871{
8872 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8873 struct net_device *dev = info->user_ptr[1];
8874 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008875 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008876 int err;
8877
8878 /* start with default */
8879 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008880 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008881
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008882 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008883 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008884 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008885 if (err)
8886 return err;
8887 }
8888
8889 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8890 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8891 return -EINVAL;
8892
Javier Cardonac80d5452010-12-16 17:37:49 -08008893 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8894 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8895
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008896 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8897 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8898 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8899 return -EINVAL;
8900
Marco Porsch9bdbf042013-01-07 16:04:51 +01008901 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8902 setup.beacon_interval =
8903 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8904 if (setup.beacon_interval < 10 ||
8905 setup.beacon_interval > 10000)
8906 return -EINVAL;
8907 }
8908
8909 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8910 setup.dtim_period =
8911 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8912 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8913 return -EINVAL;
8914 }
8915
Javier Cardonac80d5452010-12-16 17:37:49 -08008916 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8917 /* parse additional setup parameters if given */
8918 err = nl80211_parse_mesh_setup(info, &setup);
8919 if (err)
8920 return err;
8921 }
8922
Thomas Pedersend37bb182013-03-04 13:06:13 -08008923 if (setup.user_mpm)
8924 cfg.auto_open_plinks = false;
8925
Johannes Bergcc1d2802012-05-16 23:50:20 +02008926 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008927 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8928 if (err)
8929 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008930 } else {
8931 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008932 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008933 }
8934
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008935 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8936 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8937 int n_rates =
8938 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8939 struct ieee80211_supported_band *sband;
8940
8941 if (!setup.chandef.chan)
8942 return -EINVAL;
8943
8944 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8945
8946 err = ieee80211_get_ratemask(sband, rates, n_rates,
8947 &setup.basic_rates);
8948 if (err)
8949 return err;
8950 }
8951
Javier Cardonac80d5452010-12-16 17:37:49 -08008952 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008953}
8954
8955static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8956{
8957 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8958 struct net_device *dev = info->user_ptr[1];
8959
8960 return cfg80211_leave_mesh(rdev, dev);
8961}
8962
Johannes Bergdfb89c52012-06-27 09:23:48 +02008963#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008964static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8965 struct cfg80211_registered_device *rdev)
8966{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008967 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008968 struct nlattr *nl_pats, *nl_pat;
8969 int i, pat_len;
8970
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008971 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008972 return 0;
8973
8974 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8975 if (!nl_pats)
8976 return -ENOBUFS;
8977
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008978 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008979 nl_pat = nla_nest_start(msg, i + 1);
8980 if (!nl_pat)
8981 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008982 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008983 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008984 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008985 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8986 wowlan->patterns[i].pattern) ||
8987 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008988 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008989 return -ENOBUFS;
8990 nla_nest_end(msg, nl_pat);
8991 }
8992 nla_nest_end(msg, nl_pats);
8993
8994 return 0;
8995}
8996
Johannes Berg2a0e0472013-01-23 22:57:40 +01008997static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8998 struct cfg80211_wowlan_tcp *tcp)
8999{
9000 struct nlattr *nl_tcp;
9001
9002 if (!tcp)
9003 return 0;
9004
9005 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9006 if (!nl_tcp)
9007 return -ENOBUFS;
9008
Jiri Benc930345e2015-03-29 16:59:25 +02009009 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9010 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009011 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9012 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9013 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9014 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9015 tcp->payload_len, tcp->payload) ||
9016 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9017 tcp->data_interval) ||
9018 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9019 tcp->wake_len, tcp->wake_data) ||
9020 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9021 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9022 return -ENOBUFS;
9023
9024 if (tcp->payload_seq.len &&
9025 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9026 sizeof(tcp->payload_seq), &tcp->payload_seq))
9027 return -ENOBUFS;
9028
9029 if (tcp->payload_tok.len &&
9030 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9031 sizeof(tcp->payload_tok) + tcp->tokens_size,
9032 &tcp->payload_tok))
9033 return -ENOBUFS;
9034
Johannes Berge248ad32013-05-16 10:24:28 +02009035 nla_nest_end(msg, nl_tcp);
9036
Johannes Berg2a0e0472013-01-23 22:57:40 +01009037 return 0;
9038}
9039
Luciano Coelho75453cc2015-01-09 14:06:37 +02009040static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9041 struct cfg80211_sched_scan_request *req)
9042{
Avraham Stern3b06d272015-10-12 09:51:34 +03009043 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009044 int i;
9045
9046 if (!req)
9047 return 0;
9048
9049 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9050 if (!nd)
9051 return -ENOBUFS;
9052
Avraham Stern3b06d272015-10-12 09:51:34 +03009053 if (req->n_scan_plans == 1 &&
9054 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9055 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009056 return -ENOBUFS;
9057
Luciano Coelho21fea562015-03-17 16:36:01 +02009058 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9059 return -ENOBUFS;
9060
Luciano Coelho75453cc2015-01-09 14:06:37 +02009061 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9062 if (!freqs)
9063 return -ENOBUFS;
9064
9065 for (i = 0; i < req->n_channels; i++)
9066 nla_put_u32(msg, i, req->channels[i]->center_freq);
9067
9068 nla_nest_end(msg, freqs);
9069
9070 if (req->n_match_sets) {
9071 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9072 for (i = 0; i < req->n_match_sets; i++) {
9073 match = nla_nest_start(msg, i);
9074 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9075 req->match_sets[i].ssid.ssid_len,
9076 req->match_sets[i].ssid.ssid);
9077 nla_nest_end(msg, match);
9078 }
9079 nla_nest_end(msg, matches);
9080 }
9081
Avraham Stern3b06d272015-10-12 09:51:34 +03009082 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9083 if (!scan_plans)
9084 return -ENOBUFS;
9085
9086 for (i = 0; i < req->n_scan_plans; i++) {
9087 scan_plan = nla_nest_start(msg, i + 1);
9088 if (!scan_plan ||
9089 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9090 req->scan_plans[i].interval) ||
9091 (req->scan_plans[i].iterations &&
9092 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9093 req->scan_plans[i].iterations)))
9094 return -ENOBUFS;
9095 nla_nest_end(msg, scan_plan);
9096 }
9097 nla_nest_end(msg, scan_plans);
9098
Luciano Coelho75453cc2015-01-09 14:06:37 +02009099 nla_nest_end(msg, nd);
9100
9101 return 0;
9102}
9103
Johannes Bergff1b6e62011-05-04 15:37:28 +02009104static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9105{
9106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9107 struct sk_buff *msg;
9108 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009109 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009110
Johannes Berg964dc9e2013-06-03 17:25:34 +02009111 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009112 return -EOPNOTSUPP;
9113
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009114 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009115 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009116 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9117 rdev->wiphy.wowlan_config->tcp->payload_len +
9118 rdev->wiphy.wowlan_config->tcp->wake_len +
9119 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009120 }
9121
9122 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009123 if (!msg)
9124 return -ENOMEM;
9125
Eric W. Biederman15e47302012-09-07 20:12:54 +00009126 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009127 NL80211_CMD_GET_WOWLAN);
9128 if (!hdr)
9129 goto nla_put_failure;
9130
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009131 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009132 struct nlattr *nl_wowlan;
9133
9134 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9135 if (!nl_wowlan)
9136 goto nla_put_failure;
9137
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009138 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009139 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009140 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009141 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009142 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009143 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009144 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009145 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009146 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009147 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009148 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009149 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009150 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009151 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9152 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009153
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009154 if (nl80211_send_wowlan_patterns(msg, rdev))
9155 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009156
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009157 if (nl80211_send_wowlan_tcp(msg,
9158 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009159 goto nla_put_failure;
9160
Luciano Coelho75453cc2015-01-09 14:06:37 +02009161 if (nl80211_send_wowlan_nd(
9162 msg,
9163 rdev->wiphy.wowlan_config->nd_config))
9164 goto nla_put_failure;
9165
Johannes Bergff1b6e62011-05-04 15:37:28 +02009166 nla_nest_end(msg, nl_wowlan);
9167 }
9168
9169 genlmsg_end(msg, hdr);
9170 return genlmsg_reply(msg, info);
9171
9172nla_put_failure:
9173 nlmsg_free(msg);
9174 return -ENOBUFS;
9175}
9176
Johannes Berg2a0e0472013-01-23 22:57:40 +01009177static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9178 struct nlattr *attr,
9179 struct cfg80211_wowlan *trig)
9180{
9181 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9182 struct cfg80211_wowlan_tcp *cfg;
9183 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9184 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9185 u32 size;
9186 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9187 int err, port;
9188
Johannes Berg964dc9e2013-06-03 17:25:34 +02009189 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009190 return -EINVAL;
9191
9192 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9193 nla_data(attr), nla_len(attr),
9194 nl80211_wowlan_tcp_policy);
9195 if (err)
9196 return err;
9197
9198 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9199 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9200 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9201 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9202 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9203 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9204 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9205 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9206 return -EINVAL;
9207
9208 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009209 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009210 return -EINVAL;
9211
9212 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009213 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009214 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009215 return -EINVAL;
9216
9217 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009218 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009219 return -EINVAL;
9220
9221 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9222 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9223 return -EINVAL;
9224
9225 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9226 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9227
9228 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9229 tokens_size = tokln - sizeof(*tok);
9230
9231 if (!tok->len || tokens_size % tok->len)
9232 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009233 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009234 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009235 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009236 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009237 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009238 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009239 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009240 return -EINVAL;
9241 if (tok->offset + tok->len > data_size)
9242 return -EINVAL;
9243 }
9244
9245 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9246 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009247 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009248 return -EINVAL;
9249 if (seq->len == 0 || seq->len > 4)
9250 return -EINVAL;
9251 if (seq->len + seq->offset > data_size)
9252 return -EINVAL;
9253 }
9254
9255 size = sizeof(*cfg);
9256 size += data_size;
9257 size += wake_size + wake_mask_size;
9258 size += tokens_size;
9259
9260 cfg = kzalloc(size, GFP_KERNEL);
9261 if (!cfg)
9262 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009263 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9264 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009265 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9266 ETH_ALEN);
9267 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9268 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9269 else
9270 port = 0;
9271#ifdef CONFIG_INET
9272 /* allocate a socket and port for it and use it */
9273 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9274 IPPROTO_TCP, &cfg->sock, 1);
9275 if (err) {
9276 kfree(cfg);
9277 return err;
9278 }
9279 if (inet_csk_get_port(cfg->sock->sk, port)) {
9280 sock_release(cfg->sock);
9281 kfree(cfg);
9282 return -EADDRINUSE;
9283 }
9284 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9285#else
9286 if (!port) {
9287 kfree(cfg);
9288 return -EINVAL;
9289 }
9290 cfg->src_port = port;
9291#endif
9292
9293 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9294 cfg->payload_len = data_size;
9295 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9296 memcpy((void *)cfg->payload,
9297 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9298 data_size);
9299 if (seq)
9300 cfg->payload_seq = *seq;
9301 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9302 cfg->wake_len = wake_size;
9303 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9304 memcpy((void *)cfg->wake_data,
9305 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9306 wake_size);
9307 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9308 data_size + wake_size;
9309 memcpy((void *)cfg->wake_mask,
9310 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9311 wake_mask_size);
9312 if (tok) {
9313 cfg->tokens_size = tokens_size;
9314 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9315 }
9316
9317 trig->tcp = cfg;
9318
9319 return 0;
9320}
9321
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009322static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9323 const struct wiphy_wowlan_support *wowlan,
9324 struct nlattr *attr,
9325 struct cfg80211_wowlan *trig)
9326{
9327 struct nlattr **tb;
9328 int err;
9329
9330 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9331 if (!tb)
9332 return -ENOMEM;
9333
9334 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9335 err = -EOPNOTSUPP;
9336 goto out;
9337 }
9338
9339 err = nla_parse(tb, NL80211_ATTR_MAX,
9340 nla_data(attr), nla_len(attr),
9341 nl80211_policy);
9342 if (err)
9343 goto out;
9344
Johannes Bergad2b26a2014-06-12 21:39:05 +02009345 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009346 err = PTR_ERR_OR_ZERO(trig->nd_config);
9347 if (err)
9348 trig->nd_config = NULL;
9349
9350out:
9351 kfree(tb);
9352 return err;
9353}
9354
Johannes Bergff1b6e62011-05-04 15:37:28 +02009355static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9356{
9357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9358 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009359 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009360 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009361 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009362 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009363 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009364 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009365
Johannes Berg964dc9e2013-06-03 17:25:34 +02009366 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009367 return -EOPNOTSUPP;
9368
Johannes Bergae33bd82012-07-12 16:25:02 +02009369 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9370 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009371 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009372 goto set_wakeup;
9373 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009374
9375 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9376 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9377 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9378 nl80211_wowlan_policy);
9379 if (err)
9380 return err;
9381
9382 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9383 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9384 return -EINVAL;
9385 new_triggers.any = true;
9386 }
9387
9388 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9389 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9390 return -EINVAL;
9391 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009392 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009393 }
9394
9395 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9396 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9397 return -EINVAL;
9398 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009399 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009400 }
9401
Johannes Berg77dbbb12011-07-13 10:48:55 +02009402 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9403 return -EINVAL;
9404
9405 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9406 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9407 return -EINVAL;
9408 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009409 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009410 }
9411
9412 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9413 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9414 return -EINVAL;
9415 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009416 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009417 }
9418
9419 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9420 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9421 return -EINVAL;
9422 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009423 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009424 }
9425
9426 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9427 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9428 return -EINVAL;
9429 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009430 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009431 }
9432
Johannes Bergff1b6e62011-05-04 15:37:28 +02009433 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9434 struct nlattr *pat;
9435 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009436 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009437 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009438
Johannes Berg98fc4382015-03-01 09:10:13 +02009439 regular = true;
9440
Johannes Bergff1b6e62011-05-04 15:37:28 +02009441 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9442 rem)
9443 n_patterns++;
9444 if (n_patterns > wowlan->n_patterns)
9445 return -EINVAL;
9446
9447 new_triggers.patterns = kcalloc(n_patterns,
9448 sizeof(new_triggers.patterns[0]),
9449 GFP_KERNEL);
9450 if (!new_triggers.patterns)
9451 return -ENOMEM;
9452
9453 new_triggers.n_patterns = n_patterns;
9454 i = 0;
9455
9456 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9457 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009458 u8 *mask_pat;
9459
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009460 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9461 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009462 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009463 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9464 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009465 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009466 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009467 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009468 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009469 goto error;
9470 if (pat_len > wowlan->pattern_max_len ||
9471 pat_len < wowlan->pattern_min_len)
9472 goto error;
9473
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009474 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009475 pkt_offset = 0;
9476 else
9477 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009478 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009479 if (pkt_offset > wowlan->max_pkt_offset)
9480 goto error;
9481 new_triggers.patterns[i].pkt_offset = pkt_offset;
9482
Johannes Berg922bd802014-05-19 17:59:50 +02009483 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9484 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009485 err = -ENOMEM;
9486 goto error;
9487 }
Johannes Berg922bd802014-05-19 17:59:50 +02009488 new_triggers.patterns[i].mask = mask_pat;
9489 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009490 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009491 mask_pat += mask_len;
9492 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009493 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009494 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009495 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009496 pat_len);
9497 i++;
9498 }
9499 }
9500
Johannes Berg2a0e0472013-01-23 22:57:40 +01009501 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009502 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009503 err = nl80211_parse_wowlan_tcp(
9504 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9505 &new_triggers);
9506 if (err)
9507 goto error;
9508 }
9509
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009510 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009511 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009512 err = nl80211_parse_wowlan_nd(
9513 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9514 &new_triggers);
9515 if (err)
9516 goto error;
9517 }
9518
Johannes Berg98fc4382015-03-01 09:10:13 +02009519 /* The 'any' trigger means the device continues operating more or less
9520 * as in its normal operation mode and wakes up the host on most of the
9521 * normal interrupts (like packet RX, ...)
9522 * It therefore makes little sense to combine with the more constrained
9523 * wakeup trigger modes.
9524 */
9525 if (new_triggers.any && regular) {
9526 err = -EINVAL;
9527 goto error;
9528 }
9529
Johannes Bergae33bd82012-07-12 16:25:02 +02009530 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9531 if (!ntrig) {
9532 err = -ENOMEM;
9533 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009534 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009535 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009536 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009537
Johannes Bergae33bd82012-07-12 16:25:02 +02009538 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009539 if (rdev->ops->set_wakeup &&
9540 prev_enabled != !!rdev->wiphy.wowlan_config)
9541 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009542
Johannes Bergff1b6e62011-05-04 15:37:28 +02009543 return 0;
9544 error:
9545 for (i = 0; i < new_triggers.n_patterns; i++)
9546 kfree(new_triggers.patterns[i].mask);
9547 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009548 if (new_triggers.tcp && new_triggers.tcp->sock)
9549 sock_release(new_triggers.tcp->sock);
9550 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009551 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009552 return err;
9553}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009554#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009555
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009556static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9557 struct cfg80211_registered_device *rdev)
9558{
9559 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9560 int i, j, pat_len;
9561 struct cfg80211_coalesce_rules *rule;
9562
9563 if (!rdev->coalesce->n_rules)
9564 return 0;
9565
9566 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9567 if (!nl_rules)
9568 return -ENOBUFS;
9569
9570 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9571 nl_rule = nla_nest_start(msg, i + 1);
9572 if (!nl_rule)
9573 return -ENOBUFS;
9574
9575 rule = &rdev->coalesce->rules[i];
9576 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9577 rule->delay))
9578 return -ENOBUFS;
9579
9580 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9581 rule->condition))
9582 return -ENOBUFS;
9583
9584 nl_pats = nla_nest_start(msg,
9585 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9586 if (!nl_pats)
9587 return -ENOBUFS;
9588
9589 for (j = 0; j < rule->n_patterns; j++) {
9590 nl_pat = nla_nest_start(msg, j + 1);
9591 if (!nl_pat)
9592 return -ENOBUFS;
9593 pat_len = rule->patterns[j].pattern_len;
9594 if (nla_put(msg, NL80211_PKTPAT_MASK,
9595 DIV_ROUND_UP(pat_len, 8),
9596 rule->patterns[j].mask) ||
9597 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9598 rule->patterns[j].pattern) ||
9599 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9600 rule->patterns[j].pkt_offset))
9601 return -ENOBUFS;
9602 nla_nest_end(msg, nl_pat);
9603 }
9604 nla_nest_end(msg, nl_pats);
9605 nla_nest_end(msg, nl_rule);
9606 }
9607 nla_nest_end(msg, nl_rules);
9608
9609 return 0;
9610}
9611
9612static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9613{
9614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9615 struct sk_buff *msg;
9616 void *hdr;
9617
9618 if (!rdev->wiphy.coalesce)
9619 return -EOPNOTSUPP;
9620
9621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9622 if (!msg)
9623 return -ENOMEM;
9624
9625 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9626 NL80211_CMD_GET_COALESCE);
9627 if (!hdr)
9628 goto nla_put_failure;
9629
9630 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9631 goto nla_put_failure;
9632
9633 genlmsg_end(msg, hdr);
9634 return genlmsg_reply(msg, info);
9635
9636nla_put_failure:
9637 nlmsg_free(msg);
9638 return -ENOBUFS;
9639}
9640
9641void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9642{
9643 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9644 int i, j;
9645 struct cfg80211_coalesce_rules *rule;
9646
9647 if (!coalesce)
9648 return;
9649
9650 for (i = 0; i < coalesce->n_rules; i++) {
9651 rule = &coalesce->rules[i];
9652 for (j = 0; j < rule->n_patterns; j++)
9653 kfree(rule->patterns[j].mask);
9654 kfree(rule->patterns);
9655 }
9656 kfree(coalesce->rules);
9657 kfree(coalesce);
9658 rdev->coalesce = NULL;
9659}
9660
9661static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9662 struct nlattr *rule,
9663 struct cfg80211_coalesce_rules *new_rule)
9664{
9665 int err, i;
9666 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9667 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9668 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9669 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9670
9671 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9672 nla_len(rule), nl80211_coalesce_policy);
9673 if (err)
9674 return err;
9675
9676 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9677 new_rule->delay =
9678 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9679 if (new_rule->delay > coalesce->max_delay)
9680 return -EINVAL;
9681
9682 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9683 new_rule->condition =
9684 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9685 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9686 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9687 return -EINVAL;
9688
9689 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9690 return -EINVAL;
9691
9692 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9693 rem)
9694 n_patterns++;
9695 if (n_patterns > coalesce->n_patterns)
9696 return -EINVAL;
9697
9698 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9699 GFP_KERNEL);
9700 if (!new_rule->patterns)
9701 return -ENOMEM;
9702
9703 new_rule->n_patterns = n_patterns;
9704 i = 0;
9705
9706 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9707 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009708 u8 *mask_pat;
9709
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009710 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9711 nla_len(pat), NULL);
9712 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9713 !pat_tb[NL80211_PKTPAT_PATTERN])
9714 return -EINVAL;
9715 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9716 mask_len = DIV_ROUND_UP(pat_len, 8);
9717 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9718 return -EINVAL;
9719 if (pat_len > coalesce->pattern_max_len ||
9720 pat_len < coalesce->pattern_min_len)
9721 return -EINVAL;
9722
9723 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9724 pkt_offset = 0;
9725 else
9726 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9727 if (pkt_offset > coalesce->max_pkt_offset)
9728 return -EINVAL;
9729 new_rule->patterns[i].pkt_offset = pkt_offset;
9730
Johannes Berg922bd802014-05-19 17:59:50 +02009731 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9732 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009733 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009734
9735 new_rule->patterns[i].mask = mask_pat;
9736 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9737 mask_len);
9738
9739 mask_pat += mask_len;
9740 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009741 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009742 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9743 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009744 i++;
9745 }
9746
9747 return 0;
9748}
9749
9750static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9751{
9752 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9753 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9754 struct cfg80211_coalesce new_coalesce = {};
9755 struct cfg80211_coalesce *n_coalesce;
9756 int err, rem_rule, n_rules = 0, i, j;
9757 struct nlattr *rule;
9758 struct cfg80211_coalesce_rules *tmp_rule;
9759
9760 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9761 return -EOPNOTSUPP;
9762
9763 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9764 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +03009765 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009766 return 0;
9767 }
9768
9769 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9770 rem_rule)
9771 n_rules++;
9772 if (n_rules > coalesce->n_rules)
9773 return -EINVAL;
9774
9775 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9776 GFP_KERNEL);
9777 if (!new_coalesce.rules)
9778 return -ENOMEM;
9779
9780 new_coalesce.n_rules = n_rules;
9781 i = 0;
9782
9783 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9784 rem_rule) {
9785 err = nl80211_parse_coalesce_rule(rdev, rule,
9786 &new_coalesce.rules[i]);
9787 if (err)
9788 goto error;
9789
9790 i++;
9791 }
9792
Ilan Peera1056b12015-10-22 22:27:46 +03009793 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009794 if (err)
9795 goto error;
9796
9797 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9798 if (!n_coalesce) {
9799 err = -ENOMEM;
9800 goto error;
9801 }
9802 cfg80211_rdev_free_coalesce(rdev);
9803 rdev->coalesce = n_coalesce;
9804
9805 return 0;
9806error:
9807 for (i = 0; i < new_coalesce.n_rules; i++) {
9808 tmp_rule = &new_coalesce.rules[i];
9809 for (j = 0; j < tmp_rule->n_patterns; j++)
9810 kfree(tmp_rule->patterns[j].mask);
9811 kfree(tmp_rule->patterns);
9812 }
9813 kfree(new_coalesce.rules);
9814
9815 return err;
9816}
9817
Johannes Berge5497d72011-07-05 16:35:40 +02009818static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9819{
9820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9821 struct net_device *dev = info->user_ptr[1];
9822 struct wireless_dev *wdev = dev->ieee80211_ptr;
9823 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9824 struct cfg80211_gtk_rekey_data rekey_data;
9825 int err;
9826
9827 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9828 return -EINVAL;
9829
9830 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9831 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9832 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9833 nl80211_rekey_policy);
9834 if (err)
9835 return err;
9836
9837 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9838 return -ERANGE;
9839 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9840 return -ERANGE;
9841 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9842 return -ERANGE;
9843
Johannes Berg78f686c2014-09-10 22:28:06 +03009844 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9845 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9846 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009847
9848 wdev_lock(wdev);
9849 if (!wdev->current_bss) {
9850 err = -ENOTCONN;
9851 goto out;
9852 }
9853
9854 if (!rdev->ops->set_rekey_data) {
9855 err = -EOPNOTSUPP;
9856 goto out;
9857 }
9858
Hila Gonene35e4d22012-06-27 17:19:42 +03009859 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009860 out:
9861 wdev_unlock(wdev);
9862 return err;
9863}
9864
Johannes Berg28946da2011-11-04 11:18:12 +01009865static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9866 struct genl_info *info)
9867{
9868 struct net_device *dev = info->user_ptr[1];
9869 struct wireless_dev *wdev = dev->ieee80211_ptr;
9870
9871 if (wdev->iftype != NL80211_IFTYPE_AP &&
9872 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9873 return -EINVAL;
9874
Eric W. Biederman15e47302012-09-07 20:12:54 +00009875 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009876 return -EBUSY;
9877
Eric W. Biederman15e47302012-09-07 20:12:54 +00009878 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009879 return 0;
9880}
9881
Johannes Berg7f6cf312011-11-04 11:18:15 +01009882static int nl80211_probe_client(struct sk_buff *skb,
9883 struct genl_info *info)
9884{
9885 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9886 struct net_device *dev = info->user_ptr[1];
9887 struct wireless_dev *wdev = dev->ieee80211_ptr;
9888 struct sk_buff *msg;
9889 void *hdr;
9890 const u8 *addr;
9891 u64 cookie;
9892 int err;
9893
9894 if (wdev->iftype != NL80211_IFTYPE_AP &&
9895 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9896 return -EOPNOTSUPP;
9897
9898 if (!info->attrs[NL80211_ATTR_MAC])
9899 return -EINVAL;
9900
9901 if (!rdev->ops->probe_client)
9902 return -EOPNOTSUPP;
9903
9904 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9905 if (!msg)
9906 return -ENOMEM;
9907
Eric W. Biederman15e47302012-09-07 20:12:54 +00009908 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009909 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009910 if (!hdr) {
9911 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009912 goto free_msg;
9913 }
9914
9915 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9916
Hila Gonene35e4d22012-06-27 17:19:42 +03009917 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009918 if (err)
9919 goto free_msg;
9920
David S. Miller9360ffd2012-03-29 04:41:26 -04009921 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9922 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009923
9924 genlmsg_end(msg, hdr);
9925
9926 return genlmsg_reply(msg, info);
9927
9928 nla_put_failure:
9929 err = -ENOBUFS;
9930 free_msg:
9931 nlmsg_free(msg);
9932 return err;
9933}
9934
Johannes Berg5e760232011-11-04 11:18:17 +01009935static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9936{
9937 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009938 struct cfg80211_beacon_registration *reg, *nreg;
9939 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009940
9941 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9942 return -EOPNOTSUPP;
9943
Ben Greear37c73b52012-10-26 14:49:25 -07009944 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9945 if (!nreg)
9946 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009947
Ben Greear37c73b52012-10-26 14:49:25 -07009948 /* First, check if already registered. */
9949 spin_lock_bh(&rdev->beacon_registrations_lock);
9950 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9951 if (reg->nlportid == info->snd_portid) {
9952 rv = -EALREADY;
9953 goto out_err;
9954 }
9955 }
9956 /* Add it to the list */
9957 nreg->nlportid = info->snd_portid;
9958 list_add(&nreg->list, &rdev->beacon_registrations);
9959
9960 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009961
9962 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009963out_err:
9964 spin_unlock_bh(&rdev->beacon_registrations_lock);
9965 kfree(nreg);
9966 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009967}
9968
Johannes Berg98104fde2012-06-16 00:19:54 +02009969static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9970{
9971 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9972 struct wireless_dev *wdev = info->user_ptr[1];
9973 int err;
9974
9975 if (!rdev->ops->start_p2p_device)
9976 return -EOPNOTSUPP;
9977
9978 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9979 return -EOPNOTSUPP;
9980
9981 if (wdev->p2p_started)
9982 return 0;
9983
Luciano Coelhob6a55012014-02-27 11:07:21 +02009984 if (rfkill_blocked(rdev->rfkill))
9985 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009986
Johannes Bergeeb126e2012-10-23 15:16:50 +02009987 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009988 if (err)
9989 return err;
9990
9991 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009992 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009993
9994 return 0;
9995}
9996
9997static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9998{
9999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10000 struct wireless_dev *wdev = info->user_ptr[1];
10001
10002 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10003 return -EOPNOTSUPP;
10004
10005 if (!rdev->ops->stop_p2p_device)
10006 return -EOPNOTSUPP;
10007
Johannes Bergf9f47522013-03-19 15:04:07 +010010008 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010009
10010 return 0;
10011}
10012
Johannes Berg3713b4e2013-02-14 16:19:38 +010010013static int nl80211_get_protocol_features(struct sk_buff *skb,
10014 struct genl_info *info)
10015{
10016 void *hdr;
10017 struct sk_buff *msg;
10018
10019 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10020 if (!msg)
10021 return -ENOMEM;
10022
10023 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10024 NL80211_CMD_GET_PROTOCOL_FEATURES);
10025 if (!hdr)
10026 goto nla_put_failure;
10027
10028 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10029 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10030 goto nla_put_failure;
10031
10032 genlmsg_end(msg, hdr);
10033 return genlmsg_reply(msg, info);
10034
10035 nla_put_failure:
10036 kfree_skb(msg);
10037 return -ENOBUFS;
10038}
10039
Jouni Malinen355199e2013-02-27 17:14:27 +020010040static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10041{
10042 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10043 struct cfg80211_update_ft_ies_params ft_params;
10044 struct net_device *dev = info->user_ptr[1];
10045
10046 if (!rdev->ops->update_ft_ies)
10047 return -EOPNOTSUPP;
10048
10049 if (!info->attrs[NL80211_ATTR_MDID] ||
10050 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10051 return -EINVAL;
10052
10053 memset(&ft_params, 0, sizeof(ft_params));
10054 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10055 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10056 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10057
10058 return rdev_update_ft_ies(rdev, dev, &ft_params);
10059}
10060
Arend van Spriel5de17982013-04-18 15:49:00 +020010061static int nl80211_crit_protocol_start(struct sk_buff *skb,
10062 struct genl_info *info)
10063{
10064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10065 struct wireless_dev *wdev = info->user_ptr[1];
10066 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10067 u16 duration;
10068 int ret;
10069
10070 if (!rdev->ops->crit_proto_start)
10071 return -EOPNOTSUPP;
10072
10073 if (WARN_ON(!rdev->ops->crit_proto_stop))
10074 return -EINVAL;
10075
10076 if (rdev->crit_proto_nlportid)
10077 return -EBUSY;
10078
10079 /* determine protocol if provided */
10080 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10081 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10082
10083 if (proto >= NUM_NL80211_CRIT_PROTO)
10084 return -EINVAL;
10085
10086 /* timeout must be provided */
10087 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10088 return -EINVAL;
10089
10090 duration =
10091 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10092
10093 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10094 return -ERANGE;
10095
10096 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10097 if (!ret)
10098 rdev->crit_proto_nlportid = info->snd_portid;
10099
10100 return ret;
10101}
10102
10103static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10104 struct genl_info *info)
10105{
10106 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10107 struct wireless_dev *wdev = info->user_ptr[1];
10108
10109 if (!rdev->ops->crit_proto_stop)
10110 return -EOPNOTSUPP;
10111
10112 if (rdev->crit_proto_nlportid) {
10113 rdev->crit_proto_nlportid = 0;
10114 rdev_crit_proto_stop(rdev, wdev);
10115 }
10116 return 0;
10117}
10118
Johannes Bergad7e7182013-11-13 13:37:47 +010010119static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10120{
10121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10122 struct wireless_dev *wdev =
10123 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10124 int i, err;
10125 u32 vid, subcmd;
10126
10127 if (!rdev->wiphy.vendor_commands)
10128 return -EOPNOTSUPP;
10129
10130 if (IS_ERR(wdev)) {
10131 err = PTR_ERR(wdev);
10132 if (err != -EINVAL)
10133 return err;
10134 wdev = NULL;
10135 } else if (wdev->wiphy != &rdev->wiphy) {
10136 return -EINVAL;
10137 }
10138
10139 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10140 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10141 return -EINVAL;
10142
10143 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10144 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10145 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10146 const struct wiphy_vendor_command *vcmd;
10147 void *data = NULL;
10148 int len = 0;
10149
10150 vcmd = &rdev->wiphy.vendor_commands[i];
10151
10152 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10153 continue;
10154
10155 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10156 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10157 if (!wdev)
10158 return -EINVAL;
10159 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10160 !wdev->netdev)
10161 return -EINVAL;
10162
10163 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10164 if (wdev->netdev &&
10165 !netif_running(wdev->netdev))
10166 return -ENETDOWN;
10167 if (!wdev->netdev && !wdev->p2p_started)
10168 return -ENETDOWN;
10169 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010170
10171 if (!vcmd->doit)
10172 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010173 } else {
10174 wdev = NULL;
10175 }
10176
10177 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10178 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10179 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10180 }
10181
10182 rdev->cur_cmd_info = info;
10183 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10184 data, len);
10185 rdev->cur_cmd_info = NULL;
10186 return err;
10187 }
10188
10189 return -EOPNOTSUPP;
10190}
10191
Johannes Berg7bdbe402015-08-15 22:39:49 +030010192static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10193 struct netlink_callback *cb,
10194 struct cfg80211_registered_device **rdev,
10195 struct wireless_dev **wdev)
10196{
10197 u32 vid, subcmd;
10198 unsigned int i;
10199 int vcmd_idx = -1;
10200 int err;
10201 void *data = NULL;
10202 unsigned int data_len = 0;
10203
10204 rtnl_lock();
10205
10206 if (cb->args[0]) {
10207 /* subtract the 1 again here */
10208 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10209 struct wireless_dev *tmp;
10210
10211 if (!wiphy) {
10212 err = -ENODEV;
10213 goto out_unlock;
10214 }
10215 *rdev = wiphy_to_rdev(wiphy);
10216 *wdev = NULL;
10217
10218 if (cb->args[1]) {
10219 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
10220 if (tmp->identifier == cb->args[1] - 1) {
10221 *wdev = tmp;
10222 break;
10223 }
10224 }
10225 }
10226
10227 /* keep rtnl locked in successful case */
10228 return 0;
10229 }
10230
10231 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10232 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10233 nl80211_policy);
10234 if (err)
10235 goto out_unlock;
10236
10237 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10238 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10239 err = -EINVAL;
10240 goto out_unlock;
10241 }
10242
10243 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10244 nl80211_fam.attrbuf);
10245 if (IS_ERR(*wdev))
10246 *wdev = NULL;
10247
10248 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10249 nl80211_fam.attrbuf);
10250 if (IS_ERR(*rdev)) {
10251 err = PTR_ERR(*rdev);
10252 goto out_unlock;
10253 }
10254
10255 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10256 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10257
10258 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10259 const struct wiphy_vendor_command *vcmd;
10260
10261 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10262
10263 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10264 continue;
10265
10266 if (!vcmd->dumpit) {
10267 err = -EOPNOTSUPP;
10268 goto out_unlock;
10269 }
10270
10271 vcmd_idx = i;
10272 break;
10273 }
10274
10275 if (vcmd_idx < 0) {
10276 err = -EOPNOTSUPP;
10277 goto out_unlock;
10278 }
10279
10280 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10281 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10282 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10283 }
10284
10285 /* 0 is the first index - add 1 to parse only once */
10286 cb->args[0] = (*rdev)->wiphy_idx + 1;
10287 /* add 1 to know if it was NULL */
10288 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10289 cb->args[2] = vcmd_idx;
10290 cb->args[3] = (unsigned long)data;
10291 cb->args[4] = data_len;
10292
10293 /* keep rtnl locked in successful case */
10294 return 0;
10295 out_unlock:
10296 rtnl_unlock();
10297 return err;
10298}
10299
10300static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10301 struct netlink_callback *cb)
10302{
10303 struct cfg80211_registered_device *rdev;
10304 struct wireless_dev *wdev;
10305 unsigned int vcmd_idx;
10306 const struct wiphy_vendor_command *vcmd;
10307 void *data;
10308 int data_len;
10309 int err;
10310 struct nlattr *vendor_data;
10311
10312 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10313 if (err)
10314 return err;
10315
10316 vcmd_idx = cb->args[2];
10317 data = (void *)cb->args[3];
10318 data_len = cb->args[4];
10319 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10320
10321 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10322 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10323 if (!wdev)
10324 return -EINVAL;
10325 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10326 !wdev->netdev)
10327 return -EINVAL;
10328
10329 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10330 if (wdev->netdev &&
10331 !netif_running(wdev->netdev))
10332 return -ENETDOWN;
10333 if (!wdev->netdev && !wdev->p2p_started)
10334 return -ENETDOWN;
10335 }
10336 }
10337
10338 while (1) {
10339 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10340 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10341 NL80211_CMD_VENDOR);
10342 if (!hdr)
10343 break;
10344
10345 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10346 (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV,
10347 wdev_id(wdev)))) {
10348 genlmsg_cancel(skb, hdr);
10349 break;
10350 }
10351
10352 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10353 if (!vendor_data) {
10354 genlmsg_cancel(skb, hdr);
10355 break;
10356 }
10357
10358 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10359 (unsigned long *)&cb->args[5]);
10360 nla_nest_end(skb, vendor_data);
10361
10362 if (err == -ENOBUFS || err == -ENOENT) {
10363 genlmsg_cancel(skb, hdr);
10364 break;
10365 } else if (err) {
10366 genlmsg_cancel(skb, hdr);
10367 goto out;
10368 }
10369
10370 genlmsg_end(skb, hdr);
10371 }
10372
10373 err = skb->len;
10374 out:
10375 rtnl_unlock();
10376 return err;
10377}
10378
Johannes Bergad7e7182013-11-13 13:37:47 +010010379struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10380 enum nl80211_commands cmd,
10381 enum nl80211_attrs attr,
10382 int approxlen)
10383{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010384 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010385
10386 if (WARN_ON(!rdev->cur_cmd_info))
10387 return NULL;
10388
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010389 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010390 rdev->cur_cmd_info->snd_portid,
10391 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010392 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010393}
10394EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10395
10396int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10397{
10398 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10399 void *hdr = ((void **)skb->cb)[1];
10400 struct nlattr *data = ((void **)skb->cb)[2];
10401
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010402 /* clear CB data for netlink core to own from now on */
10403 memset(skb->cb, 0, sizeof(skb->cb));
10404
Johannes Bergad7e7182013-11-13 13:37:47 +010010405 if (WARN_ON(!rdev->cur_cmd_info)) {
10406 kfree_skb(skb);
10407 return -EINVAL;
10408 }
10409
10410 nla_nest_end(skb, data);
10411 genlmsg_end(skb, hdr);
10412 return genlmsg_reply(skb, rdev->cur_cmd_info);
10413}
10414EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10415
10416
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010417static int nl80211_set_qos_map(struct sk_buff *skb,
10418 struct genl_info *info)
10419{
10420 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10421 struct cfg80211_qos_map *qos_map = NULL;
10422 struct net_device *dev = info->user_ptr[1];
10423 u8 *pos, len, num_des, des_len, des;
10424 int ret;
10425
10426 if (!rdev->ops->set_qos_map)
10427 return -EOPNOTSUPP;
10428
10429 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10430 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10431 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10432
10433 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10434 len > IEEE80211_QOS_MAP_LEN_MAX)
10435 return -EINVAL;
10436
10437 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10438 if (!qos_map)
10439 return -ENOMEM;
10440
10441 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10442 if (num_des) {
10443 des_len = num_des *
10444 sizeof(struct cfg80211_dscp_exception);
10445 memcpy(qos_map->dscp_exception, pos, des_len);
10446 qos_map->num_des = num_des;
10447 for (des = 0; des < num_des; des++) {
10448 if (qos_map->dscp_exception[des].up > 7) {
10449 kfree(qos_map);
10450 return -EINVAL;
10451 }
10452 }
10453 pos += des_len;
10454 }
10455 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10456 }
10457
10458 wdev_lock(dev->ieee80211_ptr);
10459 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10460 if (!ret)
10461 ret = rdev_set_qos_map(rdev, dev, qos_map);
10462 wdev_unlock(dev->ieee80211_ptr);
10463
10464 kfree(qos_map);
10465 return ret;
10466}
10467
Johannes Berg960d01a2014-09-09 22:55:35 +030010468static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10469{
10470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10471 struct net_device *dev = info->user_ptr[1];
10472 struct wireless_dev *wdev = dev->ieee80211_ptr;
10473 const u8 *peer;
10474 u8 tsid, up;
10475 u16 admitted_time = 0;
10476 int err;
10477
Johannes Berg723e73a2014-10-22 09:25:06 +020010478 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010479 return -EOPNOTSUPP;
10480
10481 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10482 !info->attrs[NL80211_ATTR_USER_PRIO])
10483 return -EINVAL;
10484
10485 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10486 if (tsid >= IEEE80211_NUM_TIDS)
10487 return -EINVAL;
10488
10489 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10490 if (up >= IEEE80211_NUM_UPS)
10491 return -EINVAL;
10492
10493 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010494 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010495 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010496 * need more attributes for that (e.g. BA session requirement);
10497 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010498 */
10499 return -EINVAL;
10500 }
10501
10502 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10503
10504 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10505 admitted_time =
10506 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10507 if (!admitted_time)
10508 return -EINVAL;
10509 }
10510
10511 wdev_lock(wdev);
10512 switch (wdev->iftype) {
10513 case NL80211_IFTYPE_STATION:
10514 case NL80211_IFTYPE_P2P_CLIENT:
10515 if (wdev->current_bss)
10516 break;
10517 err = -ENOTCONN;
10518 goto out;
10519 default:
10520 err = -EOPNOTSUPP;
10521 goto out;
10522 }
10523
10524 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10525
10526 out:
10527 wdev_unlock(wdev);
10528 return err;
10529}
10530
10531static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10532{
10533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10534 struct net_device *dev = info->user_ptr[1];
10535 struct wireless_dev *wdev = dev->ieee80211_ptr;
10536 const u8 *peer;
10537 u8 tsid;
10538 int err;
10539
10540 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10541 return -EINVAL;
10542
10543 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10544 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10545
10546 wdev_lock(wdev);
10547 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10548 wdev_unlock(wdev);
10549
10550 return err;
10551}
10552
Arik Nemtsov1057d352014-11-19 12:54:26 +020010553static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10554 struct genl_info *info)
10555{
10556 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10557 struct net_device *dev = info->user_ptr[1];
10558 struct wireless_dev *wdev = dev->ieee80211_ptr;
10559 struct cfg80211_chan_def chandef = {};
10560 const u8 *addr;
10561 u8 oper_class;
10562 int err;
10563
10564 if (!rdev->ops->tdls_channel_switch ||
10565 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10566 return -EOPNOTSUPP;
10567
10568 switch (dev->ieee80211_ptr->iftype) {
10569 case NL80211_IFTYPE_STATION:
10570 case NL80211_IFTYPE_P2P_CLIENT:
10571 break;
10572 default:
10573 return -EOPNOTSUPP;
10574 }
10575
10576 if (!info->attrs[NL80211_ATTR_MAC] ||
10577 !info->attrs[NL80211_ATTR_OPER_CLASS])
10578 return -EINVAL;
10579
10580 err = nl80211_parse_chandef(rdev, info, &chandef);
10581 if (err)
10582 return err;
10583
10584 /*
10585 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10586 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10587 * specification is not defined for them.
10588 */
10589 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10590 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10591 chandef.width != NL80211_CHAN_WIDTH_20)
10592 return -EINVAL;
10593
10594 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010595 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10596 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010597 return -EINVAL;
10598
10599 /* don't allow switching to DFS channels */
10600 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10601 return -EINVAL;
10602
10603 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10604 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10605
10606 wdev_lock(wdev);
10607 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10608 wdev_unlock(wdev);
10609
10610 return err;
10611}
10612
10613static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10614 struct genl_info *info)
10615{
10616 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10617 struct net_device *dev = info->user_ptr[1];
10618 struct wireless_dev *wdev = dev->ieee80211_ptr;
10619 const u8 *addr;
10620
10621 if (!rdev->ops->tdls_channel_switch ||
10622 !rdev->ops->tdls_cancel_channel_switch ||
10623 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10624 return -EOPNOTSUPP;
10625
10626 switch (dev->ieee80211_ptr->iftype) {
10627 case NL80211_IFTYPE_STATION:
10628 case NL80211_IFTYPE_P2P_CLIENT:
10629 break;
10630 default:
10631 return -EOPNOTSUPP;
10632 }
10633
10634 if (!info->attrs[NL80211_ATTR_MAC])
10635 return -EINVAL;
10636
10637 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10638
10639 wdev_lock(wdev);
10640 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10641 wdev_unlock(wdev);
10642
10643 return 0;
10644}
10645
Johannes Berg4c476992010-10-04 21:36:35 +020010646#define NL80211_FLAG_NEED_WIPHY 0x01
10647#define NL80211_FLAG_NEED_NETDEV 0x02
10648#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010649#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10650#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10651 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010652#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010653/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010654#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10655 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010656#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010657
Johannes Bergf84f7712013-11-14 17:14:45 +010010658static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010659 struct genl_info *info)
10660{
10661 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010662 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010663 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010664 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10665
10666 if (rtnl)
10667 rtnl_lock();
10668
10669 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010670 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010671 if (IS_ERR(rdev)) {
10672 if (rtnl)
10673 rtnl_unlock();
10674 return PTR_ERR(rdev);
10675 }
10676 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010677 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10678 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010679 ASSERT_RTNL();
10680
Johannes Berg89a54e42012-06-15 14:33:17 +020010681 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10682 info->attrs);
10683 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010684 if (rtnl)
10685 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010686 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010687 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010688
Johannes Berg89a54e42012-06-15 14:33:17 +020010689 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010690 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010691
Johannes Berg1bf614e2012-06-15 15:23:36 +020010692 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10693 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010694 if (rtnl)
10695 rtnl_unlock();
10696 return -EINVAL;
10697 }
10698
10699 info->user_ptr[1] = dev;
10700 } else {
10701 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010702 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010703
Johannes Berg1bf614e2012-06-15 15:23:36 +020010704 if (dev) {
10705 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10706 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010707 if (rtnl)
10708 rtnl_unlock();
10709 return -ENETDOWN;
10710 }
10711
10712 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010713 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10714 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010715 if (rtnl)
10716 rtnl_unlock();
10717 return -ENETDOWN;
10718 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010719 }
10720
Johannes Berg4c476992010-10-04 21:36:35 +020010721 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010722 }
10723
10724 return 0;
10725}
10726
Johannes Bergf84f7712013-11-14 17:14:45 +010010727static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010728 struct genl_info *info)
10729{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010730 if (info->user_ptr[1]) {
10731 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10732 struct wireless_dev *wdev = info->user_ptr[1];
10733
10734 if (wdev->netdev)
10735 dev_put(wdev->netdev);
10736 } else {
10737 dev_put(info->user_ptr[1]);
10738 }
10739 }
Johannes Berg5393b912014-09-10 15:00:16 +030010740
Johannes Berg4c476992010-10-04 21:36:35 +020010741 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10742 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010743
10744 /* If needed, clear the netlink message payload from the SKB
10745 * as it might contain key data that shouldn't stick around on
10746 * the heap after the SKB is freed. The netlink message header
10747 * is still needed for further processing, so leave it intact.
10748 */
10749 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10750 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10751
10752 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10753 }
Johannes Berg4c476992010-10-04 21:36:35 +020010754}
10755
Johannes Berg4534de82013-11-14 17:14:46 +010010756static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010757 {
10758 .cmd = NL80211_CMD_GET_WIPHY,
10759 .doit = nl80211_get_wiphy,
10760 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010761 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010762 .policy = nl80211_policy,
10763 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010764 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10765 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010766 },
10767 {
10768 .cmd = NL80211_CMD_SET_WIPHY,
10769 .doit = nl80211_set_wiphy,
10770 .policy = nl80211_policy,
10771 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010772 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010773 },
10774 {
10775 .cmd = NL80211_CMD_GET_INTERFACE,
10776 .doit = nl80211_get_interface,
10777 .dumpit = nl80211_dump_interface,
10778 .policy = nl80211_policy,
10779 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010780 .internal_flags = NL80211_FLAG_NEED_WDEV |
10781 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010782 },
10783 {
10784 .cmd = NL80211_CMD_SET_INTERFACE,
10785 .doit = nl80211_set_interface,
10786 .policy = nl80211_policy,
10787 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010788 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10789 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010790 },
10791 {
10792 .cmd = NL80211_CMD_NEW_INTERFACE,
10793 .doit = nl80211_new_interface,
10794 .policy = nl80211_policy,
10795 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010796 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10797 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010798 },
10799 {
10800 .cmd = NL80211_CMD_DEL_INTERFACE,
10801 .doit = nl80211_del_interface,
10802 .policy = nl80211_policy,
10803 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010804 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010805 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010806 },
Johannes Berg41ade002007-12-19 02:03:29 +010010807 {
10808 .cmd = NL80211_CMD_GET_KEY,
10809 .doit = nl80211_get_key,
10810 .policy = nl80211_policy,
10811 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010812 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010813 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010814 },
10815 {
10816 .cmd = NL80211_CMD_SET_KEY,
10817 .doit = nl80211_set_key,
10818 .policy = nl80211_policy,
10819 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010820 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010821 NL80211_FLAG_NEED_RTNL |
10822 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010823 },
10824 {
10825 .cmd = NL80211_CMD_NEW_KEY,
10826 .doit = nl80211_new_key,
10827 .policy = nl80211_policy,
10828 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010829 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010830 NL80211_FLAG_NEED_RTNL |
10831 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010832 },
10833 {
10834 .cmd = NL80211_CMD_DEL_KEY,
10835 .doit = nl80211_del_key,
10836 .policy = nl80211_policy,
10837 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010838 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010839 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010840 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010841 {
10842 .cmd = NL80211_CMD_SET_BEACON,
10843 .policy = nl80211_policy,
10844 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010845 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010846 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010847 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010848 },
10849 {
Johannes Berg88600202012-02-13 15:17:18 +010010850 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010851 .policy = nl80211_policy,
10852 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010853 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010854 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010855 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010856 },
10857 {
Johannes Berg88600202012-02-13 15:17:18 +010010858 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010859 .policy = nl80211_policy,
10860 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010861 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010862 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010863 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010864 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010865 {
10866 .cmd = NL80211_CMD_GET_STATION,
10867 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010868 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010869 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010870 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10871 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010872 },
10873 {
10874 .cmd = NL80211_CMD_SET_STATION,
10875 .doit = nl80211_set_station,
10876 .policy = nl80211_policy,
10877 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010878 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010879 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010880 },
10881 {
10882 .cmd = NL80211_CMD_NEW_STATION,
10883 .doit = nl80211_new_station,
10884 .policy = nl80211_policy,
10885 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010886 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010887 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010888 },
10889 {
10890 .cmd = NL80211_CMD_DEL_STATION,
10891 .doit = nl80211_del_station,
10892 .policy = nl80211_policy,
10893 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010894 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010895 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010896 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010897 {
10898 .cmd = NL80211_CMD_GET_MPATH,
10899 .doit = nl80211_get_mpath,
10900 .dumpit = nl80211_dump_mpath,
10901 .policy = nl80211_policy,
10902 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010903 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010904 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010905 },
10906 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010907 .cmd = NL80211_CMD_GET_MPP,
10908 .doit = nl80211_get_mpp,
10909 .dumpit = nl80211_dump_mpp,
10910 .policy = nl80211_policy,
10911 .flags = GENL_ADMIN_PERM,
10912 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10913 NL80211_FLAG_NEED_RTNL,
10914 },
10915 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010916 .cmd = NL80211_CMD_SET_MPATH,
10917 .doit = nl80211_set_mpath,
10918 .policy = nl80211_policy,
10919 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010920 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010921 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010922 },
10923 {
10924 .cmd = NL80211_CMD_NEW_MPATH,
10925 .doit = nl80211_new_mpath,
10926 .policy = nl80211_policy,
10927 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010928 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010929 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010930 },
10931 {
10932 .cmd = NL80211_CMD_DEL_MPATH,
10933 .doit = nl80211_del_mpath,
10934 .policy = nl80211_policy,
10935 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010936 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010937 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010938 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010939 {
10940 .cmd = NL80211_CMD_SET_BSS,
10941 .doit = nl80211_set_bss,
10942 .policy = nl80211_policy,
10943 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010944 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010945 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010946 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010947 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010948 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010949 .doit = nl80211_get_reg_do,
10950 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010951 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010952 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010953 /* can be retrieved by unprivileged users */
10954 },
Johannes Bergb6863032015-10-15 09:25:18 +020010955#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010956 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010957 .cmd = NL80211_CMD_SET_REG,
10958 .doit = nl80211_set_reg,
10959 .policy = nl80211_policy,
10960 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010961 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010962 },
Johannes Bergb6863032015-10-15 09:25:18 +020010963#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010964 {
10965 .cmd = NL80211_CMD_REQ_SET_REG,
10966 .doit = nl80211_req_set_reg,
10967 .policy = nl80211_policy,
10968 .flags = GENL_ADMIN_PERM,
10969 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010970 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010971 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10972 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010973 .policy = nl80211_policy,
10974 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010976 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010977 },
10978 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010979 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10980 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010981 .policy = nl80211_policy,
10982 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010983 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010984 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010985 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010986 {
Johannes Berg2a519312009-02-10 21:25:55 +010010987 .cmd = NL80211_CMD_TRIGGER_SCAN,
10988 .doit = nl80211_trigger_scan,
10989 .policy = nl80211_policy,
10990 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010991 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010992 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010993 },
10994 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053010995 .cmd = NL80211_CMD_ABORT_SCAN,
10996 .doit = nl80211_abort_scan,
10997 .policy = nl80211_policy,
10998 .flags = GENL_ADMIN_PERM,
10999 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11000 NL80211_FLAG_NEED_RTNL,
11001 },
11002 {
Johannes Berg2a519312009-02-10 21:25:55 +010011003 .cmd = NL80211_CMD_GET_SCAN,
11004 .policy = nl80211_policy,
11005 .dumpit = nl80211_dump_scan,
11006 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011007 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011008 .cmd = NL80211_CMD_START_SCHED_SCAN,
11009 .doit = nl80211_start_sched_scan,
11010 .policy = nl80211_policy,
11011 .flags = GENL_ADMIN_PERM,
11012 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11013 NL80211_FLAG_NEED_RTNL,
11014 },
11015 {
11016 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11017 .doit = nl80211_stop_sched_scan,
11018 .policy = nl80211_policy,
11019 .flags = GENL_ADMIN_PERM,
11020 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11021 NL80211_FLAG_NEED_RTNL,
11022 },
11023 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011024 .cmd = NL80211_CMD_AUTHENTICATE,
11025 .doit = nl80211_authenticate,
11026 .policy = nl80211_policy,
11027 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011028 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011029 NL80211_FLAG_NEED_RTNL |
11030 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011031 },
11032 {
11033 .cmd = NL80211_CMD_ASSOCIATE,
11034 .doit = nl80211_associate,
11035 .policy = nl80211_policy,
11036 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011037 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011038 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011039 },
11040 {
11041 .cmd = NL80211_CMD_DEAUTHENTICATE,
11042 .doit = nl80211_deauthenticate,
11043 .policy = nl80211_policy,
11044 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011045 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011046 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011047 },
11048 {
11049 .cmd = NL80211_CMD_DISASSOCIATE,
11050 .doit = nl80211_disassociate,
11051 .policy = nl80211_policy,
11052 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011053 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011054 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011055 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011056 {
11057 .cmd = NL80211_CMD_JOIN_IBSS,
11058 .doit = nl80211_join_ibss,
11059 .policy = nl80211_policy,
11060 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011061 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011062 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011063 },
11064 {
11065 .cmd = NL80211_CMD_LEAVE_IBSS,
11066 .doit = nl80211_leave_ibss,
11067 .policy = nl80211_policy,
11068 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011069 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011070 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011071 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011072#ifdef CONFIG_NL80211_TESTMODE
11073 {
11074 .cmd = NL80211_CMD_TESTMODE,
11075 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011076 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011077 .policy = nl80211_policy,
11078 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011079 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11080 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011081 },
11082#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011083 {
11084 .cmd = NL80211_CMD_CONNECT,
11085 .doit = nl80211_connect,
11086 .policy = nl80211_policy,
11087 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011088 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011089 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011090 },
11091 {
11092 .cmd = NL80211_CMD_DISCONNECT,
11093 .doit = nl80211_disconnect,
11094 .policy = nl80211_policy,
11095 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011096 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011097 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011098 },
Johannes Berg463d0182009-07-14 00:33:35 +020011099 {
11100 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11101 .doit = nl80211_wiphy_netns,
11102 .policy = nl80211_policy,
11103 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011104 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11105 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011106 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011107 {
11108 .cmd = NL80211_CMD_GET_SURVEY,
11109 .policy = nl80211_policy,
11110 .dumpit = nl80211_dump_survey,
11111 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011112 {
11113 .cmd = NL80211_CMD_SET_PMKSA,
11114 .doit = nl80211_setdel_pmksa,
11115 .policy = nl80211_policy,
11116 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011117 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011118 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011119 },
11120 {
11121 .cmd = NL80211_CMD_DEL_PMKSA,
11122 .doit = nl80211_setdel_pmksa,
11123 .policy = nl80211_policy,
11124 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011125 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011126 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011127 },
11128 {
11129 .cmd = NL80211_CMD_FLUSH_PMKSA,
11130 .doit = nl80211_flush_pmksa,
11131 .policy = nl80211_policy,
11132 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011133 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011134 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011135 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011136 {
11137 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11138 .doit = nl80211_remain_on_channel,
11139 .policy = nl80211_policy,
11140 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011141 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011142 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011143 },
11144 {
11145 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11146 .doit = nl80211_cancel_remain_on_channel,
11147 .policy = nl80211_policy,
11148 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011149 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011150 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011151 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011152 {
11153 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11154 .doit = nl80211_set_tx_bitrate_mask,
11155 .policy = nl80211_policy,
11156 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011157 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11158 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011159 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011160 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011161 .cmd = NL80211_CMD_REGISTER_FRAME,
11162 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011163 .policy = nl80211_policy,
11164 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011165 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011166 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011167 },
11168 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011169 .cmd = NL80211_CMD_FRAME,
11170 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011171 .policy = nl80211_policy,
11172 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011173 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011174 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011175 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011176 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011177 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11178 .doit = nl80211_tx_mgmt_cancel_wait,
11179 .policy = nl80211_policy,
11180 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011181 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011182 NL80211_FLAG_NEED_RTNL,
11183 },
11184 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011185 .cmd = NL80211_CMD_SET_POWER_SAVE,
11186 .doit = nl80211_set_power_save,
11187 .policy = nl80211_policy,
11188 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011189 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11190 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011191 },
11192 {
11193 .cmd = NL80211_CMD_GET_POWER_SAVE,
11194 .doit = nl80211_get_power_save,
11195 .policy = nl80211_policy,
11196 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011197 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11198 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011199 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011200 {
11201 .cmd = NL80211_CMD_SET_CQM,
11202 .doit = nl80211_set_cqm,
11203 .policy = nl80211_policy,
11204 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011205 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11206 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011207 },
Johannes Bergf444de02010-05-05 15:25:02 +020011208 {
11209 .cmd = NL80211_CMD_SET_CHANNEL,
11210 .doit = nl80211_set_channel,
11211 .policy = nl80211_policy,
11212 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011213 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11214 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011215 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011216 {
11217 .cmd = NL80211_CMD_SET_WDS_PEER,
11218 .doit = nl80211_set_wds_peer,
11219 .policy = nl80211_policy,
11220 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011221 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11222 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011223 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011224 {
11225 .cmd = NL80211_CMD_JOIN_MESH,
11226 .doit = nl80211_join_mesh,
11227 .policy = nl80211_policy,
11228 .flags = GENL_ADMIN_PERM,
11229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11230 NL80211_FLAG_NEED_RTNL,
11231 },
11232 {
11233 .cmd = NL80211_CMD_LEAVE_MESH,
11234 .doit = nl80211_leave_mesh,
11235 .policy = nl80211_policy,
11236 .flags = GENL_ADMIN_PERM,
11237 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11238 NL80211_FLAG_NEED_RTNL,
11239 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011240 {
11241 .cmd = NL80211_CMD_JOIN_OCB,
11242 .doit = nl80211_join_ocb,
11243 .policy = nl80211_policy,
11244 .flags = GENL_ADMIN_PERM,
11245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11246 NL80211_FLAG_NEED_RTNL,
11247 },
11248 {
11249 .cmd = NL80211_CMD_LEAVE_OCB,
11250 .doit = nl80211_leave_ocb,
11251 .policy = nl80211_policy,
11252 .flags = GENL_ADMIN_PERM,
11253 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11254 NL80211_FLAG_NEED_RTNL,
11255 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011256#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011257 {
11258 .cmd = NL80211_CMD_GET_WOWLAN,
11259 .doit = nl80211_get_wowlan,
11260 .policy = nl80211_policy,
11261 /* can be retrieved by unprivileged users */
11262 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11263 NL80211_FLAG_NEED_RTNL,
11264 },
11265 {
11266 .cmd = NL80211_CMD_SET_WOWLAN,
11267 .doit = nl80211_set_wowlan,
11268 .policy = nl80211_policy,
11269 .flags = GENL_ADMIN_PERM,
11270 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11271 NL80211_FLAG_NEED_RTNL,
11272 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011273#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011274 {
11275 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11276 .doit = nl80211_set_rekey_data,
11277 .policy = nl80211_policy,
11278 .flags = GENL_ADMIN_PERM,
11279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011280 NL80211_FLAG_NEED_RTNL |
11281 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011282 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011283 {
11284 .cmd = NL80211_CMD_TDLS_MGMT,
11285 .doit = nl80211_tdls_mgmt,
11286 .policy = nl80211_policy,
11287 .flags = GENL_ADMIN_PERM,
11288 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11289 NL80211_FLAG_NEED_RTNL,
11290 },
11291 {
11292 .cmd = NL80211_CMD_TDLS_OPER,
11293 .doit = nl80211_tdls_oper,
11294 .policy = nl80211_policy,
11295 .flags = GENL_ADMIN_PERM,
11296 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11297 NL80211_FLAG_NEED_RTNL,
11298 },
Johannes Berg28946da2011-11-04 11:18:12 +010011299 {
11300 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11301 .doit = nl80211_register_unexpected_frame,
11302 .policy = nl80211_policy,
11303 .flags = GENL_ADMIN_PERM,
11304 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11305 NL80211_FLAG_NEED_RTNL,
11306 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011307 {
11308 .cmd = NL80211_CMD_PROBE_CLIENT,
11309 .doit = nl80211_probe_client,
11310 .policy = nl80211_policy,
11311 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011312 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011313 NL80211_FLAG_NEED_RTNL,
11314 },
Johannes Berg5e760232011-11-04 11:18:17 +010011315 {
11316 .cmd = NL80211_CMD_REGISTER_BEACONS,
11317 .doit = nl80211_register_beacons,
11318 .policy = nl80211_policy,
11319 .flags = GENL_ADMIN_PERM,
11320 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11321 NL80211_FLAG_NEED_RTNL,
11322 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011323 {
11324 .cmd = NL80211_CMD_SET_NOACK_MAP,
11325 .doit = nl80211_set_noack_map,
11326 .policy = nl80211_policy,
11327 .flags = GENL_ADMIN_PERM,
11328 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11329 NL80211_FLAG_NEED_RTNL,
11330 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011331 {
11332 .cmd = NL80211_CMD_START_P2P_DEVICE,
11333 .doit = nl80211_start_p2p_device,
11334 .policy = nl80211_policy,
11335 .flags = GENL_ADMIN_PERM,
11336 .internal_flags = NL80211_FLAG_NEED_WDEV |
11337 NL80211_FLAG_NEED_RTNL,
11338 },
11339 {
11340 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11341 .doit = nl80211_stop_p2p_device,
11342 .policy = nl80211_policy,
11343 .flags = GENL_ADMIN_PERM,
11344 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11345 NL80211_FLAG_NEED_RTNL,
11346 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011347 {
11348 .cmd = NL80211_CMD_SET_MCAST_RATE,
11349 .doit = nl80211_set_mcast_rate,
11350 .policy = nl80211_policy,
11351 .flags = GENL_ADMIN_PERM,
11352 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11353 NL80211_FLAG_NEED_RTNL,
11354 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011355 {
11356 .cmd = NL80211_CMD_SET_MAC_ACL,
11357 .doit = nl80211_set_mac_acl,
11358 .policy = nl80211_policy,
11359 .flags = GENL_ADMIN_PERM,
11360 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11361 NL80211_FLAG_NEED_RTNL,
11362 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011363 {
11364 .cmd = NL80211_CMD_RADAR_DETECT,
11365 .doit = nl80211_start_radar_detection,
11366 .policy = nl80211_policy,
11367 .flags = GENL_ADMIN_PERM,
11368 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11369 NL80211_FLAG_NEED_RTNL,
11370 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011371 {
11372 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11373 .doit = nl80211_get_protocol_features,
11374 .policy = nl80211_policy,
11375 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011376 {
11377 .cmd = NL80211_CMD_UPDATE_FT_IES,
11378 .doit = nl80211_update_ft_ies,
11379 .policy = nl80211_policy,
11380 .flags = GENL_ADMIN_PERM,
11381 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11382 NL80211_FLAG_NEED_RTNL,
11383 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011384 {
11385 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11386 .doit = nl80211_crit_protocol_start,
11387 .policy = nl80211_policy,
11388 .flags = GENL_ADMIN_PERM,
11389 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11390 NL80211_FLAG_NEED_RTNL,
11391 },
11392 {
11393 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11394 .doit = nl80211_crit_protocol_stop,
11395 .policy = nl80211_policy,
11396 .flags = GENL_ADMIN_PERM,
11397 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11398 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011399 },
11400 {
11401 .cmd = NL80211_CMD_GET_COALESCE,
11402 .doit = nl80211_get_coalesce,
11403 .policy = nl80211_policy,
11404 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11405 NL80211_FLAG_NEED_RTNL,
11406 },
11407 {
11408 .cmd = NL80211_CMD_SET_COALESCE,
11409 .doit = nl80211_set_coalesce,
11410 .policy = nl80211_policy,
11411 .flags = GENL_ADMIN_PERM,
11412 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11413 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011414 },
11415 {
11416 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11417 .doit = nl80211_channel_switch,
11418 .policy = nl80211_policy,
11419 .flags = GENL_ADMIN_PERM,
11420 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11421 NL80211_FLAG_NEED_RTNL,
11422 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011423 {
11424 .cmd = NL80211_CMD_VENDOR,
11425 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011426 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011427 .policy = nl80211_policy,
11428 .flags = GENL_ADMIN_PERM,
11429 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11430 NL80211_FLAG_NEED_RTNL,
11431 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011432 {
11433 .cmd = NL80211_CMD_SET_QOS_MAP,
11434 .doit = nl80211_set_qos_map,
11435 .policy = nl80211_policy,
11436 .flags = GENL_ADMIN_PERM,
11437 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11438 NL80211_FLAG_NEED_RTNL,
11439 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011440 {
11441 .cmd = NL80211_CMD_ADD_TX_TS,
11442 .doit = nl80211_add_tx_ts,
11443 .policy = nl80211_policy,
11444 .flags = GENL_ADMIN_PERM,
11445 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11446 NL80211_FLAG_NEED_RTNL,
11447 },
11448 {
11449 .cmd = NL80211_CMD_DEL_TX_TS,
11450 .doit = nl80211_del_tx_ts,
11451 .policy = nl80211_policy,
11452 .flags = GENL_ADMIN_PERM,
11453 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11454 NL80211_FLAG_NEED_RTNL,
11455 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011456 {
11457 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11458 .doit = nl80211_tdls_channel_switch,
11459 .policy = nl80211_policy,
11460 .flags = GENL_ADMIN_PERM,
11461 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11462 NL80211_FLAG_NEED_RTNL,
11463 },
11464 {
11465 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11466 .doit = nl80211_tdls_cancel_channel_switch,
11467 .policy = nl80211_policy,
11468 .flags = GENL_ADMIN_PERM,
11469 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11470 NL80211_FLAG_NEED_RTNL,
11471 },
Johannes Berg55682962007-09-20 13:09:35 -040011472};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011473
Johannes Berg55682962007-09-20 13:09:35 -040011474/* notification functions */
11475
Johannes Berg3bb20552014-05-26 13:52:25 +020011476void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11477 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011478{
11479 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011480 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011481
Johannes Berg3bb20552014-05-26 13:52:25 +020011482 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11483 cmd != NL80211_CMD_DEL_WIPHY);
11484
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011485 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011486 if (!msg)
11487 return;
11488
Johannes Berg3bb20552014-05-26 13:52:25 +020011489 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011490 nlmsg_free(msg);
11491 return;
11492 }
11493
Johannes Berg68eb5502013-11-19 15:19:38 +010011494 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011495 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011496}
11497
Johannes Berg362a4152009-05-24 16:43:15 +020011498static int nl80211_add_scan_req(struct sk_buff *msg,
11499 struct cfg80211_registered_device *rdev)
11500{
11501 struct cfg80211_scan_request *req = rdev->scan_req;
11502 struct nlattr *nest;
11503 int i;
11504
11505 if (WARN_ON(!req))
11506 return 0;
11507
11508 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11509 if (!nest)
11510 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011511 for (i = 0; i < req->n_ssids; i++) {
11512 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11513 goto nla_put_failure;
11514 }
Johannes Berg362a4152009-05-24 16:43:15 +020011515 nla_nest_end(msg, nest);
11516
11517 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11518 if (!nest)
11519 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011520 for (i = 0; i < req->n_channels; i++) {
11521 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11522 goto nla_put_failure;
11523 }
Johannes Berg362a4152009-05-24 16:43:15 +020011524 nla_nest_end(msg, nest);
11525
David S. Miller9360ffd2012-03-29 04:41:26 -040011526 if (req->ie &&
11527 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11528 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011529
Johannes Bergae917c92013-10-25 11:05:22 +020011530 if (req->flags &&
11531 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11532 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011533
Johannes Berg362a4152009-05-24 16:43:15 +020011534 return 0;
11535 nla_put_failure:
11536 return -ENOBUFS;
11537}
11538
Johannes Berga538e2d2009-06-16 19:56:42 +020011539static int nl80211_send_scan_msg(struct sk_buff *msg,
11540 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011541 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011542 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011543 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011544{
11545 void *hdr;
11546
Eric W. Biederman15e47302012-09-07 20:12:54 +000011547 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011548 if (!hdr)
11549 return -1;
11550
David S. Miller9360ffd2012-03-29 04:41:26 -040011551 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011552 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11553 wdev->netdev->ifindex)) ||
11554 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011555 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011556
Johannes Berg362a4152009-05-24 16:43:15 +020011557 /* ignore errors and send incomplete event anyway */
11558 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011559
Johannes Berg053c0952015-01-16 22:09:00 +010011560 genlmsg_end(msg, hdr);
11561 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011562
11563 nla_put_failure:
11564 genlmsg_cancel(msg, hdr);
11565 return -EMSGSIZE;
11566}
11567
Luciano Coelho807f8a82011-05-11 17:09:35 +030011568static int
11569nl80211_send_sched_scan_msg(struct sk_buff *msg,
11570 struct cfg80211_registered_device *rdev,
11571 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011572 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011573{
11574 void *hdr;
11575
Eric W. Biederman15e47302012-09-07 20:12:54 +000011576 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011577 if (!hdr)
11578 return -1;
11579
David S. Miller9360ffd2012-03-29 04:41:26 -040011580 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11581 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11582 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011583
Johannes Berg053c0952015-01-16 22:09:00 +010011584 genlmsg_end(msg, hdr);
11585 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011586
11587 nla_put_failure:
11588 genlmsg_cancel(msg, hdr);
11589 return -EMSGSIZE;
11590}
11591
Johannes Berga538e2d2009-06-16 19:56:42 +020011592void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011593 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011594{
11595 struct sk_buff *msg;
11596
Thomas Graf58050fc2012-06-28 03:57:45 +000011597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011598 if (!msg)
11599 return;
11600
Johannes Bergfd014282012-06-18 19:17:03 +020011601 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011602 NL80211_CMD_TRIGGER_SCAN) < 0) {
11603 nlmsg_free(msg);
11604 return;
11605 }
11606
Johannes Berg68eb5502013-11-19 15:19:38 +010011607 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011608 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011609}
11610
Johannes Bergf9d15d12014-01-22 11:14:19 +020011611struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11612 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011613{
11614 struct sk_buff *msg;
11615
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011616 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011617 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011618 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011619
Johannes Bergfd014282012-06-18 19:17:03 +020011620 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011621 aborted ? NL80211_CMD_SCAN_ABORTED :
11622 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011623 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011624 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011625 }
11626
Johannes Bergf9d15d12014-01-22 11:14:19 +020011627 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011628}
11629
Johannes Bergf9d15d12014-01-22 11:14:19 +020011630void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11631 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011632{
Johannes Berg2a519312009-02-10 21:25:55 +010011633 if (!msg)
11634 return;
11635
Johannes Berg68eb5502013-11-19 15:19:38 +010011636 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011637 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011638}
11639
Luciano Coelho807f8a82011-05-11 17:09:35 +030011640void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11641 struct net_device *netdev)
11642{
11643 struct sk_buff *msg;
11644
11645 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11646 if (!msg)
11647 return;
11648
11649 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11650 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11651 nlmsg_free(msg);
11652 return;
11653 }
11654
Johannes Berg68eb5502013-11-19 15:19:38 +010011655 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011656 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011657}
11658
11659void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11660 struct net_device *netdev, u32 cmd)
11661{
11662 struct sk_buff *msg;
11663
Thomas Graf58050fc2012-06-28 03:57:45 +000011664 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011665 if (!msg)
11666 return;
11667
11668 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11669 nlmsg_free(msg);
11670 return;
11671 }
11672
Johannes Berg68eb5502013-11-19 15:19:38 +010011673 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011674 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011675}
11676
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011677static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11678 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011679{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011680 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011681 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11682 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011683
David S. Miller9360ffd2012-03-29 04:41:26 -040011684 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11685 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11686 NL80211_REGDOM_TYPE_WORLD))
11687 goto nla_put_failure;
11688 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11689 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11690 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11691 goto nla_put_failure;
11692 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11693 request->intersect) {
11694 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11695 NL80211_REGDOM_TYPE_INTERSECTION))
11696 goto nla_put_failure;
11697 } else {
11698 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11699 NL80211_REGDOM_TYPE_COUNTRY) ||
11700 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11701 request->alpha2))
11702 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011703 }
11704
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011705 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11706 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11707
11708 if (wiphy &&
11709 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11710 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011711
11712 if (wiphy &&
11713 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11714 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11715 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011716 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011717
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011718 return true;
11719
11720nla_put_failure:
11721 return false;
11722}
11723
11724/*
11725 * This can happen on global regulatory changes or device specific settings
11726 * based on custom regulatory domains.
11727 */
11728void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11729 struct regulatory_request *request)
11730{
11731 struct sk_buff *msg;
11732 void *hdr;
11733
11734 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11735 if (!msg)
11736 return;
11737
11738 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11739 if (!hdr) {
11740 nlmsg_free(msg);
11741 return;
11742 }
11743
11744 if (nl80211_reg_change_event_fill(msg, request) == false)
11745 goto nla_put_failure;
11746
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011747 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011748
Johannes Bergbc43b282009-07-25 10:54:13 +020011749 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011750 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011751 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011752 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011753
11754 return;
11755
11756nla_put_failure:
11757 genlmsg_cancel(msg, hdr);
11758 nlmsg_free(msg);
11759}
11760
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011761static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11762 struct net_device *netdev,
11763 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011764 enum nl80211_commands cmd, gfp_t gfp,
11765 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011766{
11767 struct sk_buff *msg;
11768 void *hdr;
11769
Johannes Berge6d6e342009-07-01 21:26:47 +020011770 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011771 if (!msg)
11772 return;
11773
11774 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11775 if (!hdr) {
11776 nlmsg_free(msg);
11777 return;
11778 }
11779
David S. Miller9360ffd2012-03-29 04:41:26 -040011780 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11781 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11782 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11783 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011784
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011785 if (uapsd_queues >= 0) {
11786 struct nlattr *nla_wmm =
11787 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11788 if (!nla_wmm)
11789 goto nla_put_failure;
11790
11791 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11792 uapsd_queues))
11793 goto nla_put_failure;
11794
11795 nla_nest_end(msg, nla_wmm);
11796 }
11797
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011798 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011799
Johannes Berg68eb5502013-11-19 15:19:38 +010011800 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011801 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011802 return;
11803
11804 nla_put_failure:
11805 genlmsg_cancel(msg, hdr);
11806 nlmsg_free(msg);
11807}
11808
11809void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011810 struct net_device *netdev, const u8 *buf,
11811 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011812{
11813 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011814 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011815}
11816
11817void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11818 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011819 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011820{
Johannes Berge6d6e342009-07-01 21:26:47 +020011821 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011822 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011823}
11824
Jouni Malinen53b46b82009-03-27 20:53:56 +020011825void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011826 struct net_device *netdev, const u8 *buf,
11827 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011828{
11829 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011830 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011831}
11832
Jouni Malinen53b46b82009-03-27 20:53:56 +020011833void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11834 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011835 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011836{
11837 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011838 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011839}
11840
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011841void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11842 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011843{
Johannes Berg947add32013-02-22 22:05:20 +010011844 struct wireless_dev *wdev = dev->ieee80211_ptr;
11845 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011846 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011847 const struct ieee80211_mgmt *mgmt = (void *)buf;
11848 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011849
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011850 if (WARN_ON(len < 2))
11851 return;
11852
11853 if (ieee80211_is_deauth(mgmt->frame_control))
11854 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11855 else
11856 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11857
11858 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011859 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011860}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011861EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011862
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011863static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11864 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011865 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011866{
11867 struct sk_buff *msg;
11868 void *hdr;
11869
Johannes Berge6d6e342009-07-01 21:26:47 +020011870 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011871 if (!msg)
11872 return;
11873
11874 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11875 if (!hdr) {
11876 nlmsg_free(msg);
11877 return;
11878 }
11879
David S. Miller9360ffd2012-03-29 04:41:26 -040011880 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11881 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11882 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11883 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11884 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011885
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011886 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011887
Johannes Berg68eb5502013-11-19 15:19:38 +010011888 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011889 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011890 return;
11891
11892 nla_put_failure:
11893 genlmsg_cancel(msg, hdr);
11894 nlmsg_free(msg);
11895}
11896
11897void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011898 struct net_device *netdev, const u8 *addr,
11899 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011900{
11901 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011902 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011903}
11904
11905void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011906 struct net_device *netdev, const u8 *addr,
11907 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011908{
Johannes Berge6d6e342009-07-01 21:26:47 +020011909 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11910 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011911}
11912
Samuel Ortizb23aa672009-07-01 21:26:54 +020011913void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11914 struct net_device *netdev, const u8 *bssid,
11915 const u8 *req_ie, size_t req_ie_len,
11916 const u8 *resp_ie, size_t resp_ie_len,
11917 u16 status, gfp_t gfp)
11918{
11919 struct sk_buff *msg;
11920 void *hdr;
11921
Thomas Graf58050fc2012-06-28 03:57:45 +000011922 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011923 if (!msg)
11924 return;
11925
11926 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11927 if (!hdr) {
11928 nlmsg_free(msg);
11929 return;
11930 }
11931
David S. Miller9360ffd2012-03-29 04:41:26 -040011932 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11933 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11934 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11935 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11936 (req_ie &&
11937 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11938 (resp_ie &&
11939 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11940 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011941
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011942 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011943
Johannes Berg68eb5502013-11-19 15:19:38 +010011944 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011945 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011946 return;
11947
11948 nla_put_failure:
11949 genlmsg_cancel(msg, hdr);
11950 nlmsg_free(msg);
11951
11952}
11953
11954void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11955 struct net_device *netdev, const u8 *bssid,
11956 const u8 *req_ie, size_t req_ie_len,
11957 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11958{
11959 struct sk_buff *msg;
11960 void *hdr;
11961
Thomas Graf58050fc2012-06-28 03:57:45 +000011962 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011963 if (!msg)
11964 return;
11965
11966 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11967 if (!hdr) {
11968 nlmsg_free(msg);
11969 return;
11970 }
11971
David S. Miller9360ffd2012-03-29 04:41:26 -040011972 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11973 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11974 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11975 (req_ie &&
11976 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11977 (resp_ie &&
11978 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11979 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011980
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011981 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011982
Johannes Berg68eb5502013-11-19 15:19:38 +010011983 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011984 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011985 return;
11986
11987 nla_put_failure:
11988 genlmsg_cancel(msg, hdr);
11989 nlmsg_free(msg);
11990
11991}
11992
11993void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11994 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020011995 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011996{
11997 struct sk_buff *msg;
11998 void *hdr;
11999
Thomas Graf58050fc2012-06-28 03:57:45 +000012000 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012001 if (!msg)
12002 return;
12003
12004 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12005 if (!hdr) {
12006 nlmsg_free(msg);
12007 return;
12008 }
12009
David S. Miller9360ffd2012-03-29 04:41:26 -040012010 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12011 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12012 (from_ap && reason &&
12013 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12014 (from_ap &&
12015 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12016 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12017 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012018
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012019 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012020
Johannes Berg68eb5502013-11-19 15:19:38 +010012021 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012022 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012023 return;
12024
12025 nla_put_failure:
12026 genlmsg_cancel(msg, hdr);
12027 nlmsg_free(msg);
12028
12029}
12030
Johannes Berg04a773a2009-04-19 21:24:32 +020012031void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12032 struct net_device *netdev, const u8 *bssid,
12033 gfp_t gfp)
12034{
12035 struct sk_buff *msg;
12036 void *hdr;
12037
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012038 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012039 if (!msg)
12040 return;
12041
12042 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12043 if (!hdr) {
12044 nlmsg_free(msg);
12045 return;
12046 }
12047
David S. Miller9360ffd2012-03-29 04:41:26 -040012048 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12049 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12050 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12051 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012052
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012053 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012054
Johannes Berg68eb5502013-11-19 15:19:38 +010012055 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012056 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012057 return;
12058
12059 nla_put_failure:
12060 genlmsg_cancel(msg, hdr);
12061 nlmsg_free(msg);
12062}
12063
Johannes Berg947add32013-02-22 22:05:20 +010012064void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12065 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012066{
Johannes Berg947add32013-02-22 22:05:20 +010012067 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012068 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012069 struct sk_buff *msg;
12070 void *hdr;
12071
Johannes Berg947add32013-02-22 22:05:20 +010012072 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12073 return;
12074
12075 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12076
Javier Cardonac93b5e72011-04-07 15:08:34 -070012077 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12078 if (!msg)
12079 return;
12080
12081 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12082 if (!hdr) {
12083 nlmsg_free(msg);
12084 return;
12085 }
12086
David S. Miller9360ffd2012-03-29 04:41:26 -040012087 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012088 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12089 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012090 (ie_len && ie &&
12091 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12092 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012093
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012094 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012095
Johannes Berg68eb5502013-11-19 15:19:38 +010012096 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012097 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012098 return;
12099
12100 nla_put_failure:
12101 genlmsg_cancel(msg, hdr);
12102 nlmsg_free(msg);
12103}
Johannes Berg947add32013-02-22 22:05:20 +010012104EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012105
Jouni Malinena3b8b052009-03-27 21:59:49 +020012106void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12107 struct net_device *netdev, const u8 *addr,
12108 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012109 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012110{
12111 struct sk_buff *msg;
12112 void *hdr;
12113
Johannes Berge6d6e342009-07-01 21:26:47 +020012114 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012115 if (!msg)
12116 return;
12117
12118 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12119 if (!hdr) {
12120 nlmsg_free(msg);
12121 return;
12122 }
12123
David S. Miller9360ffd2012-03-29 04:41:26 -040012124 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12125 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12126 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12127 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12128 (key_id != -1 &&
12129 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12130 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12131 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012132
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012133 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012134
Johannes Berg68eb5502013-11-19 15:19:38 +010012135 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012136 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012137 return;
12138
12139 nla_put_failure:
12140 genlmsg_cancel(msg, hdr);
12141 nlmsg_free(msg);
12142}
12143
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012144void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12145 struct ieee80211_channel *channel_before,
12146 struct ieee80211_channel *channel_after)
12147{
12148 struct sk_buff *msg;
12149 void *hdr;
12150 struct nlattr *nl_freq;
12151
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012152 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012153 if (!msg)
12154 return;
12155
12156 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12157 if (!hdr) {
12158 nlmsg_free(msg);
12159 return;
12160 }
12161
12162 /*
12163 * Since we are applying the beacon hint to a wiphy we know its
12164 * wiphy_idx is valid
12165 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012166 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12167 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012168
12169 /* Before */
12170 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12171 if (!nl_freq)
12172 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012173 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012174 goto nla_put_failure;
12175 nla_nest_end(msg, nl_freq);
12176
12177 /* After */
12178 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12179 if (!nl_freq)
12180 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012181 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012182 goto nla_put_failure;
12183 nla_nest_end(msg, nl_freq);
12184
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012185 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012186
Johannes Berg463d0182009-07-14 00:33:35 +020012187 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012188 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012189 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012190 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012191
12192 return;
12193
12194nla_put_failure:
12195 genlmsg_cancel(msg, hdr);
12196 nlmsg_free(msg);
12197}
12198
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012199static void nl80211_send_remain_on_chan_event(
12200 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012201 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012202 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012203 unsigned int duration, gfp_t gfp)
12204{
12205 struct sk_buff *msg;
12206 void *hdr;
12207
12208 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12209 if (!msg)
12210 return;
12211
12212 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
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) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012219 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12220 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020012221 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012222 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012223 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12224 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012225 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
12226 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012227
David S. Miller9360ffd2012-03-29 04:41:26 -040012228 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12229 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12230 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012231
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012232 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012233
Johannes Berg68eb5502013-11-19 15:19:38 +010012234 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012235 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012236 return;
12237
12238 nla_put_failure:
12239 genlmsg_cancel(msg, hdr);
12240 nlmsg_free(msg);
12241}
12242
Johannes Berg947add32013-02-22 22:05:20 +010012243void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12244 struct ieee80211_channel *chan,
12245 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012246{
Johannes Berg947add32013-02-22 22:05:20 +010012247 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012248 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012249
12250 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012251 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012252 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012253 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012254}
Johannes Berg947add32013-02-22 22:05:20 +010012255EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012256
Johannes Berg947add32013-02-22 22:05:20 +010012257void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12258 struct ieee80211_channel *chan,
12259 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012260{
Johannes Berg947add32013-02-22 22:05:20 +010012261 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012262 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012263
12264 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012265 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012266 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012267}
Johannes Berg947add32013-02-22 22:05:20 +010012268EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012269
Johannes Berg947add32013-02-22 22:05:20 +010012270void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12271 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012272{
Johannes Berg947add32013-02-22 22:05:20 +010012273 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012274 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012275 struct sk_buff *msg;
12276
Johannes Berg947add32013-02-22 22:05:20 +010012277 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12278
Thomas Graf58050fc2012-06-28 03:57:45 +000012279 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012280 if (!msg)
12281 return;
12282
Johannes Bergcf5ead82014-11-14 17:14:00 +010012283 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012284 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012285 nlmsg_free(msg);
12286 return;
12287 }
12288
Johannes Berg68eb5502013-11-19 15:19:38 +010012289 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012290 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012291}
Johannes Berg947add32013-02-22 22:05:20 +010012292EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012293
Johannes Bergcf5ead82014-11-14 17:14:00 +010012294void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12295 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012296{
Johannes Berg947add32013-02-22 22:05:20 +010012297 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012298 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012299 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012300 struct station_info empty_sinfo = {};
12301
12302 if (!sinfo)
12303 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012304
Johannes Berg947add32013-02-22 22:05:20 +010012305 trace_cfg80211_del_sta(dev, mac_addr);
12306
Thomas Graf58050fc2012-06-28 03:57:45 +000012307 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012308 if (!msg)
12309 return;
12310
Johannes Bergcf5ead82014-11-14 17:14:00 +010012311 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012312 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012313 nlmsg_free(msg);
12314 return;
12315 }
12316
Johannes Berg68eb5502013-11-19 15:19:38 +010012317 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012318 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012319}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012320EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012321
Johannes Berg947add32013-02-22 22:05:20 +010012322void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12323 enum nl80211_connect_failed_reason reason,
12324 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012325{
Johannes Berg947add32013-02-22 22:05:20 +010012326 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012327 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012328 struct sk_buff *msg;
12329 void *hdr;
12330
12331 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12332 if (!msg)
12333 return;
12334
12335 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12336 if (!hdr) {
12337 nlmsg_free(msg);
12338 return;
12339 }
12340
12341 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12342 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12343 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12344 goto nla_put_failure;
12345
12346 genlmsg_end(msg, hdr);
12347
Johannes Berg68eb5502013-11-19 15:19:38 +010012348 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012349 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012350 return;
12351
12352 nla_put_failure:
12353 genlmsg_cancel(msg, hdr);
12354 nlmsg_free(msg);
12355}
Johannes Berg947add32013-02-22 22:05:20 +010012356EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012357
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012358static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12359 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012360{
12361 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012362 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012363 struct sk_buff *msg;
12364 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012365 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012366
Eric W. Biederman15e47302012-09-07 20:12:54 +000012367 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012368 return false;
12369
12370 msg = nlmsg_new(100, gfp);
12371 if (!msg)
12372 return true;
12373
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012374 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012375 if (!hdr) {
12376 nlmsg_free(msg);
12377 return true;
12378 }
12379
David S. Miller9360ffd2012-03-29 04:41:26 -040012380 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12381 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12382 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12383 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012384
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012385 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012386 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012387 return true;
12388
12389 nla_put_failure:
12390 genlmsg_cancel(msg, hdr);
12391 nlmsg_free(msg);
12392 return true;
12393}
12394
Johannes Berg947add32013-02-22 22:05:20 +010012395bool cfg80211_rx_spurious_frame(struct net_device *dev,
12396 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012397{
Johannes Berg947add32013-02-22 22:05:20 +010012398 struct wireless_dev *wdev = dev->ieee80211_ptr;
12399 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012400
Johannes Berg947add32013-02-22 22:05:20 +010012401 trace_cfg80211_rx_spurious_frame(dev, addr);
12402
12403 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12404 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12405 trace_cfg80211_return_bool(false);
12406 return false;
12407 }
12408 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12409 addr, gfp);
12410 trace_cfg80211_return_bool(ret);
12411 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012412}
Johannes Berg947add32013-02-22 22:05:20 +010012413EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12414
12415bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12416 const u8 *addr, gfp_t gfp)
12417{
12418 struct wireless_dev *wdev = dev->ieee80211_ptr;
12419 bool ret;
12420
12421 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12422
12423 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12424 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12425 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12426 trace_cfg80211_return_bool(false);
12427 return false;
12428 }
12429 ret = __nl80211_unexpected_frame(dev,
12430 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12431 addr, gfp);
12432 trace_cfg80211_return_bool(ret);
12433 return ret;
12434}
12435EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012436
Johannes Berg2e161f72010-08-12 15:38:38 +020012437int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012438 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012439 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012440 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012441{
Johannes Berg71bbc992012-06-15 15:30:18 +020012442 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012443 struct sk_buff *msg;
12444 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012445
12446 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12447 if (!msg)
12448 return -ENOMEM;
12449
Johannes Berg2e161f72010-08-12 15:38:38 +020012450 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012451 if (!hdr) {
12452 nlmsg_free(msg);
12453 return -ENOMEM;
12454 }
12455
David S. Miller9360ffd2012-03-29 04:41:26 -040012456 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012457 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12458 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012459 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012460 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12461 (sig_dbm &&
12462 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012463 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12464 (flags &&
12465 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012466 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012467
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012468 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012469
Eric W. Biederman15e47302012-09-07 20:12:54 +000012470 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012471
12472 nla_put_failure:
12473 genlmsg_cancel(msg, hdr);
12474 nlmsg_free(msg);
12475 return -ENOBUFS;
12476}
12477
Johannes Berg947add32013-02-22 22:05:20 +010012478void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12479 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012480{
Johannes Berg947add32013-02-22 22:05:20 +010012481 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012482 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012483 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012484 struct sk_buff *msg;
12485 void *hdr;
12486
Johannes Berg947add32013-02-22 22:05:20 +010012487 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12488
Jouni Malinen026331c2010-02-15 12:53:10 +020012489 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12490 if (!msg)
12491 return;
12492
Johannes Berg2e161f72010-08-12 15:38:38 +020012493 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012494 if (!hdr) {
12495 nlmsg_free(msg);
12496 return;
12497 }
12498
David S. Miller9360ffd2012-03-29 04:41:26 -040012499 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012500 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12501 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012502 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012503 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12504 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12505 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12506 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012507
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012508 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012509
Johannes Berg68eb5502013-11-19 15:19:38 +010012510 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012511 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012512 return;
12513
12514 nla_put_failure:
12515 genlmsg_cancel(msg, hdr);
12516 nlmsg_free(msg);
12517}
Johannes Berg947add32013-02-22 22:05:20 +010012518EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012519
Johannes Berg5b97f492014-11-26 12:37:43 +010012520static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12521 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012522{
Johannes Berg947add32013-02-22 22:05:20 +010012523 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012524 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12525 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12526 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012527
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012528 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012529 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012530
Johannes Berg5b97f492014-11-26 12:37:43 +010012531 cb = (void **)msg->cb;
12532
12533 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12534 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012535 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012536 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012537 }
12538
David S. Miller9360ffd2012-03-29 04:41:26 -040012539 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012540 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012541 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012542
Johannes Berg5b97f492014-11-26 12:37:43 +010012543 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012544 goto nla_put_failure;
12545
Johannes Berg5b97f492014-11-26 12:37:43 +010012546 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12547 if (!cb[1])
12548 goto nla_put_failure;
12549
12550 cb[2] = rdev;
12551
12552 return msg;
12553 nla_put_failure:
12554 nlmsg_free(msg);
12555 return NULL;
12556}
12557
12558static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12559{
12560 void **cb = (void **)msg->cb;
12561 struct cfg80211_registered_device *rdev = cb[2];
12562
12563 nla_nest_end(msg, cb[1]);
12564 genlmsg_end(msg, cb[0]);
12565
12566 memset(msg->cb, 0, sizeof(msg->cb));
12567
12568 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12569 NL80211_MCGRP_MLME, gfp);
12570}
12571
12572void cfg80211_cqm_rssi_notify(struct net_device *dev,
12573 enum nl80211_cqm_rssi_threshold_event rssi_event,
12574 gfp_t gfp)
12575{
12576 struct sk_buff *msg;
12577
12578 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12579
Johannes Berg98f03342014-11-26 12:42:02 +010012580 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12581 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12582 return;
12583
Johannes Berg5b97f492014-11-26 12:37:43 +010012584 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12585 if (!msg)
12586 return;
12587
David S. Miller9360ffd2012-03-29 04:41:26 -040012588 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12589 rssi_event))
12590 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012591
Johannes Berg5b97f492014-11-26 12:37:43 +010012592 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012593
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012594 return;
12595
12596 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012597 nlmsg_free(msg);
12598}
Johannes Berg947add32013-02-22 22:05:20 +010012599EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012600
Johannes Berg5b97f492014-11-26 12:37:43 +010012601void cfg80211_cqm_txe_notify(struct net_device *dev,
12602 const u8 *peer, u32 num_packets,
12603 u32 rate, u32 intvl, gfp_t gfp)
12604{
12605 struct sk_buff *msg;
12606
12607 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12608 if (!msg)
12609 return;
12610
12611 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12612 goto nla_put_failure;
12613
12614 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12615 goto nla_put_failure;
12616
12617 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12618 goto nla_put_failure;
12619
12620 cfg80211_send_cqm(msg, gfp);
12621 return;
12622
12623 nla_put_failure:
12624 nlmsg_free(msg);
12625}
12626EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12627
12628void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12629 const u8 *peer, u32 num_packets, gfp_t gfp)
12630{
12631 struct sk_buff *msg;
12632
12633 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12634
12635 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12636 if (!msg)
12637 return;
12638
12639 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12640 goto nla_put_failure;
12641
12642 cfg80211_send_cqm(msg, gfp);
12643 return;
12644
12645 nla_put_failure:
12646 nlmsg_free(msg);
12647}
12648EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12649
Johannes Berg98f03342014-11-26 12:42:02 +010012650void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12651{
12652 struct sk_buff *msg;
12653
12654 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12655 if (!msg)
12656 return;
12657
12658 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12659 goto nla_put_failure;
12660
12661 cfg80211_send_cqm(msg, gfp);
12662 return;
12663
12664 nla_put_failure:
12665 nlmsg_free(msg);
12666}
12667EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12668
Johannes Berg947add32013-02-22 22:05:20 +010012669static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12670 struct net_device *netdev, const u8 *bssid,
12671 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012672{
12673 struct sk_buff *msg;
12674 struct nlattr *rekey_attr;
12675 void *hdr;
12676
Thomas Graf58050fc2012-06-28 03:57:45 +000012677 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012678 if (!msg)
12679 return;
12680
12681 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12682 if (!hdr) {
12683 nlmsg_free(msg);
12684 return;
12685 }
12686
David S. Miller9360ffd2012-03-29 04:41:26 -040012687 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12688 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12689 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12690 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012691
12692 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12693 if (!rekey_attr)
12694 goto nla_put_failure;
12695
David S. Miller9360ffd2012-03-29 04:41:26 -040012696 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12697 NL80211_REPLAY_CTR_LEN, replay_ctr))
12698 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012699
12700 nla_nest_end(msg, rekey_attr);
12701
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012702 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012703
Johannes Berg68eb5502013-11-19 15:19:38 +010012704 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012705 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012706 return;
12707
12708 nla_put_failure:
12709 genlmsg_cancel(msg, hdr);
12710 nlmsg_free(msg);
12711}
12712
Johannes Berg947add32013-02-22 22:05:20 +010012713void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12714 const u8 *replay_ctr, gfp_t gfp)
12715{
12716 struct wireless_dev *wdev = dev->ieee80211_ptr;
12717 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012718 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012719
12720 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12721 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12722}
12723EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12724
12725static void
12726nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12727 struct net_device *netdev, int index,
12728 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012729{
12730 struct sk_buff *msg;
12731 struct nlattr *attr;
12732 void *hdr;
12733
Thomas Graf58050fc2012-06-28 03:57:45 +000012734 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012735 if (!msg)
12736 return;
12737
12738 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12739 if (!hdr) {
12740 nlmsg_free(msg);
12741 return;
12742 }
12743
David S. Miller9360ffd2012-03-29 04:41:26 -040012744 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12745 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12746 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012747
12748 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12749 if (!attr)
12750 goto nla_put_failure;
12751
David S. Miller9360ffd2012-03-29 04:41:26 -040012752 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12753 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12754 (preauth &&
12755 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12756 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012757
12758 nla_nest_end(msg, attr);
12759
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012760 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012761
Johannes Berg68eb5502013-11-19 15:19:38 +010012762 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012763 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012764 return;
12765
12766 nla_put_failure:
12767 genlmsg_cancel(msg, hdr);
12768 nlmsg_free(msg);
12769}
12770
Johannes Berg947add32013-02-22 22:05:20 +010012771void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12772 const u8 *bssid, bool preauth, gfp_t gfp)
12773{
12774 struct wireless_dev *wdev = dev->ieee80211_ptr;
12775 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012776 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012777
12778 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12779 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12780}
12781EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12782
12783static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12784 struct net_device *netdev,
12785 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012786 gfp_t gfp,
12787 enum nl80211_commands notif,
12788 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012789{
12790 struct sk_buff *msg;
12791 void *hdr;
12792
Thomas Graf58050fc2012-06-28 03:57:45 +000012793 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012794 if (!msg)
12795 return;
12796
Luciano Coelhof8d75522014-11-07 14:31:35 +020012797 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012798 if (!hdr) {
12799 nlmsg_free(msg);
12800 return;
12801 }
12802
Johannes Berg683b6d32012-11-08 21:25:48 +010012803 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12804 goto nla_put_failure;
12805
12806 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012807 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012808
Luciano Coelhof8d75522014-11-07 14:31:35 +020012809 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12810 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12811 goto nla_put_failure;
12812
Thomas Pedersen53145262012-04-06 13:35:47 -070012813 genlmsg_end(msg, hdr);
12814
Johannes Berg68eb5502013-11-19 15:19:38 +010012815 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012816 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012817 return;
12818
12819 nla_put_failure:
12820 genlmsg_cancel(msg, hdr);
12821 nlmsg_free(msg);
12822}
12823
Johannes Berg947add32013-02-22 22:05:20 +010012824void cfg80211_ch_switch_notify(struct net_device *dev,
12825 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012826{
Johannes Berg947add32013-02-22 22:05:20 +010012827 struct wireless_dev *wdev = dev->ieee80211_ptr;
12828 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012829 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012830
Simon Wunderliche487eae2013-11-21 18:19:51 +010012831 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012832
Simon Wunderliche487eae2013-11-21 18:19:51 +010012833 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012834
Michal Kazior9e0e2962014-01-29 14:22:27 +010012835 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012836 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012837 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12838 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012839}
12840EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12841
Luciano Coelhof8d75522014-11-07 14:31:35 +020012842void cfg80211_ch_switch_started_notify(struct net_device *dev,
12843 struct cfg80211_chan_def *chandef,
12844 u8 count)
12845{
12846 struct wireless_dev *wdev = dev->ieee80211_ptr;
12847 struct wiphy *wiphy = wdev->wiphy;
12848 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12849
12850 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12851
12852 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12853 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12854}
12855EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12856
Thomas Pedersen84f10702012-07-12 16:17:33 -070012857void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012858nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012859 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012860 enum nl80211_radar_event event,
12861 struct net_device *netdev, gfp_t gfp)
12862{
12863 struct sk_buff *msg;
12864 void *hdr;
12865
12866 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12867 if (!msg)
12868 return;
12869
12870 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12871 if (!hdr) {
12872 nlmsg_free(msg);
12873 return;
12874 }
12875
12876 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12877 goto nla_put_failure;
12878
12879 /* NOP and radar events don't need a netdev parameter */
12880 if (netdev) {
12881 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12882
12883 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12884 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12885 goto nla_put_failure;
12886 }
12887
12888 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12889 goto nla_put_failure;
12890
12891 if (nl80211_send_chandef(msg, chandef))
12892 goto nla_put_failure;
12893
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012894 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012895
Johannes Berg68eb5502013-11-19 15:19:38 +010012896 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012897 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012898 return;
12899
12900 nla_put_failure:
12901 genlmsg_cancel(msg, hdr);
12902 nlmsg_free(msg);
12903}
12904
Johannes Berg7f6cf312011-11-04 11:18:15 +010012905void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12906 u64 cookie, bool acked, gfp_t gfp)
12907{
12908 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012909 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012910 struct sk_buff *msg;
12911 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012912
Beni Lev4ee3e062012-08-27 12:49:39 +030012913 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12914
Thomas Graf58050fc2012-06-28 03:57:45 +000012915 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012916
Johannes Berg7f6cf312011-11-04 11:18:15 +010012917 if (!msg)
12918 return;
12919
12920 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12921 if (!hdr) {
12922 nlmsg_free(msg);
12923 return;
12924 }
12925
David S. Miller9360ffd2012-03-29 04:41:26 -040012926 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12927 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12928 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12929 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12930 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12931 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012932
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012933 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012934
Johannes Berg68eb5502013-11-19 15:19:38 +010012935 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012936 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012937 return;
12938
12939 nla_put_failure:
12940 genlmsg_cancel(msg, hdr);
12941 nlmsg_free(msg);
12942}
12943EXPORT_SYMBOL(cfg80211_probe_status);
12944
Johannes Berg5e760232011-11-04 11:18:17 +010012945void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12946 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012947 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012948{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012949 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012950 struct sk_buff *msg;
12951 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012952 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012953
Beni Lev4ee3e062012-08-27 12:49:39 +030012954 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12955
Ben Greear37c73b52012-10-26 14:49:25 -070012956 spin_lock_bh(&rdev->beacon_registrations_lock);
12957 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12958 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12959 if (!msg) {
12960 spin_unlock_bh(&rdev->beacon_registrations_lock);
12961 return;
12962 }
Johannes Berg5e760232011-11-04 11:18:17 +010012963
Ben Greear37c73b52012-10-26 14:49:25 -070012964 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12965 if (!hdr)
12966 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012967
Ben Greear37c73b52012-10-26 14:49:25 -070012968 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12969 (freq &&
12970 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12971 (sig_dbm &&
12972 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12973 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12974 goto nla_put_failure;
12975
12976 genlmsg_end(msg, hdr);
12977
12978 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012979 }
Ben Greear37c73b52012-10-26 14:49:25 -070012980 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012981 return;
12982
12983 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012984 spin_unlock_bh(&rdev->beacon_registrations_lock);
12985 if (hdr)
12986 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012987 nlmsg_free(msg);
12988}
12989EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12990
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012991#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012992static int cfg80211_net_detect_results(struct sk_buff *msg,
12993 struct cfg80211_wowlan_wakeup *wakeup)
12994{
12995 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12996 struct nlattr *nl_results, *nl_match, *nl_freqs;
12997 int i, j;
12998
12999 nl_results = nla_nest_start(
13000 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13001 if (!nl_results)
13002 return -EMSGSIZE;
13003
13004 for (i = 0; i < nd->n_matches; i++) {
13005 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13006
13007 nl_match = nla_nest_start(msg, i);
13008 if (!nl_match)
13009 break;
13010
13011 /* The SSID attribute is optional in nl80211, but for
13012 * simplicity reasons it's always present in the
13013 * cfg80211 structure. If a driver can't pass the
13014 * SSID, that needs to be changed. A zero length SSID
13015 * is still a valid SSID (wildcard), so it cannot be
13016 * used for this purpose.
13017 */
13018 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13019 match->ssid.ssid)) {
13020 nla_nest_cancel(msg, nl_match);
13021 goto out;
13022 }
13023
13024 if (match->n_channels) {
13025 nl_freqs = nla_nest_start(
13026 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13027 if (!nl_freqs) {
13028 nla_nest_cancel(msg, nl_match);
13029 goto out;
13030 }
13031
13032 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013033 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013034 nla_nest_cancel(msg, nl_freqs);
13035 nla_nest_cancel(msg, nl_match);
13036 goto out;
13037 }
13038 }
13039
13040 nla_nest_end(msg, nl_freqs);
13041 }
13042
13043 nla_nest_end(msg, nl_match);
13044 }
13045
13046out:
13047 nla_nest_end(msg, nl_results);
13048 return 0;
13049}
13050
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013051void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13052 struct cfg80211_wowlan_wakeup *wakeup,
13053 gfp_t gfp)
13054{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013055 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013056 struct sk_buff *msg;
13057 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013058 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013059
13060 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13061
13062 if (wakeup)
13063 size += wakeup->packet_present_len;
13064
13065 msg = nlmsg_new(size, gfp);
13066 if (!msg)
13067 return;
13068
13069 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13070 if (!hdr)
13071 goto free_msg;
13072
13073 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13074 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13075 goto free_msg;
13076
13077 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13078 wdev->netdev->ifindex))
13079 goto free_msg;
13080
13081 if (wakeup) {
13082 struct nlattr *reasons;
13083
13084 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013085 if (!reasons)
13086 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013087
13088 if (wakeup->disconnect &&
13089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13090 goto free_msg;
13091 if (wakeup->magic_pkt &&
13092 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13093 goto free_msg;
13094 if (wakeup->gtk_rekey_failure &&
13095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13096 goto free_msg;
13097 if (wakeup->eap_identity_req &&
13098 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13099 goto free_msg;
13100 if (wakeup->four_way_handshake &&
13101 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13102 goto free_msg;
13103 if (wakeup->rfkill_release &&
13104 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13105 goto free_msg;
13106
13107 if (wakeup->pattern_idx >= 0 &&
13108 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13109 wakeup->pattern_idx))
13110 goto free_msg;
13111
Johannes Bergae917c92013-10-25 11:05:22 +020013112 if (wakeup->tcp_match &&
13113 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13114 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013115
Johannes Bergae917c92013-10-25 11:05:22 +020013116 if (wakeup->tcp_connlost &&
13117 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13118 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013119
Johannes Bergae917c92013-10-25 11:05:22 +020013120 if (wakeup->tcp_nomoretokens &&
13121 nla_put_flag(msg,
13122 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13123 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013124
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013125 if (wakeup->packet) {
13126 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13127 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13128
13129 if (!wakeup->packet_80211) {
13130 pkt_attr =
13131 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13132 len_attr =
13133 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13134 }
13135
13136 if (wakeup->packet_len &&
13137 nla_put_u32(msg, len_attr, wakeup->packet_len))
13138 goto free_msg;
13139
13140 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13141 wakeup->packet))
13142 goto free_msg;
13143 }
13144
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013145 if (wakeup->net_detect &&
13146 cfg80211_net_detect_results(msg, wakeup))
13147 goto free_msg;
13148
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013149 nla_nest_end(msg, reasons);
13150 }
13151
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013152 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013153
Johannes Berg68eb5502013-11-19 15:19:38 +010013154 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013155 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013156 return;
13157
13158 free_msg:
13159 nlmsg_free(msg);
13160}
13161EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13162#endif
13163
Jouni Malinen3475b092012-11-16 22:49:57 +020013164void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13165 enum nl80211_tdls_operation oper,
13166 u16 reason_code, gfp_t gfp)
13167{
13168 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013169 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013170 struct sk_buff *msg;
13171 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013172
13173 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13174 reason_code);
13175
13176 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13177 if (!msg)
13178 return;
13179
13180 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13181 if (!hdr) {
13182 nlmsg_free(msg);
13183 return;
13184 }
13185
13186 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13187 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13188 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13189 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13190 (reason_code > 0 &&
13191 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13192 goto nla_put_failure;
13193
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013194 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013195
Johannes Berg68eb5502013-11-19 15:19:38 +010013196 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013197 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013198 return;
13199
13200 nla_put_failure:
13201 genlmsg_cancel(msg, hdr);
13202 nlmsg_free(msg);
13203}
13204EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13205
Jouni Malinen026331c2010-02-15 12:53:10 +020013206static int nl80211_netlink_notify(struct notifier_block * nb,
13207 unsigned long state,
13208 void *_notify)
13209{
13210 struct netlink_notify *notify = _notify;
13211 struct cfg80211_registered_device *rdev;
13212 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013213 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013214
13215 if (state != NETLINK_URELEASE)
13216 return NOTIFY_DONE;
13217
13218 rcu_read_lock();
13219
Johannes Berg5e760232011-11-04 11:18:17 +010013220 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013221 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013222 bool schedule_scan_stop = false;
13223 struct cfg80211_sched_scan_request *sched_scan_req =
13224 rcu_dereference(rdev->sched_scan_req);
13225
13226 if (sched_scan_req && notify->portid &&
13227 sched_scan_req->owner_nlportid == notify->portid)
13228 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013229
13230 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013231 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013232
Johannes Berg78f22b62014-03-24 17:57:27 +010013233 if (wdev->owner_nlportid == notify->portid)
13234 schedule_destroy_work = true;
13235 }
13236
Ben Greear37c73b52012-10-26 14:49:25 -070013237 spin_lock_bh(&rdev->beacon_registrations_lock);
13238 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13239 list) {
13240 if (reg->nlportid == notify->portid) {
13241 list_del(&reg->list);
13242 kfree(reg);
13243 break;
13244 }
13245 }
13246 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013247
13248 if (schedule_destroy_work) {
13249 struct cfg80211_iface_destroy *destroy;
13250
13251 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13252 if (destroy) {
13253 destroy->nlportid = notify->portid;
13254 spin_lock(&rdev->destroy_list_lock);
13255 list_add(&destroy->list, &rdev->destroy_list);
13256 spin_unlock(&rdev->destroy_list_lock);
13257 schedule_work(&rdev->destroy_work);
13258 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013259 } else if (schedule_scan_stop) {
13260 sched_scan_req->owner_nlportid = 0;
13261
13262 if (rdev->ops->sched_scan_stop &&
13263 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13264 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013265 }
Johannes Berg5e760232011-11-04 11:18:17 +010013266 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013267
13268 rcu_read_unlock();
13269
Ilan peer05050752015-03-04 00:32:06 -050013270 /*
13271 * It is possible that the user space process that is controlling the
13272 * indoor setting disappeared, so notify the regulatory core.
13273 */
13274 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013275 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013276}
13277
13278static struct notifier_block nl80211_netlink_notifier = {
13279 .notifier_call = nl80211_netlink_notify,
13280};
13281
Jouni Malinen355199e2013-02-27 17:14:27 +020013282void cfg80211_ft_event(struct net_device *netdev,
13283 struct cfg80211_ft_event_params *ft_event)
13284{
13285 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013286 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013287 struct sk_buff *msg;
13288 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013289
13290 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13291
13292 if (!ft_event->target_ap)
13293 return;
13294
13295 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13296 if (!msg)
13297 return;
13298
13299 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013300 if (!hdr)
13301 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013302
Johannes Bergae917c92013-10-25 11:05:22 +020013303 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13304 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13305 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13306 goto out;
13307
13308 if (ft_event->ies &&
13309 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13310 goto out;
13311 if (ft_event->ric_ies &&
13312 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13313 ft_event->ric_ies))
13314 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013315
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013316 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013317
Johannes Berg68eb5502013-11-19 15:19:38 +010013318 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013319 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013320 return;
13321 out:
13322 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013323}
13324EXPORT_SYMBOL(cfg80211_ft_event);
13325
Arend van Spriel5de17982013-04-18 15:49:00 +020013326void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13327{
13328 struct cfg80211_registered_device *rdev;
13329 struct sk_buff *msg;
13330 void *hdr;
13331 u32 nlportid;
13332
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013333 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013334 if (!rdev->crit_proto_nlportid)
13335 return;
13336
13337 nlportid = rdev->crit_proto_nlportid;
13338 rdev->crit_proto_nlportid = 0;
13339
13340 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13341 if (!msg)
13342 return;
13343
13344 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13345 if (!hdr)
13346 goto nla_put_failure;
13347
13348 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13349 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13350 goto nla_put_failure;
13351
13352 genlmsg_end(msg, hdr);
13353
13354 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13355 return;
13356
13357 nla_put_failure:
13358 if (hdr)
13359 genlmsg_cancel(msg, hdr);
13360 nlmsg_free(msg);
13361
13362}
13363EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13364
Johannes Berg348baf02014-01-24 14:06:29 +010013365void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13366{
13367 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013368 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013369 struct sk_buff *msg;
13370 void *hdr;
13371
13372 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13373 if (!msg)
13374 return;
13375
13376 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13377 if (!hdr)
13378 goto out;
13379
13380 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13381 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
13382 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13383 goto out;
13384
13385 genlmsg_end(msg, hdr);
13386
13387 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13388 NL80211_MCGRP_MLME, GFP_KERNEL);
13389 return;
13390 out:
13391 nlmsg_free(msg);
13392}
13393
Johannes Berg55682962007-09-20 13:09:35 -040013394/* initialisation/exit functions */
13395
13396int nl80211_init(void)
13397{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013398 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013399
Johannes Berg2a94fe42013-11-19 15:19:39 +010013400 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13401 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013402 if (err)
13403 return err;
13404
Jouni Malinen026331c2010-02-15 12:53:10 +020013405 err = netlink_register_notifier(&nl80211_netlink_notifier);
13406 if (err)
13407 goto err_out;
13408
Johannes Berg55682962007-09-20 13:09:35 -040013409 return 0;
13410 err_out:
13411 genl_unregister_family(&nl80211_fam);
13412 return err;
13413}
13414
13415void nl80211_exit(void)
13416{
Jouni Malinen026331c2010-02-15 12:53:10 +020013417 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013418 genl_unregister_family(&nl80211_fam);
13419}