blob: 98c924260b3d312055c598255cff8478bccba1e9 [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Beni Lev0c9ca112016-02-17 20:30:00 +02006 * Copyright 2015-2016 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Bergf84f7712013-11-14 17:14:45 +010035static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010037static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020038 struct genl_info *info);
39
Johannes Berg55682962007-09-20 13:09:35 -040040/* the netlink family */
41static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070042 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
43 .name = NL80211_GENL_NAME, /* have users key off the name instead */
44 .hdrsize = 0, /* no private header */
45 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040046 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020047 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020048 .pre_doit = nl80211_pre_doit,
49 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040050};
51
Johannes Berg2a94fe42013-11-19 15:19:39 +010052/* multicast groups */
53enum nl80211_multicast_groups {
54 NL80211_MCGRP_CONFIG,
55 NL80211_MCGRP_SCAN,
56 NL80211_MCGRP_REGULATORY,
57 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010058 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010059 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
60};
61
62static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010063 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
64 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
65 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
66 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
67 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010068#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010069 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#endif
71};
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073/* returns ERR_PTR values */
74static struct wireless_dev *
75__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040076{
Johannes Berg89a54e42012-06-15 14:33:17 +020077 struct cfg80211_registered_device *rdev;
78 struct wireless_dev *result = NULL;
79 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
80 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
81 u64 wdev_id;
82 int wiphy_idx = -1;
83 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg5fe231e2013-05-08 21:45:15 +020085 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg89a54e42012-06-15 14:33:17 +020087 if (!have_ifidx && !have_wdev_id)
88 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (have_ifidx)
91 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
92 if (have_wdev_id) {
93 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
94 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040095 }
96
Johannes Berg89a54e42012-06-15 14:33:17 +020097 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
98 struct wireless_dev *wdev;
99
100 if (wiphy_net(&rdev->wiphy) != netns)
101 continue;
102
103 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
104 continue;
105
Johannes Berg89a54e42012-06-15 14:33:17 +0200106 list_for_each_entry(wdev, &rdev->wdev_list, list) {
107 if (have_ifidx && wdev->netdev &&
108 wdev->netdev->ifindex == ifidx) {
109 result = wdev;
110 break;
111 }
112 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 result = wdev;
114 break;
115 }
116 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200117
118 if (result)
119 break;
120 }
121
122 if (result)
123 return result;
124 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400125}
126
Johannes Berga9455402012-06-15 13:32:49 +0200127static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200129{
Johannes Berg7fee4772012-06-15 14:09:58 +0200130 struct cfg80211_registered_device *rdev = NULL, *tmp;
131 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg5fe231e2013-05-08 21:45:15 +0200133 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg878d9ec2012-06-15 14:18:32 +0200135 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 !attrs[NL80211_ATTR_IFINDEX] &&
137 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200138 return ERR_PTR(-EINVAL);
139
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200141 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200143
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (attrs[NL80211_ATTR_WDEV]) {
145 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
146 struct wireless_dev *wdev;
147 bool found = false;
148
149 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
150 if (tmp) {
151 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200152 list_for_each_entry(wdev, &tmp->wdev_list, list) {
153 if (wdev->identifier != (u32)wdev_id)
154 continue;
155 found = true;
156 break;
157 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200158
159 if (!found)
160 tmp = NULL;
161
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164 rdev = tmp;
165 }
166 }
167
Johannes Berg878d9ec2012-06-15 14:18:32 +0200168 if (attrs[NL80211_ATTR_IFINDEX]) {
169 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800170 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200171 if (netdev) {
172 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800173 tmp = wiphy_to_rdev(
174 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200175 else
176 tmp = NULL;
177
Johannes Berg7fee4772012-06-15 14:09:58 +0200178 /* not wireless device -- return error */
179 if (!tmp)
180 return ERR_PTR(-EINVAL);
181
182 /* mismatch -- return error */
183 if (rdev && tmp != rdev)
184 return ERR_PTR(-EINVAL);
185
186 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
189
Johannes Berg4f7eff12012-06-15 14:14:22 +0200190 if (!rdev)
191 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200192
Johannes Berg4f7eff12012-06-15 14:14:22 +0200193 if (netns != wiphy_net(&rdev->wiphy))
194 return ERR_PTR(-ENODEV);
195
196 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200197}
198
199/*
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200202 *
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
205 */
206static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200207cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200208{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200209 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200210}
211
Johannes Berg55682962007-09-20 13:09:35 -0400212/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300213static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400214 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
215 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700216 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200217 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100218
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200219 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100221 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
224
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200225 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200230 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400231
232 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Eliad Pellere007b852011-11-24 18:13:56 +0200236 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
237 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100238
Johannes Bergb9454e82009-07-08 13:29:08 +0200239 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100240 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
241 .len = WLAN_MAX_KEY_LEN },
242 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
243 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
244 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200245 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200246 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100247
248 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
249 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
250 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
251 .len = IEEE80211_MAX_DATA_LEN },
252 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100254 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
255 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
256 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
257 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
258 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100260 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200261 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100262 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800263 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100264 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300265
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700266 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
267 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
268
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300269 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200272 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
273 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100274 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300275
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800276 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700277 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700278
Johannes Berg6c739412011-11-03 09:27:01 +0100279 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200280
281 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
282 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
283 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100284 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
285 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200286
287 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
288 .len = IEEE80211_MAX_SSID_LEN },
289 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
290 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200291 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300292 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300293 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300294 [NL80211_ATTR_STA_FLAGS2] = {
295 .len = sizeof(struct nl80211_sta_flag_update),
296 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300297 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300298 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
299 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200300 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
301 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
302 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200303 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100304 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100305 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
306 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100307 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
308 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200309 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200310 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
311 .len = IEEE80211_MAX_DATA_LEN },
312 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200313 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200314 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300315 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200316 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300317 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200319 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900320 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
321 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100322 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100323 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100324 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200325 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700326 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300327 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200328 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200329 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300330 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300331 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
332 .len = IEEE80211_MAX_DATA_LEN },
333 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530335 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300336 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530337 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300338 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
342 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300343 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100344 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200345 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
346 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700347 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800348 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
349 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
350 .len = NL80211_HT_CAPABILITY_LEN
351 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100352 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530353 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530354 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200355 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700356 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300357 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000358 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700359 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100360 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
361 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530362 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
363 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200364 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
365 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100366 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100367 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
368 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
369 .len = NL80211_VHT_CAPABILITY_LEN,
370 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200371 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
372 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
373 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300374 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200375 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
376 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
377 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300378 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
379 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530380 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
381 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200382 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100383 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100384 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800387 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
388 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200389 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
390 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530391 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200392 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300393 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300394 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300395 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
396 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
397 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300398 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200399 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200400 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200401 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200402 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500403 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Lior David34d50512016-01-28 10:58:25 +0200404 [NL80211_ATTR_PBSS] = { .type = NLA_FLAG },
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])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007289 if (!((rdev->wiphy.features &
7290 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7291 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7292 !wiphy_ext_feature_isset(&rdev->wiphy,
7293 NL80211_EXT_FEATURE_RRM))
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007294 return -EINVAL;
7295 req.flags |= ASSOC_REQ_USE_RRM;
7296 }
7297
Johannes Bergf62fab72013-02-21 20:09:09 +01007298 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007299 if (!err) {
7300 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007301 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7302 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007303 wdev_unlock(dev->ieee80211_ptr);
7304 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007305
Jouni Malinen636a5d32009-03-19 13:39:22 +02007306 return err;
7307}
7308
7309static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7310{
Johannes Berg4c476992010-10-04 21:36:35 +02007311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7312 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007313 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007314 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007315 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007316 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007317
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007318 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7319 return -EINVAL;
7320
7321 if (!info->attrs[NL80211_ATTR_MAC])
7322 return -EINVAL;
7323
7324 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7325 return -EINVAL;
7326
Johannes Berg4c476992010-10-04 21:36:35 +02007327 if (!rdev->ops->deauth)
7328 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007329
Johannes Berg074ac8d2010-09-16 14:58:22 +02007330 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007331 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7332 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007333
Johannes Berg19957bb2009-07-02 17:20:43 +02007334 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007335
Johannes Berg19957bb2009-07-02 17:20:43 +02007336 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7337 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007338 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007339 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007340 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007341
7342 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007343 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7344 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007345 }
7346
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007347 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7348
Johannes Berg91bf9b22013-05-15 17:44:01 +02007349 wdev_lock(dev->ieee80211_ptr);
7350 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7351 local_state_change);
7352 wdev_unlock(dev->ieee80211_ptr);
7353 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007354}
7355
7356static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7357{
Johannes Berg4c476992010-10-04 21:36:35 +02007358 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7359 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007360 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007361 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007362 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007363 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007364
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007365 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7366 return -EINVAL;
7367
7368 if (!info->attrs[NL80211_ATTR_MAC])
7369 return -EINVAL;
7370
7371 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7372 return -EINVAL;
7373
Johannes Berg4c476992010-10-04 21:36:35 +02007374 if (!rdev->ops->disassoc)
7375 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007376
Johannes Berg074ac8d2010-09-16 14:58:22 +02007377 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007378 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7379 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007380
Johannes Berg19957bb2009-07-02 17:20:43 +02007381 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007382
Johannes Berg19957bb2009-07-02 17:20:43 +02007383 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7384 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007385 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007386 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007387 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007388
7389 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007390 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7391 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007392 }
7393
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007394 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7395
Johannes Berg91bf9b22013-05-15 17:44:01 +02007396 wdev_lock(dev->ieee80211_ptr);
7397 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7398 local_state_change);
7399 wdev_unlock(dev->ieee80211_ptr);
7400 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007401}
7402
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007403static bool
7404nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7405 int mcast_rate[IEEE80211_NUM_BANDS],
7406 int rateval)
7407{
7408 struct wiphy *wiphy = &rdev->wiphy;
7409 bool found = false;
7410 int band, i;
7411
7412 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7413 struct ieee80211_supported_band *sband;
7414
7415 sband = wiphy->bands[band];
7416 if (!sband)
7417 continue;
7418
7419 for (i = 0; i < sband->n_bitrates; i++) {
7420 if (sband->bitrates[i].bitrate == rateval) {
7421 mcast_rate[band] = i + 1;
7422 found = true;
7423 break;
7424 }
7425 }
7426 }
7427
7428 return found;
7429}
7430
Johannes Berg04a773a2009-04-19 21:24:32 +02007431static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7432{
Johannes Berg4c476992010-10-04 21:36:35 +02007433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7434 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007435 struct cfg80211_ibss_params ibss;
7436 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007437 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007438 int err;
7439
Johannes Berg8e30bc52009-04-22 17:45:38 +02007440 memset(&ibss, 0, sizeof(ibss));
7441
Johannes Berg04a773a2009-04-19 21:24:32 +02007442 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7443 return -EINVAL;
7444
Johannes Berg683b6d32012-11-08 21:25:48 +01007445 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007446 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7447 return -EINVAL;
7448
Johannes Berg8e30bc52009-04-22 17:45:38 +02007449 ibss.beacon_interval = 100;
7450
7451 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7452 ibss.beacon_interval =
7453 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7454 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7455 return -EINVAL;
7456 }
7457
Johannes Berg4c476992010-10-04 21:36:35 +02007458 if (!rdev->ops->join_ibss)
7459 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007460
Johannes Berg4c476992010-10-04 21:36:35 +02007461 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7462 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007463
Johannes Berg79c97e92009-07-07 03:56:12 +02007464 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007465
Johannes Berg39193492011-09-16 13:45:25 +02007466 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007467 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007468
7469 if (!is_valid_ether_addr(ibss.bssid))
7470 return -EINVAL;
7471 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007472 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7473 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7474
7475 if (info->attrs[NL80211_ATTR_IE]) {
7476 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7477 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7478 }
7479
Johannes Berg683b6d32012-11-08 21:25:48 +01007480 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7481 if (err)
7482 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007483
Ilan Peer174e0cd2014-02-23 09:13:01 +02007484 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7485 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007486 return -EINVAL;
7487
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007488 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007489 case NL80211_CHAN_WIDTH_5:
7490 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007491 case NL80211_CHAN_WIDTH_20_NOHT:
7492 break;
7493 case NL80211_CHAN_WIDTH_20:
7494 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007495 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7496 return -EINVAL;
7497 break;
7498 case NL80211_CHAN_WIDTH_80:
7499 case NL80211_CHAN_WIDTH_80P80:
7500 case NL80211_CHAN_WIDTH_160:
7501 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7502 return -EINVAL;
7503 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7504 NL80211_EXT_FEATURE_VHT_IBSS))
7505 return -EINVAL;
7506 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007507 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007508 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007509 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007510
Johannes Berg04a773a2009-04-19 21:24:32 +02007511 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007512 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007513
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007514 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7515 u8 *rates =
7516 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7517 int n_rates =
7518 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7519 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007520 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007521
Johannes Berg34850ab2011-07-18 18:08:35 +02007522 err = ieee80211_get_ratemask(sband, rates, n_rates,
7523 &ibss.basic_rates);
7524 if (err)
7525 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007526 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007527
Simon Wunderlich803768f2013-06-28 10:39:58 +02007528 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7529 memcpy(&ibss.ht_capa_mask,
7530 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7531 sizeof(ibss.ht_capa_mask));
7532
7533 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7534 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7535 return -EINVAL;
7536 memcpy(&ibss.ht_capa,
7537 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7538 sizeof(ibss.ht_capa));
7539 }
7540
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007541 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7542 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7543 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7544 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007545
Johannes Berg4c476992010-10-04 21:36:35 +02007546 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307547 bool no_ht = false;
7548
Johannes Berg4c476992010-10-04 21:36:35 +02007549 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307550 info->attrs[NL80211_ATTR_KEYS],
7551 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007552 if (IS_ERR(connkeys))
7553 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307554
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007555 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7556 no_ht) {
Ola Olsson5e950a72016-02-11 01:00:22 +01007557 kzfree(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307558 return -EINVAL;
7559 }
Johannes Berg4c476992010-10-04 21:36:35 +02007560 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007561
Antonio Quartulli267335d2012-01-31 20:25:47 +01007562 ibss.control_port =
7563 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7564
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007565 ibss.userspace_handles_dfs =
7566 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7567
Johannes Berg4c476992010-10-04 21:36:35 +02007568 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007569 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007570 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007571 return err;
7572}
7573
7574static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7575{
Johannes Berg4c476992010-10-04 21:36:35 +02007576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7577 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007578
Johannes Berg4c476992010-10-04 21:36:35 +02007579 if (!rdev->ops->leave_ibss)
7580 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007581
Johannes Berg4c476992010-10-04 21:36:35 +02007582 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7583 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007584
Johannes Berg4c476992010-10-04 21:36:35 +02007585 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007586}
7587
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007588static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7589{
7590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7591 struct net_device *dev = info->user_ptr[1];
7592 int mcast_rate[IEEE80211_NUM_BANDS];
7593 u32 nla_rate;
7594 int err;
7595
7596 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007597 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7598 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007599 return -EOPNOTSUPP;
7600
7601 if (!rdev->ops->set_mcast_rate)
7602 return -EOPNOTSUPP;
7603
7604 memset(mcast_rate, 0, sizeof(mcast_rate));
7605
7606 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7607 return -EINVAL;
7608
7609 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7610 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7611 return -EINVAL;
7612
Ilan Peera1056b12015-10-22 22:27:46 +03007613 err = rdev_set_mcast_rate(rdev, dev, mcast_rate);
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007614
7615 return err;
7616}
7617
Johannes Bergad7e7182013-11-13 13:37:47 +01007618static struct sk_buff *
7619__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007620 struct wireless_dev *wdev, int approxlen,
7621 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007622 enum nl80211_attrs attr,
7623 const struct nl80211_vendor_cmd_info *info,
7624 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007625{
7626 struct sk_buff *skb;
7627 void *hdr;
7628 struct nlattr *data;
7629
7630 skb = nlmsg_new(approxlen + 100, gfp);
7631 if (!skb)
7632 return NULL;
7633
7634 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7635 if (!hdr) {
7636 kfree_skb(skb);
7637 return NULL;
7638 }
7639
7640 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7641 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007642
7643 if (info) {
7644 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7645 info->vendor_id))
7646 goto nla_put_failure;
7647 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7648 info->subcmd))
7649 goto nla_put_failure;
7650 }
7651
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007652 if (wdev) {
7653 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7654 wdev_id(wdev)))
7655 goto nla_put_failure;
7656 if (wdev->netdev &&
7657 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7658 wdev->netdev->ifindex))
7659 goto nla_put_failure;
7660 }
7661
Johannes Bergad7e7182013-11-13 13:37:47 +01007662 data = nla_nest_start(skb, attr);
7663
7664 ((void **)skb->cb)[0] = rdev;
7665 ((void **)skb->cb)[1] = hdr;
7666 ((void **)skb->cb)[2] = data;
7667
7668 return skb;
7669
7670 nla_put_failure:
7671 kfree_skb(skb);
7672 return NULL;
7673}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007674
Johannes Berge03ad6e2014-01-01 17:22:30 +01007675struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007676 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007677 enum nl80211_commands cmd,
7678 enum nl80211_attrs attr,
7679 int vendor_event_idx,
7680 int approxlen, gfp_t gfp)
7681{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007682 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007683 const struct nl80211_vendor_cmd_info *info;
7684
7685 switch (cmd) {
7686 case NL80211_CMD_TESTMODE:
7687 if (WARN_ON(vendor_event_idx != -1))
7688 return NULL;
7689 info = NULL;
7690 break;
7691 case NL80211_CMD_VENDOR:
7692 if (WARN_ON(vendor_event_idx < 0 ||
7693 vendor_event_idx >= wiphy->n_vendor_events))
7694 return NULL;
7695 info = &wiphy->vendor_events[vendor_event_idx];
7696 break;
7697 default:
7698 WARN_ON(1);
7699 return NULL;
7700 }
7701
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007702 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007703 cmd, attr, info, gfp);
7704}
7705EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7706
7707void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7708{
7709 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7710 void *hdr = ((void **)skb->cb)[1];
7711 struct nlattr *data = ((void **)skb->cb)[2];
7712 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7713
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007714 /* clear CB data for netlink core to own from now on */
7715 memset(skb->cb, 0, sizeof(skb->cb));
7716
Johannes Berge03ad6e2014-01-01 17:22:30 +01007717 nla_nest_end(skb, data);
7718 genlmsg_end(skb, hdr);
7719
7720 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7721 mcgrp = NL80211_MCGRP_VENDOR;
7722
7723 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7724 mcgrp, gfp);
7725}
7726EXPORT_SYMBOL(__cfg80211_send_event_skb);
7727
Johannes Bergaff89a92009-07-01 21:26:51 +02007728#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007729static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7730{
Johannes Berg4c476992010-10-04 21:36:35 +02007731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007732 struct wireless_dev *wdev =
7733 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007734 int err;
7735
David Spinadelfc73f112013-07-31 18:04:15 +03007736 if (!rdev->ops->testmode_cmd)
7737 return -EOPNOTSUPP;
7738
7739 if (IS_ERR(wdev)) {
7740 err = PTR_ERR(wdev);
7741 if (err != -EINVAL)
7742 return err;
7743 wdev = NULL;
7744 } else if (wdev->wiphy != &rdev->wiphy) {
7745 return -EINVAL;
7746 }
7747
Johannes Bergaff89a92009-07-01 21:26:51 +02007748 if (!info->attrs[NL80211_ATTR_TESTDATA])
7749 return -EINVAL;
7750
Johannes Bergad7e7182013-11-13 13:37:47 +01007751 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007752 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007753 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7754 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007755 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007756
Johannes Bergaff89a92009-07-01 21:26:51 +02007757 return err;
7758}
7759
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007760static int nl80211_testmode_dump(struct sk_buff *skb,
7761 struct netlink_callback *cb)
7762{
Johannes Berg00918d32011-12-13 17:22:05 +01007763 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007764 int err;
7765 long phy_idx;
7766 void *data = NULL;
7767 int data_len = 0;
7768
Johannes Berg5fe231e2013-05-08 21:45:15 +02007769 rtnl_lock();
7770
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007771 if (cb->args[0]) {
7772 /*
7773 * 0 is a valid index, but not valid for args[0],
7774 * so we need to offset by 1.
7775 */
7776 phy_idx = cb->args[0] - 1;
7777 } else {
7778 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7779 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7780 nl80211_policy);
7781 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007782 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007783
Johannes Berg2bd7e352012-06-15 14:23:16 +02007784 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7785 nl80211_fam.attrbuf);
7786 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007787 err = PTR_ERR(rdev);
7788 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007789 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007790 phy_idx = rdev->wiphy_idx;
7791 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007792
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007793 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7794 cb->args[1] =
7795 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7796 }
7797
7798 if (cb->args[1]) {
7799 data = nla_data((void *)cb->args[1]);
7800 data_len = nla_len((void *)cb->args[1]);
7801 }
7802
Johannes Berg00918d32011-12-13 17:22:05 +01007803 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7804 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007805 err = -ENOENT;
7806 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007807 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007808
Johannes Berg00918d32011-12-13 17:22:05 +01007809 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007810 err = -EOPNOTSUPP;
7811 goto out_err;
7812 }
7813
7814 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007815 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007816 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7817 NL80211_CMD_TESTMODE);
7818 struct nlattr *tmdata;
7819
Dan Carpentercb35fba2013-08-14 14:50:01 +03007820 if (!hdr)
7821 break;
7822
David S. Miller9360ffd2012-03-29 04:41:26 -04007823 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007824 genlmsg_cancel(skb, hdr);
7825 break;
7826 }
7827
7828 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7829 if (!tmdata) {
7830 genlmsg_cancel(skb, hdr);
7831 break;
7832 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007833 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007834 nla_nest_end(skb, tmdata);
7835
7836 if (err == -ENOBUFS || err == -ENOENT) {
7837 genlmsg_cancel(skb, hdr);
7838 break;
7839 } else if (err) {
7840 genlmsg_cancel(skb, hdr);
7841 goto out_err;
7842 }
7843
7844 genlmsg_end(skb, hdr);
7845 }
7846
7847 err = skb->len;
7848 /* see above */
7849 cb->args[0] = phy_idx + 1;
7850 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007851 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007852 return err;
7853}
Johannes Bergaff89a92009-07-01 21:26:51 +02007854#endif
7855
Samuel Ortizb23aa672009-07-01 21:26:54 +02007856static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7857{
Johannes Berg4c476992010-10-04 21:36:35 +02007858 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7859 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007860 struct cfg80211_connect_params connect;
7861 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007862 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007863 int err;
7864
7865 memset(&connect, 0, sizeof(connect));
7866
7867 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7868 return -EINVAL;
7869
7870 if (!info->attrs[NL80211_ATTR_SSID] ||
7871 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7872 return -EINVAL;
7873
7874 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7875 connect.auth_type =
7876 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007877 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7878 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007879 return -EINVAL;
7880 } else
7881 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7882
7883 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7884
Johannes Bergc0692b82010-08-27 14:26:53 +03007885 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007886 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007887 if (err)
7888 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007889
Johannes Berg074ac8d2010-09-16 14:58:22 +02007890 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007891 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7892 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007893
Johannes Berg79c97e92009-07-07 03:56:12 +02007894 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007895
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307896 connect.bg_scan_period = -1;
7897 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7898 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7899 connect.bg_scan_period =
7900 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7901 }
7902
Samuel Ortizb23aa672009-07-01 21:26:54 +02007903 if (info->attrs[NL80211_ATTR_MAC])
7904 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007905 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7906 connect.bssid_hint =
7907 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007908 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7909 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7910
7911 if (info->attrs[NL80211_ATTR_IE]) {
7912 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7913 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7914 }
7915
Jouni Malinencee00a92013-01-15 17:15:57 +02007916 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7917 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7918 if (connect.mfp != NL80211_MFP_REQUIRED &&
7919 connect.mfp != NL80211_MFP_NO)
7920 return -EINVAL;
7921 } else {
7922 connect.mfp = NL80211_MFP_NO;
7923 }
7924
Samuel Ortizb23aa672009-07-01 21:26:54 +02007925 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007926 connect.channel = nl80211_get_valid_chan(
7927 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7928 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007929 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007930 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007931 connect.channel_hint = nl80211_get_valid_chan(
7932 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7933 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007934 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007935 }
7936
Johannes Bergfffd0932009-07-08 14:22:54 +02007937 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7938 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307939 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007940 if (IS_ERR(connkeys))
7941 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007942 }
7943
Ben Greear7e7c8922011-11-18 11:31:59 -08007944 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7945 connect.flags |= ASSOC_REQ_DISABLE_HT;
7946
7947 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7948 memcpy(&connect.ht_capa_mask,
7949 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7950 sizeof(connect.ht_capa_mask));
7951
7952 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007953 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007954 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007955 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007956 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007957 memcpy(&connect.ht_capa,
7958 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7959 sizeof(connect.ht_capa));
7960 }
7961
Johannes Bergee2aca32013-02-21 17:36:01 +01007962 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7963 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7964
7965 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7966 memcpy(&connect.vht_capa_mask,
7967 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7968 sizeof(connect.vht_capa_mask));
7969
7970 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7971 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007972 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007973 return -EINVAL;
7974 }
7975 memcpy(&connect.vht_capa,
7976 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7977 sizeof(connect.vht_capa));
7978 }
7979
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007980 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
Beni Lev0c9ca112016-02-17 20:30:00 +02007981 if (!((rdev->wiphy.features &
7982 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) &&
7983 (rdev->wiphy.features & NL80211_FEATURE_QUIET)) &&
7984 !wiphy_ext_feature_isset(&rdev->wiphy,
7985 NL80211_EXT_FEATURE_RRM)) {
Ola Olsson707554b2015-12-11 21:04:52 +01007986 kzfree(connkeys);
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007987 return -EINVAL;
Ola Olsson707554b2015-12-11 21:04:52 +01007988 }
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007989 connect.flags |= ASSOC_REQ_USE_RRM;
7990 }
7991
Lior David34d50512016-01-28 10:58:25 +02007992 connect.pbss = nla_get_flag(info->attrs[NL80211_ATTR_PBSS]);
7993 if (connect.pbss && !rdev->wiphy.bands[IEEE80211_BAND_60GHZ]) {
7994 kzfree(connkeys);
7995 return -EOPNOTSUPP;
7996 }
7997
Johannes Berg83739b02013-05-15 17:44:01 +02007998 wdev_lock(dev->ieee80211_ptr);
7999 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
8000 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02008001 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03008002 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02008003 return err;
8004}
8005
8006static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
8007{
Johannes Berg4c476992010-10-04 21:36:35 +02008008 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8009 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02008010 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02008011 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008012
8013 if (!info->attrs[NL80211_ATTR_REASON_CODE])
8014 reason = WLAN_REASON_DEAUTH_LEAVING;
8015 else
8016 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
8017
8018 if (reason == 0)
8019 return -EINVAL;
8020
Johannes Berg074ac8d2010-09-16 14:58:22 +02008021 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008022 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8023 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008024
Johannes Berg83739b02013-05-15 17:44:01 +02008025 wdev_lock(dev->ieee80211_ptr);
8026 ret = cfg80211_disconnect(rdev, dev, reason, true);
8027 wdev_unlock(dev->ieee80211_ptr);
8028 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02008029}
8030
Johannes Berg463d0182009-07-14 00:33:35 +02008031static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
8032{
Johannes Berg4c476992010-10-04 21:36:35 +02008033 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02008034 struct net *net;
8035 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02008036
Vadim Kochan4b681c82015-01-12 16:34:05 +02008037 if (info->attrs[NL80211_ATTR_PID]) {
8038 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
8039
8040 net = get_net_ns_by_pid(pid);
8041 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
8042 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
8043
8044 net = get_net_ns_by_fd(fd);
8045 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02008046 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02008047 }
Johannes Berg463d0182009-07-14 00:33:35 +02008048
Johannes Berg4c476992010-10-04 21:36:35 +02008049 if (IS_ERR(net))
8050 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008051
8052 err = 0;
8053
8054 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008055 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8056 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008057
Johannes Berg463d0182009-07-14 00:33:35 +02008058 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008059 return err;
8060}
8061
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008062static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8063{
Johannes Berg4c476992010-10-04 21:36:35 +02008064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008065 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8066 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008067 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008068 struct cfg80211_pmksa pmksa;
8069
8070 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8071
8072 if (!info->attrs[NL80211_ATTR_MAC])
8073 return -EINVAL;
8074
8075 if (!info->attrs[NL80211_ATTR_PMKID])
8076 return -EINVAL;
8077
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008078 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8079 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8080
Johannes Berg074ac8d2010-09-16 14:58:22 +02008081 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008082 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8083 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008084
8085 switch (info->genlhdr->cmd) {
8086 case NL80211_CMD_SET_PMKSA:
8087 rdev_ops = rdev->ops->set_pmksa;
8088 break;
8089 case NL80211_CMD_DEL_PMKSA:
8090 rdev_ops = rdev->ops->del_pmksa;
8091 break;
8092 default:
8093 WARN_ON(1);
8094 break;
8095 }
8096
Johannes Berg4c476992010-10-04 21:36:35 +02008097 if (!rdev_ops)
8098 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008099
Johannes Berg4c476992010-10-04 21:36:35 +02008100 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008101}
8102
8103static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8104{
Johannes Berg4c476992010-10-04 21:36:35 +02008105 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8106 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008107
Johannes Berg074ac8d2010-09-16 14:58:22 +02008108 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008109 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8110 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008111
Johannes Berg4c476992010-10-04 21:36:35 +02008112 if (!rdev->ops->flush_pmksa)
8113 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008114
Hila Gonene35e4d22012-06-27 17:19:42 +03008115 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008116}
8117
Arik Nemtsov109086c2011-09-28 14:12:50 +03008118static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8119{
8120 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8121 struct net_device *dev = info->user_ptr[1];
8122 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308123 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008124 u16 status_code;
8125 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008126 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008127
8128 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8129 !rdev->ops->tdls_mgmt)
8130 return -EOPNOTSUPP;
8131
8132 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8133 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8134 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8135 !info->attrs[NL80211_ATTR_IE] ||
8136 !info->attrs[NL80211_ATTR_MAC])
8137 return -EINVAL;
8138
8139 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8140 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8141 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8142 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008143 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308144 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8145 peer_capability =
8146 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008147
Hila Gonene35e4d22012-06-27 17:19:42 +03008148 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308149 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008150 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008151 nla_data(info->attrs[NL80211_ATTR_IE]),
8152 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008153}
8154
8155static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8156{
8157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8158 struct net_device *dev = info->user_ptr[1];
8159 enum nl80211_tdls_operation operation;
8160 u8 *peer;
8161
8162 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8163 !rdev->ops->tdls_oper)
8164 return -EOPNOTSUPP;
8165
8166 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8167 !info->attrs[NL80211_ATTR_MAC])
8168 return -EINVAL;
8169
8170 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8171 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8172
Hila Gonene35e4d22012-06-27 17:19:42 +03008173 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008174}
8175
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008176static int nl80211_remain_on_channel(struct sk_buff *skb,
8177 struct genl_info *info)
8178{
Johannes Berg4c476992010-10-04 21:36:35 +02008179 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008180 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008181 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008182 struct sk_buff *msg;
8183 void *hdr;
8184 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008185 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008186 int err;
8187
8188 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8189 !info->attrs[NL80211_ATTR_DURATION])
8190 return -EINVAL;
8191
8192 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8193
Johannes Berg7c4ef712011-11-18 15:33:48 +01008194 if (!rdev->ops->remain_on_channel ||
8195 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008196 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008197
Johannes Bergebf348f2012-06-01 12:50:54 +02008198 /*
8199 * We should be on that channel for at least a minimum amount of
8200 * time (10ms) but no longer than the driver supports.
8201 */
8202 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8203 duration > rdev->wiphy.max_remain_on_channel_duration)
8204 return -EINVAL;
8205
Johannes Berg683b6d32012-11-08 21:25:48 +01008206 err = nl80211_parse_chandef(rdev, info, &chandef);
8207 if (err)
8208 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008209
8210 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008211 if (!msg)
8212 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008213
Eric W. Biederman15e47302012-09-07 20:12:54 +00008214 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008215 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008216 if (!hdr) {
8217 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008218 goto free_msg;
8219 }
8220
Johannes Berg683b6d32012-11-08 21:25:48 +01008221 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8222 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008223
8224 if (err)
8225 goto free_msg;
8226
David S. Miller9360ffd2012-03-29 04:41:26 -04008227 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8228 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008229
8230 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008231
8232 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008233
8234 nla_put_failure:
8235 err = -ENOBUFS;
8236 free_msg:
8237 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008238 return err;
8239}
8240
8241static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8242 struct genl_info *info)
8243{
Johannes Berg4c476992010-10-04 21:36:35 +02008244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008245 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008246 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008247
8248 if (!info->attrs[NL80211_ATTR_COOKIE])
8249 return -EINVAL;
8250
Johannes Berg4c476992010-10-04 21:36:35 +02008251 if (!rdev->ops->cancel_remain_on_channel)
8252 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008253
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008254 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8255
Hila Gonene35e4d22012-06-27 17:19:42 +03008256 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008257}
8258
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008259static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8260 u8 *rates, u8 rates_len)
8261{
8262 u8 i;
8263 u32 mask = 0;
8264
8265 for (i = 0; i < rates_len; i++) {
8266 int rate = (rates[i] & 0x7f) * 5;
8267 int ridx;
8268 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8269 struct ieee80211_rate *srate =
8270 &sband->bitrates[ridx];
8271 if (rate == srate->bitrate) {
8272 mask |= 1 << ridx;
8273 break;
8274 }
8275 }
8276 if (ridx == sband->n_bitrates)
8277 return 0; /* rate not found */
8278 }
8279
8280 return mask;
8281}
8282
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008283static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8284 u8 *rates, u8 rates_len,
8285 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8286{
8287 u8 i;
8288
8289 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8290
8291 for (i = 0; i < rates_len; i++) {
8292 int ridx, rbit;
8293
8294 ridx = rates[i] / 8;
8295 rbit = BIT(rates[i] % 8);
8296
8297 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008298 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008299 return false;
8300
8301 /* check availability */
8302 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8303 mcs[ridx] |= rbit;
8304 else
8305 return false;
8306 }
8307
8308 return true;
8309}
8310
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008311static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8312{
8313 u16 mcs_mask = 0;
8314
8315 switch (vht_mcs_map) {
8316 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8317 break;
8318 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8319 mcs_mask = 0x00FF;
8320 break;
8321 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8322 mcs_mask = 0x01FF;
8323 break;
8324 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8325 mcs_mask = 0x03FF;
8326 break;
8327 default:
8328 break;
8329 }
8330
8331 return mcs_mask;
8332}
8333
8334static void vht_build_mcs_mask(u16 vht_mcs_map,
8335 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8336{
8337 u8 nss;
8338
8339 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8340 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8341 vht_mcs_map >>= 2;
8342 }
8343}
8344
8345static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8346 struct nl80211_txrate_vht *txrate,
8347 u16 mcs[NL80211_VHT_NSS_MAX])
8348{
8349 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8350 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8351 u8 i;
8352
8353 if (!sband->vht_cap.vht_supported)
8354 return false;
8355
8356 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8357
8358 /* Build vht_mcs_mask from VHT capabilities */
8359 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8360
8361 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8362 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8363 mcs[i] = txrate->mcs[i];
8364 else
8365 return false;
8366 }
8367
8368 return true;
8369}
8370
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008371static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008372 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8373 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008374 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8375 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008376 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008377 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008378};
8379
8380static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8381 struct genl_info *info)
8382{
8383 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008384 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008385 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008386 int rem, i;
8387 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008388 struct nlattr *tx_rates;
8389 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008390 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008391
Johannes Berg4c476992010-10-04 21:36:35 +02008392 if (!rdev->ops->set_bitrate_mask)
8393 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008394
8395 memset(&mask, 0, sizeof(mask));
8396 /* Default to all rates enabled */
8397 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8398 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008399
8400 if (!sband)
8401 continue;
8402
8403 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008404 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008405 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008406 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008407
8408 if (!sband->vht_cap.vht_supported)
8409 continue;
8410
8411 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8412 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008413 }
8414
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008415 /* if no rates are given set it back to the defaults */
8416 if (!info->attrs[NL80211_ATTR_TX_RATES])
8417 goto out;
8418
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008419 /*
8420 * The nested attribute uses enum nl80211_band as the index. This maps
8421 * directly to the enum ieee80211_band values used in cfg80211.
8422 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008423 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008424 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008425 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008426 int err;
8427
Johannes Berg4c476992010-10-04 21:36:35 +02008428 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8429 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008430 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008431 if (sband == NULL)
8432 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008433 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8434 nla_len(tx_rates), nl80211_txattr_policy);
8435 if (err)
8436 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008437 if (tb[NL80211_TXRATE_LEGACY]) {
8438 mask.control[band].legacy = rateset_to_mask(
8439 sband,
8440 nla_data(tb[NL80211_TXRATE_LEGACY]),
8441 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308442 if ((mask.control[band].legacy == 0) &&
8443 nla_len(tb[NL80211_TXRATE_LEGACY]))
8444 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008445 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008446 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008447 if (!ht_rateset_to_mask(
8448 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008449 nla_data(tb[NL80211_TXRATE_HT]),
8450 nla_len(tb[NL80211_TXRATE_HT]),
8451 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008452 return -EINVAL;
8453 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008454 if (tb[NL80211_TXRATE_VHT]) {
8455 if (!vht_set_mcs_mask(
8456 sband,
8457 nla_data(tb[NL80211_TXRATE_VHT]),
8458 mask.control[band].vht_mcs))
8459 return -EINVAL;
8460 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008461 if (tb[NL80211_TXRATE_GI]) {
8462 mask.control[band].gi =
8463 nla_get_u8(tb[NL80211_TXRATE_GI]);
8464 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8465 return -EINVAL;
8466 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008467
8468 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008469 /* don't allow empty legacy rates if HT or VHT
8470 * are not even supported.
8471 */
8472 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8473 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008474 return -EINVAL;
8475
8476 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008477 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008478 goto out;
8479
8480 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8481 if (mask.control[band].vht_mcs[i])
8482 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008483
8484 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008485 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008486 }
8487 }
8488
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008489out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008490 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008491}
8492
Johannes Berg2e161f72010-08-12 15:38:38 +02008493static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008494{
Johannes Berg4c476992010-10-04 21:36:35 +02008495 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008496 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008497 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008498
8499 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8500 return -EINVAL;
8501
Johannes Berg2e161f72010-08-12 15:38:38 +02008502 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8503 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008504
Johannes Berg71bbc992012-06-15 15:30:18 +02008505 switch (wdev->iftype) {
8506 case NL80211_IFTYPE_STATION:
8507 case NL80211_IFTYPE_ADHOC:
8508 case NL80211_IFTYPE_P2P_CLIENT:
8509 case NL80211_IFTYPE_AP:
8510 case NL80211_IFTYPE_AP_VLAN:
8511 case NL80211_IFTYPE_MESH_POINT:
8512 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008513 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008514 break;
8515 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008516 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008517 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008518
8519 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008520 if (!rdev->ops->mgmt_tx)
8521 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008522
Eric W. Biederman15e47302012-09-07 20:12:54 +00008523 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008524 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8525 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008526}
8527
Johannes Berg2e161f72010-08-12 15:38:38 +02008528static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008529{
Johannes Berg4c476992010-10-04 21:36:35 +02008530 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008531 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008532 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008533 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008534 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008535 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008536 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008537 struct cfg80211_mgmt_tx_params params = {
8538 .dont_wait_for_ack =
8539 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8540 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008541
Johannes Berg683b6d32012-11-08 21:25:48 +01008542 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008543 return -EINVAL;
8544
Johannes Berg4c476992010-10-04 21:36:35 +02008545 if (!rdev->ops->mgmt_tx)
8546 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008547
Johannes Berg71bbc992012-06-15 15:30:18 +02008548 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008549 case NL80211_IFTYPE_P2P_DEVICE:
8550 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8551 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008552 case NL80211_IFTYPE_STATION:
8553 case NL80211_IFTYPE_ADHOC:
8554 case NL80211_IFTYPE_P2P_CLIENT:
8555 case NL80211_IFTYPE_AP:
8556 case NL80211_IFTYPE_AP_VLAN:
8557 case NL80211_IFTYPE_MESH_POINT:
8558 case NL80211_IFTYPE_P2P_GO:
8559 break;
8560 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008561 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008562 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008563
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008564 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008565 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008566 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008567 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008568
8569 /*
8570 * We should wait on the channel for at least a minimum amount
8571 * of time (10ms) but no longer than the driver supports.
8572 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008573 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8574 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008575 return -EINVAL;
8576
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008577 }
8578
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008579 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008580
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008581 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008582 return -EINVAL;
8583
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008584 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308585
Antonio Quartulliea141b752013-06-11 14:20:03 +02008586 /* get the channel if any has been specified, otherwise pass NULL to
8587 * the driver. The latter will use the current one
8588 */
8589 chandef.chan = NULL;
8590 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8591 err = nl80211_parse_chandef(rdev, info, &chandef);
8592 if (err)
8593 return err;
8594 }
8595
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008596 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008597 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008598
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008599 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8600 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8601
8602 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8603 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8604 int i;
8605
8606 if (len % sizeof(u16))
8607 return -EINVAL;
8608
8609 params.n_csa_offsets = len / sizeof(u16);
8610 params.csa_offsets =
8611 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8612
8613 /* check that all the offsets fit the frame */
8614 for (i = 0; i < params.n_csa_offsets; i++) {
8615 if (params.csa_offsets[i] >= params.len)
8616 return -EINVAL;
8617 }
8618 }
8619
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008620 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008621 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8622 if (!msg)
8623 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008624
Eric W. Biederman15e47302012-09-07 20:12:54 +00008625 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008626 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008627 if (!hdr) {
8628 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008629 goto free_msg;
8630 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008631 }
Johannes Berge247bd902011-11-04 11:18:21 +01008632
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008633 params.chan = chandef.chan;
8634 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008635 if (err)
8636 goto free_msg;
8637
Johannes Berge247bd902011-11-04 11:18:21 +01008638 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008639 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8640 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008641
Johannes Berge247bd902011-11-04 11:18:21 +01008642 genlmsg_end(msg, hdr);
8643 return genlmsg_reply(msg, info);
8644 }
8645
8646 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008647
8648 nla_put_failure:
8649 err = -ENOBUFS;
8650 free_msg:
8651 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008652 return err;
8653}
8654
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008655static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8656{
8657 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008658 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008659 u64 cookie;
8660
8661 if (!info->attrs[NL80211_ATTR_COOKIE])
8662 return -EINVAL;
8663
8664 if (!rdev->ops->mgmt_tx_cancel_wait)
8665 return -EOPNOTSUPP;
8666
Johannes Berg71bbc992012-06-15 15:30:18 +02008667 switch (wdev->iftype) {
8668 case NL80211_IFTYPE_STATION:
8669 case NL80211_IFTYPE_ADHOC:
8670 case NL80211_IFTYPE_P2P_CLIENT:
8671 case NL80211_IFTYPE_AP:
8672 case NL80211_IFTYPE_AP_VLAN:
8673 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008674 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008675 break;
8676 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008677 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008678 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008679
8680 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8681
Hila Gonene35e4d22012-06-27 17:19:42 +03008682 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008683}
8684
Kalle Valoffb9eb32010-02-17 17:58:10 +02008685static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8686{
Johannes Berg4c476992010-10-04 21:36:35 +02008687 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008688 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008689 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008690 u8 ps_state;
8691 bool state;
8692 int err;
8693
Johannes Berg4c476992010-10-04 21:36:35 +02008694 if (!info->attrs[NL80211_ATTR_PS_STATE])
8695 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008696
8697 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8698
Johannes Berg4c476992010-10-04 21:36:35 +02008699 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8700 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008701
8702 wdev = dev->ieee80211_ptr;
8703
Johannes Berg4c476992010-10-04 21:36:35 +02008704 if (!rdev->ops->set_power_mgmt)
8705 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008706
8707 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8708
8709 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008710 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008711
Hila Gonene35e4d22012-06-27 17:19:42 +03008712 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008713 if (!err)
8714 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008715 return err;
8716}
8717
8718static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8719{
Johannes Berg4c476992010-10-04 21:36:35 +02008720 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008721 enum nl80211_ps_state ps_state;
8722 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008723 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008724 struct sk_buff *msg;
8725 void *hdr;
8726 int err;
8727
Kalle Valoffb9eb32010-02-17 17:58:10 +02008728 wdev = dev->ieee80211_ptr;
8729
Johannes Berg4c476992010-10-04 21:36:35 +02008730 if (!rdev->ops->set_power_mgmt)
8731 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008732
8733 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008734 if (!msg)
8735 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008736
Eric W. Biederman15e47302012-09-07 20:12:54 +00008737 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008738 NL80211_CMD_GET_POWER_SAVE);
8739 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008740 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008741 goto free_msg;
8742 }
8743
8744 if (wdev->ps)
8745 ps_state = NL80211_PS_ENABLED;
8746 else
8747 ps_state = NL80211_PS_DISABLED;
8748
David S. Miller9360ffd2012-03-29 04:41:26 -04008749 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8750 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008751
8752 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008753 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008754
Johannes Berg4c476992010-10-04 21:36:35 +02008755 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008756 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008757 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008758 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008759 return err;
8760}
8761
Johannes Berg94e860f2014-01-20 23:58:15 +01008762static const struct nla_policy
8763nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008764 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8765 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8766 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008767 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8768 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8769 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008770};
8771
Thomas Pedersen84f10702012-07-12 16:17:33 -07008772static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008773 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008774{
8775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008776 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008777 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008778
Johannes Bergd9d8b012012-11-26 12:51:52 +01008779 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008780 return -EINVAL;
8781
Thomas Pedersen84f10702012-07-12 16:17:33 -07008782 if (!rdev->ops->set_cqm_txe_config)
8783 return -EOPNOTSUPP;
8784
8785 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8786 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8787 return -EOPNOTSUPP;
8788
Hila Gonene35e4d22012-06-27 17:19:42 +03008789 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008790}
8791
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008792static int nl80211_set_cqm_rssi(struct genl_info *info,
8793 s32 threshold, u32 hysteresis)
8794{
Johannes Berg4c476992010-10-04 21:36:35 +02008795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008796 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008797 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008798
8799 if (threshold > 0)
8800 return -EINVAL;
8801
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008802 /* disabling - hysteresis should also be zero then */
8803 if (threshold == 0)
8804 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008805
Johannes Berg4c476992010-10-04 21:36:35 +02008806 if (!rdev->ops->set_cqm_rssi_config)
8807 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008808
Johannes Berg074ac8d2010-09-16 14:58:22 +02008809 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008810 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8811 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008812
Hila Gonene35e4d22012-06-27 17:19:42 +03008813 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008814}
8815
8816static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8817{
8818 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8819 struct nlattr *cqm;
8820 int err;
8821
8822 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008823 if (!cqm)
8824 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008825
8826 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8827 nl80211_attr_cqm_policy);
8828 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008829 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008830
8831 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8832 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008833 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8834 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008835
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008836 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8837 }
8838
8839 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8840 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8841 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8842 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8843 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8844 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8845
8846 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8847 }
8848
8849 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008850}
8851
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008852static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8853{
8854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8855 struct net_device *dev = info->user_ptr[1];
8856 struct ocb_setup setup = {};
8857 int err;
8858
8859 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8860 if (err)
8861 return err;
8862
8863 return cfg80211_join_ocb(rdev, dev, &setup);
8864}
8865
8866static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8867{
8868 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8869 struct net_device *dev = info->user_ptr[1];
8870
8871 return cfg80211_leave_ocb(rdev, dev);
8872}
8873
Johannes Berg29cbe682010-12-03 09:20:44 +01008874static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8875{
8876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8877 struct net_device *dev = info->user_ptr[1];
8878 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008879 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008880 int err;
8881
8882 /* start with default */
8883 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008884 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008885
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008886 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008887 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008888 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008889 if (err)
8890 return err;
8891 }
8892
8893 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8894 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8895 return -EINVAL;
8896
Javier Cardonac80d5452010-12-16 17:37:49 -08008897 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8898 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8899
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008900 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8901 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8902 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8903 return -EINVAL;
8904
Marco Porsch9bdbf042013-01-07 16:04:51 +01008905 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8906 setup.beacon_interval =
8907 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8908 if (setup.beacon_interval < 10 ||
8909 setup.beacon_interval > 10000)
8910 return -EINVAL;
8911 }
8912
8913 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8914 setup.dtim_period =
8915 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8916 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8917 return -EINVAL;
8918 }
8919
Javier Cardonac80d5452010-12-16 17:37:49 -08008920 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8921 /* parse additional setup parameters if given */
8922 err = nl80211_parse_mesh_setup(info, &setup);
8923 if (err)
8924 return err;
8925 }
8926
Thomas Pedersend37bb182013-03-04 13:06:13 -08008927 if (setup.user_mpm)
8928 cfg.auto_open_plinks = false;
8929
Johannes Bergcc1d2802012-05-16 23:50:20 +02008930 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008931 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8932 if (err)
8933 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008934 } else {
8935 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008936 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008937 }
8938
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008939 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8940 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8941 int n_rates =
8942 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8943 struct ieee80211_supported_band *sband;
8944
8945 if (!setup.chandef.chan)
8946 return -EINVAL;
8947
8948 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8949
8950 err = ieee80211_get_ratemask(sband, rates, n_rates,
8951 &setup.basic_rates);
8952 if (err)
8953 return err;
8954 }
8955
Javier Cardonac80d5452010-12-16 17:37:49 -08008956 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008957}
8958
8959static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8960{
8961 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8962 struct net_device *dev = info->user_ptr[1];
8963
8964 return cfg80211_leave_mesh(rdev, dev);
8965}
8966
Johannes Bergdfb89c52012-06-27 09:23:48 +02008967#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008968static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8969 struct cfg80211_registered_device *rdev)
8970{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008971 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008972 struct nlattr *nl_pats, *nl_pat;
8973 int i, pat_len;
8974
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008975 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008976 return 0;
8977
8978 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8979 if (!nl_pats)
8980 return -ENOBUFS;
8981
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008982 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008983 nl_pat = nla_nest_start(msg, i + 1);
8984 if (!nl_pat)
8985 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008986 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008987 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008988 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008989 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8990 wowlan->patterns[i].pattern) ||
8991 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008992 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008993 return -ENOBUFS;
8994 nla_nest_end(msg, nl_pat);
8995 }
8996 nla_nest_end(msg, nl_pats);
8997
8998 return 0;
8999}
9000
Johannes Berg2a0e0472013-01-23 22:57:40 +01009001static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
9002 struct cfg80211_wowlan_tcp *tcp)
9003{
9004 struct nlattr *nl_tcp;
9005
9006 if (!tcp)
9007 return 0;
9008
9009 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
9010 if (!nl_tcp)
9011 return -ENOBUFS;
9012
Jiri Benc930345e2015-03-29 16:59:25 +02009013 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
9014 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01009015 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
9016 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
9017 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
9018 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
9019 tcp->payload_len, tcp->payload) ||
9020 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
9021 tcp->data_interval) ||
9022 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
9023 tcp->wake_len, tcp->wake_data) ||
9024 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
9025 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
9026 return -ENOBUFS;
9027
9028 if (tcp->payload_seq.len &&
9029 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
9030 sizeof(tcp->payload_seq), &tcp->payload_seq))
9031 return -ENOBUFS;
9032
9033 if (tcp->payload_tok.len &&
9034 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
9035 sizeof(tcp->payload_tok) + tcp->tokens_size,
9036 &tcp->payload_tok))
9037 return -ENOBUFS;
9038
Johannes Berge248ad32013-05-16 10:24:28 +02009039 nla_nest_end(msg, nl_tcp);
9040
Johannes Berg2a0e0472013-01-23 22:57:40 +01009041 return 0;
9042}
9043
Luciano Coelho75453cc2015-01-09 14:06:37 +02009044static int nl80211_send_wowlan_nd(struct sk_buff *msg,
9045 struct cfg80211_sched_scan_request *req)
9046{
Avraham Stern3b06d272015-10-12 09:51:34 +03009047 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02009048 int i;
9049
9050 if (!req)
9051 return 0;
9052
9053 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9054 if (!nd)
9055 return -ENOBUFS;
9056
Avraham Stern3b06d272015-10-12 09:51:34 +03009057 if (req->n_scan_plans == 1 &&
9058 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9059 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009060 return -ENOBUFS;
9061
Luciano Coelho21fea562015-03-17 16:36:01 +02009062 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9063 return -ENOBUFS;
9064
Luciano Coelho75453cc2015-01-09 14:06:37 +02009065 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9066 if (!freqs)
9067 return -ENOBUFS;
9068
9069 for (i = 0; i < req->n_channels; i++)
9070 nla_put_u32(msg, i, req->channels[i]->center_freq);
9071
9072 nla_nest_end(msg, freqs);
9073
9074 if (req->n_match_sets) {
9075 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9076 for (i = 0; i < req->n_match_sets; i++) {
9077 match = nla_nest_start(msg, i);
9078 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9079 req->match_sets[i].ssid.ssid_len,
9080 req->match_sets[i].ssid.ssid);
9081 nla_nest_end(msg, match);
9082 }
9083 nla_nest_end(msg, matches);
9084 }
9085
Avraham Stern3b06d272015-10-12 09:51:34 +03009086 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9087 if (!scan_plans)
9088 return -ENOBUFS;
9089
9090 for (i = 0; i < req->n_scan_plans; i++) {
9091 scan_plan = nla_nest_start(msg, i + 1);
9092 if (!scan_plan ||
9093 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9094 req->scan_plans[i].interval) ||
9095 (req->scan_plans[i].iterations &&
9096 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9097 req->scan_plans[i].iterations)))
9098 return -ENOBUFS;
9099 nla_nest_end(msg, scan_plan);
9100 }
9101 nla_nest_end(msg, scan_plans);
9102
Luciano Coelho75453cc2015-01-09 14:06:37 +02009103 nla_nest_end(msg, nd);
9104
9105 return 0;
9106}
9107
Johannes Bergff1b6e62011-05-04 15:37:28 +02009108static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9109{
9110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9111 struct sk_buff *msg;
9112 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009113 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009114
Johannes Berg964dc9e2013-06-03 17:25:34 +02009115 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009116 return -EOPNOTSUPP;
9117
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009118 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009119 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009120 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9121 rdev->wiphy.wowlan_config->tcp->payload_len +
9122 rdev->wiphy.wowlan_config->tcp->wake_len +
9123 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009124 }
9125
9126 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009127 if (!msg)
9128 return -ENOMEM;
9129
Eric W. Biederman15e47302012-09-07 20:12:54 +00009130 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009131 NL80211_CMD_GET_WOWLAN);
9132 if (!hdr)
9133 goto nla_put_failure;
9134
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009135 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009136 struct nlattr *nl_wowlan;
9137
9138 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9139 if (!nl_wowlan)
9140 goto nla_put_failure;
9141
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009142 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009143 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009144 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009145 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009146 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009147 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009148 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009149 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009150 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009151 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009152 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009153 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009154 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009155 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9156 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009157
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009158 if (nl80211_send_wowlan_patterns(msg, rdev))
9159 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009160
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009161 if (nl80211_send_wowlan_tcp(msg,
9162 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009163 goto nla_put_failure;
9164
Luciano Coelho75453cc2015-01-09 14:06:37 +02009165 if (nl80211_send_wowlan_nd(
9166 msg,
9167 rdev->wiphy.wowlan_config->nd_config))
9168 goto nla_put_failure;
9169
Johannes Bergff1b6e62011-05-04 15:37:28 +02009170 nla_nest_end(msg, nl_wowlan);
9171 }
9172
9173 genlmsg_end(msg, hdr);
9174 return genlmsg_reply(msg, info);
9175
9176nla_put_failure:
9177 nlmsg_free(msg);
9178 return -ENOBUFS;
9179}
9180
Johannes Berg2a0e0472013-01-23 22:57:40 +01009181static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9182 struct nlattr *attr,
9183 struct cfg80211_wowlan *trig)
9184{
9185 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9186 struct cfg80211_wowlan_tcp *cfg;
9187 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9188 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9189 u32 size;
9190 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9191 int err, port;
9192
Johannes Berg964dc9e2013-06-03 17:25:34 +02009193 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009194 return -EINVAL;
9195
9196 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9197 nla_data(attr), nla_len(attr),
9198 nl80211_wowlan_tcp_policy);
9199 if (err)
9200 return err;
9201
9202 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9203 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9204 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9205 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9206 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9207 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9208 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9209 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9210 return -EINVAL;
9211
9212 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009213 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009214 return -EINVAL;
9215
9216 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009217 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009218 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009219 return -EINVAL;
9220
9221 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009222 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009223 return -EINVAL;
9224
9225 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9226 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9227 return -EINVAL;
9228
9229 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9230 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9231
9232 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9233 tokens_size = tokln - sizeof(*tok);
9234
9235 if (!tok->len || tokens_size % tok->len)
9236 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009237 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009238 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009239 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009240 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009241 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009242 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009243 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009244 return -EINVAL;
9245 if (tok->offset + tok->len > data_size)
9246 return -EINVAL;
9247 }
9248
9249 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9250 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009251 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009252 return -EINVAL;
9253 if (seq->len == 0 || seq->len > 4)
9254 return -EINVAL;
9255 if (seq->len + seq->offset > data_size)
9256 return -EINVAL;
9257 }
9258
9259 size = sizeof(*cfg);
9260 size += data_size;
9261 size += wake_size + wake_mask_size;
9262 size += tokens_size;
9263
9264 cfg = kzalloc(size, GFP_KERNEL);
9265 if (!cfg)
9266 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009267 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9268 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009269 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9270 ETH_ALEN);
9271 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9272 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9273 else
9274 port = 0;
9275#ifdef CONFIG_INET
9276 /* allocate a socket and port for it and use it */
9277 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9278 IPPROTO_TCP, &cfg->sock, 1);
9279 if (err) {
9280 kfree(cfg);
9281 return err;
9282 }
9283 if (inet_csk_get_port(cfg->sock->sk, port)) {
9284 sock_release(cfg->sock);
9285 kfree(cfg);
9286 return -EADDRINUSE;
9287 }
9288 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9289#else
9290 if (!port) {
9291 kfree(cfg);
9292 return -EINVAL;
9293 }
9294 cfg->src_port = port;
9295#endif
9296
9297 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9298 cfg->payload_len = data_size;
9299 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9300 memcpy((void *)cfg->payload,
9301 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9302 data_size);
9303 if (seq)
9304 cfg->payload_seq = *seq;
9305 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9306 cfg->wake_len = wake_size;
9307 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9308 memcpy((void *)cfg->wake_data,
9309 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9310 wake_size);
9311 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9312 data_size + wake_size;
9313 memcpy((void *)cfg->wake_mask,
9314 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9315 wake_mask_size);
9316 if (tok) {
9317 cfg->tokens_size = tokens_size;
9318 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9319 }
9320
9321 trig->tcp = cfg;
9322
9323 return 0;
9324}
9325
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009326static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9327 const struct wiphy_wowlan_support *wowlan,
9328 struct nlattr *attr,
9329 struct cfg80211_wowlan *trig)
9330{
9331 struct nlattr **tb;
9332 int err;
9333
9334 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9335 if (!tb)
9336 return -ENOMEM;
9337
9338 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9339 err = -EOPNOTSUPP;
9340 goto out;
9341 }
9342
9343 err = nla_parse(tb, NL80211_ATTR_MAX,
9344 nla_data(attr), nla_len(attr),
9345 nl80211_policy);
9346 if (err)
9347 goto out;
9348
Johannes Bergad2b26a2014-06-12 21:39:05 +02009349 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009350 err = PTR_ERR_OR_ZERO(trig->nd_config);
9351 if (err)
9352 trig->nd_config = NULL;
9353
9354out:
9355 kfree(tb);
9356 return err;
9357}
9358
Johannes Bergff1b6e62011-05-04 15:37:28 +02009359static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9360{
9361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9362 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009363 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009364 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009365 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009366 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009367 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009368 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009369
Johannes Berg964dc9e2013-06-03 17:25:34 +02009370 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009371 return -EOPNOTSUPP;
9372
Johannes Bergae33bd82012-07-12 16:25:02 +02009373 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9374 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009375 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009376 goto set_wakeup;
9377 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009378
9379 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9380 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9381 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9382 nl80211_wowlan_policy);
9383 if (err)
9384 return err;
9385
9386 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9387 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9388 return -EINVAL;
9389 new_triggers.any = true;
9390 }
9391
9392 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9393 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9394 return -EINVAL;
9395 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009396 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009397 }
9398
9399 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9400 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9401 return -EINVAL;
9402 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009403 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009404 }
9405
Johannes Berg77dbbb12011-07-13 10:48:55 +02009406 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9407 return -EINVAL;
9408
9409 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9410 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9411 return -EINVAL;
9412 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009413 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009414 }
9415
9416 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9417 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9418 return -EINVAL;
9419 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009420 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009421 }
9422
9423 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9424 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9425 return -EINVAL;
9426 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009427 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009428 }
9429
9430 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9431 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9432 return -EINVAL;
9433 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009434 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009435 }
9436
Johannes Bergff1b6e62011-05-04 15:37:28 +02009437 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9438 struct nlattr *pat;
9439 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009440 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009441 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009442
Johannes Berg98fc4382015-03-01 09:10:13 +02009443 regular = true;
9444
Johannes Bergff1b6e62011-05-04 15:37:28 +02009445 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9446 rem)
9447 n_patterns++;
9448 if (n_patterns > wowlan->n_patterns)
9449 return -EINVAL;
9450
9451 new_triggers.patterns = kcalloc(n_patterns,
9452 sizeof(new_triggers.patterns[0]),
9453 GFP_KERNEL);
9454 if (!new_triggers.patterns)
9455 return -ENOMEM;
9456
9457 new_triggers.n_patterns = n_patterns;
9458 i = 0;
9459
9460 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9461 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009462 u8 *mask_pat;
9463
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009464 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9465 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009466 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009467 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9468 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009469 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009470 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009471 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009472 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009473 goto error;
9474 if (pat_len > wowlan->pattern_max_len ||
9475 pat_len < wowlan->pattern_min_len)
9476 goto error;
9477
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009478 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009479 pkt_offset = 0;
9480 else
9481 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009482 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009483 if (pkt_offset > wowlan->max_pkt_offset)
9484 goto error;
9485 new_triggers.patterns[i].pkt_offset = pkt_offset;
9486
Johannes Berg922bd802014-05-19 17:59:50 +02009487 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9488 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009489 err = -ENOMEM;
9490 goto error;
9491 }
Johannes Berg922bd802014-05-19 17:59:50 +02009492 new_triggers.patterns[i].mask = mask_pat;
9493 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009494 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009495 mask_pat += mask_len;
9496 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009497 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009498 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009499 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009500 pat_len);
9501 i++;
9502 }
9503 }
9504
Johannes Berg2a0e0472013-01-23 22:57:40 +01009505 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009506 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009507 err = nl80211_parse_wowlan_tcp(
9508 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9509 &new_triggers);
9510 if (err)
9511 goto error;
9512 }
9513
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009514 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009515 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009516 err = nl80211_parse_wowlan_nd(
9517 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9518 &new_triggers);
9519 if (err)
9520 goto error;
9521 }
9522
Johannes Berg98fc4382015-03-01 09:10:13 +02009523 /* The 'any' trigger means the device continues operating more or less
9524 * as in its normal operation mode and wakes up the host on most of the
9525 * normal interrupts (like packet RX, ...)
9526 * It therefore makes little sense to combine with the more constrained
9527 * wakeup trigger modes.
9528 */
9529 if (new_triggers.any && regular) {
9530 err = -EINVAL;
9531 goto error;
9532 }
9533
Johannes Bergae33bd82012-07-12 16:25:02 +02009534 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9535 if (!ntrig) {
9536 err = -ENOMEM;
9537 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009538 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009539 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009540 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009541
Johannes Bergae33bd82012-07-12 16:25:02 +02009542 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009543 if (rdev->ops->set_wakeup &&
9544 prev_enabled != !!rdev->wiphy.wowlan_config)
9545 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009546
Johannes Bergff1b6e62011-05-04 15:37:28 +02009547 return 0;
9548 error:
9549 for (i = 0; i < new_triggers.n_patterns; i++)
9550 kfree(new_triggers.patterns[i].mask);
9551 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009552 if (new_triggers.tcp && new_triggers.tcp->sock)
9553 sock_release(new_triggers.tcp->sock);
9554 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009555 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009556 return err;
9557}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009558#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009559
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009560static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9561 struct cfg80211_registered_device *rdev)
9562{
9563 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9564 int i, j, pat_len;
9565 struct cfg80211_coalesce_rules *rule;
9566
9567 if (!rdev->coalesce->n_rules)
9568 return 0;
9569
9570 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9571 if (!nl_rules)
9572 return -ENOBUFS;
9573
9574 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9575 nl_rule = nla_nest_start(msg, i + 1);
9576 if (!nl_rule)
9577 return -ENOBUFS;
9578
9579 rule = &rdev->coalesce->rules[i];
9580 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9581 rule->delay))
9582 return -ENOBUFS;
9583
9584 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9585 rule->condition))
9586 return -ENOBUFS;
9587
9588 nl_pats = nla_nest_start(msg,
9589 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9590 if (!nl_pats)
9591 return -ENOBUFS;
9592
9593 for (j = 0; j < rule->n_patterns; j++) {
9594 nl_pat = nla_nest_start(msg, j + 1);
9595 if (!nl_pat)
9596 return -ENOBUFS;
9597 pat_len = rule->patterns[j].pattern_len;
9598 if (nla_put(msg, NL80211_PKTPAT_MASK,
9599 DIV_ROUND_UP(pat_len, 8),
9600 rule->patterns[j].mask) ||
9601 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9602 rule->patterns[j].pattern) ||
9603 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9604 rule->patterns[j].pkt_offset))
9605 return -ENOBUFS;
9606 nla_nest_end(msg, nl_pat);
9607 }
9608 nla_nest_end(msg, nl_pats);
9609 nla_nest_end(msg, nl_rule);
9610 }
9611 nla_nest_end(msg, nl_rules);
9612
9613 return 0;
9614}
9615
9616static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9617{
9618 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9619 struct sk_buff *msg;
9620 void *hdr;
9621
9622 if (!rdev->wiphy.coalesce)
9623 return -EOPNOTSUPP;
9624
9625 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9626 if (!msg)
9627 return -ENOMEM;
9628
9629 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9630 NL80211_CMD_GET_COALESCE);
9631 if (!hdr)
9632 goto nla_put_failure;
9633
9634 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9635 goto nla_put_failure;
9636
9637 genlmsg_end(msg, hdr);
9638 return genlmsg_reply(msg, info);
9639
9640nla_put_failure:
9641 nlmsg_free(msg);
9642 return -ENOBUFS;
9643}
9644
9645void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9646{
9647 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9648 int i, j;
9649 struct cfg80211_coalesce_rules *rule;
9650
9651 if (!coalesce)
9652 return;
9653
9654 for (i = 0; i < coalesce->n_rules; i++) {
9655 rule = &coalesce->rules[i];
9656 for (j = 0; j < rule->n_patterns; j++)
9657 kfree(rule->patterns[j].mask);
9658 kfree(rule->patterns);
9659 }
9660 kfree(coalesce->rules);
9661 kfree(coalesce);
9662 rdev->coalesce = NULL;
9663}
9664
9665static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9666 struct nlattr *rule,
9667 struct cfg80211_coalesce_rules *new_rule)
9668{
9669 int err, i;
9670 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9671 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9672 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9673 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9674
9675 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9676 nla_len(rule), nl80211_coalesce_policy);
9677 if (err)
9678 return err;
9679
9680 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9681 new_rule->delay =
9682 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9683 if (new_rule->delay > coalesce->max_delay)
9684 return -EINVAL;
9685
9686 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9687 new_rule->condition =
9688 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9689 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9690 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9691 return -EINVAL;
9692
9693 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9694 return -EINVAL;
9695
9696 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9697 rem)
9698 n_patterns++;
9699 if (n_patterns > coalesce->n_patterns)
9700 return -EINVAL;
9701
9702 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9703 GFP_KERNEL);
9704 if (!new_rule->patterns)
9705 return -ENOMEM;
9706
9707 new_rule->n_patterns = n_patterns;
9708 i = 0;
9709
9710 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9711 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009712 u8 *mask_pat;
9713
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009714 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9715 nla_len(pat), NULL);
9716 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9717 !pat_tb[NL80211_PKTPAT_PATTERN])
9718 return -EINVAL;
9719 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9720 mask_len = DIV_ROUND_UP(pat_len, 8);
9721 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9722 return -EINVAL;
9723 if (pat_len > coalesce->pattern_max_len ||
9724 pat_len < coalesce->pattern_min_len)
9725 return -EINVAL;
9726
9727 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9728 pkt_offset = 0;
9729 else
9730 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9731 if (pkt_offset > coalesce->max_pkt_offset)
9732 return -EINVAL;
9733 new_rule->patterns[i].pkt_offset = pkt_offset;
9734
Johannes Berg922bd802014-05-19 17:59:50 +02009735 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9736 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009737 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009738
9739 new_rule->patterns[i].mask = mask_pat;
9740 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9741 mask_len);
9742
9743 mask_pat += mask_len;
9744 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009745 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009746 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9747 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009748 i++;
9749 }
9750
9751 return 0;
9752}
9753
9754static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9755{
9756 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9757 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9758 struct cfg80211_coalesce new_coalesce = {};
9759 struct cfg80211_coalesce *n_coalesce;
9760 int err, rem_rule, n_rules = 0, i, j;
9761 struct nlattr *rule;
9762 struct cfg80211_coalesce_rules *tmp_rule;
9763
9764 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9765 return -EOPNOTSUPP;
9766
9767 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9768 cfg80211_rdev_free_coalesce(rdev);
Ilan Peera1056b12015-10-22 22:27:46 +03009769 rdev_set_coalesce(rdev, NULL);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009770 return 0;
9771 }
9772
9773 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9774 rem_rule)
9775 n_rules++;
9776 if (n_rules > coalesce->n_rules)
9777 return -EINVAL;
9778
9779 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9780 GFP_KERNEL);
9781 if (!new_coalesce.rules)
9782 return -ENOMEM;
9783
9784 new_coalesce.n_rules = n_rules;
9785 i = 0;
9786
9787 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9788 rem_rule) {
9789 err = nl80211_parse_coalesce_rule(rdev, rule,
9790 &new_coalesce.rules[i]);
9791 if (err)
9792 goto error;
9793
9794 i++;
9795 }
9796
Ilan Peera1056b12015-10-22 22:27:46 +03009797 err = rdev_set_coalesce(rdev, &new_coalesce);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009798 if (err)
9799 goto error;
9800
9801 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9802 if (!n_coalesce) {
9803 err = -ENOMEM;
9804 goto error;
9805 }
9806 cfg80211_rdev_free_coalesce(rdev);
9807 rdev->coalesce = n_coalesce;
9808
9809 return 0;
9810error:
9811 for (i = 0; i < new_coalesce.n_rules; i++) {
9812 tmp_rule = &new_coalesce.rules[i];
9813 for (j = 0; j < tmp_rule->n_patterns; j++)
9814 kfree(tmp_rule->patterns[j].mask);
9815 kfree(tmp_rule->patterns);
9816 }
9817 kfree(new_coalesce.rules);
9818
9819 return err;
9820}
9821
Johannes Berge5497d72011-07-05 16:35:40 +02009822static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9823{
9824 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9825 struct net_device *dev = info->user_ptr[1];
9826 struct wireless_dev *wdev = dev->ieee80211_ptr;
9827 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9828 struct cfg80211_gtk_rekey_data rekey_data;
9829 int err;
9830
9831 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9832 return -EINVAL;
9833
9834 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9835 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9836 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9837 nl80211_rekey_policy);
9838 if (err)
9839 return err;
9840
9841 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9842 return -ERANGE;
9843 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9844 return -ERANGE;
9845 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9846 return -ERANGE;
9847
Johannes Berg78f686c2014-09-10 22:28:06 +03009848 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9849 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9850 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009851
9852 wdev_lock(wdev);
9853 if (!wdev->current_bss) {
9854 err = -ENOTCONN;
9855 goto out;
9856 }
9857
9858 if (!rdev->ops->set_rekey_data) {
9859 err = -EOPNOTSUPP;
9860 goto out;
9861 }
9862
Hila Gonene35e4d22012-06-27 17:19:42 +03009863 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009864 out:
9865 wdev_unlock(wdev);
9866 return err;
9867}
9868
Johannes Berg28946da2011-11-04 11:18:12 +01009869static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9870 struct genl_info *info)
9871{
9872 struct net_device *dev = info->user_ptr[1];
9873 struct wireless_dev *wdev = dev->ieee80211_ptr;
9874
9875 if (wdev->iftype != NL80211_IFTYPE_AP &&
9876 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9877 return -EINVAL;
9878
Eric W. Biederman15e47302012-09-07 20:12:54 +00009879 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009880 return -EBUSY;
9881
Eric W. Biederman15e47302012-09-07 20:12:54 +00009882 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009883 return 0;
9884}
9885
Johannes Berg7f6cf312011-11-04 11:18:15 +01009886static int nl80211_probe_client(struct sk_buff *skb,
9887 struct genl_info *info)
9888{
9889 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9890 struct net_device *dev = info->user_ptr[1];
9891 struct wireless_dev *wdev = dev->ieee80211_ptr;
9892 struct sk_buff *msg;
9893 void *hdr;
9894 const u8 *addr;
9895 u64 cookie;
9896 int err;
9897
9898 if (wdev->iftype != NL80211_IFTYPE_AP &&
9899 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9900 return -EOPNOTSUPP;
9901
9902 if (!info->attrs[NL80211_ATTR_MAC])
9903 return -EINVAL;
9904
9905 if (!rdev->ops->probe_client)
9906 return -EOPNOTSUPP;
9907
9908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9909 if (!msg)
9910 return -ENOMEM;
9911
Eric W. Biederman15e47302012-09-07 20:12:54 +00009912 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009913 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009914 if (!hdr) {
9915 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009916 goto free_msg;
9917 }
9918
9919 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9920
Hila Gonene35e4d22012-06-27 17:19:42 +03009921 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009922 if (err)
9923 goto free_msg;
9924
David S. Miller9360ffd2012-03-29 04:41:26 -04009925 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9926 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009927
9928 genlmsg_end(msg, hdr);
9929
9930 return genlmsg_reply(msg, info);
9931
9932 nla_put_failure:
9933 err = -ENOBUFS;
9934 free_msg:
9935 nlmsg_free(msg);
9936 return err;
9937}
9938
Johannes Berg5e760232011-11-04 11:18:17 +01009939static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9940{
9941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009942 struct cfg80211_beacon_registration *reg, *nreg;
9943 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009944
9945 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9946 return -EOPNOTSUPP;
9947
Ben Greear37c73b52012-10-26 14:49:25 -07009948 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9949 if (!nreg)
9950 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009951
Ben Greear37c73b52012-10-26 14:49:25 -07009952 /* First, check if already registered. */
9953 spin_lock_bh(&rdev->beacon_registrations_lock);
9954 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9955 if (reg->nlportid == info->snd_portid) {
9956 rv = -EALREADY;
9957 goto out_err;
9958 }
9959 }
9960 /* Add it to the list */
9961 nreg->nlportid = info->snd_portid;
9962 list_add(&nreg->list, &rdev->beacon_registrations);
9963
9964 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009965
9966 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009967out_err:
9968 spin_unlock_bh(&rdev->beacon_registrations_lock);
9969 kfree(nreg);
9970 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009971}
9972
Johannes Berg98104fde2012-06-16 00:19:54 +02009973static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9974{
9975 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9976 struct wireless_dev *wdev = info->user_ptr[1];
9977 int err;
9978
9979 if (!rdev->ops->start_p2p_device)
9980 return -EOPNOTSUPP;
9981
9982 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9983 return -EOPNOTSUPP;
9984
9985 if (wdev->p2p_started)
9986 return 0;
9987
Luciano Coelhob6a55012014-02-27 11:07:21 +02009988 if (rfkill_blocked(rdev->rfkill))
9989 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009990
Johannes Bergeeb126e2012-10-23 15:16:50 +02009991 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009992 if (err)
9993 return err;
9994
9995 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009996 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009997
9998 return 0;
9999}
10000
10001static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
10002{
10003 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10004 struct wireless_dev *wdev = info->user_ptr[1];
10005
10006 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
10007 return -EOPNOTSUPP;
10008
10009 if (!rdev->ops->stop_p2p_device)
10010 return -EOPNOTSUPP;
10011
Johannes Bergf9f47522013-03-19 15:04:07 +010010012 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010013
10014 return 0;
10015}
10016
Johannes Berg3713b4e2013-02-14 16:19:38 +010010017static int nl80211_get_protocol_features(struct sk_buff *skb,
10018 struct genl_info *info)
10019{
10020 void *hdr;
10021 struct sk_buff *msg;
10022
10023 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10024 if (!msg)
10025 return -ENOMEM;
10026
10027 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
10028 NL80211_CMD_GET_PROTOCOL_FEATURES);
10029 if (!hdr)
10030 goto nla_put_failure;
10031
10032 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
10033 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
10034 goto nla_put_failure;
10035
10036 genlmsg_end(msg, hdr);
10037 return genlmsg_reply(msg, info);
10038
10039 nla_put_failure:
10040 kfree_skb(msg);
10041 return -ENOBUFS;
10042}
10043
Jouni Malinen355199e2013-02-27 17:14:27 +020010044static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
10045{
10046 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10047 struct cfg80211_update_ft_ies_params ft_params;
10048 struct net_device *dev = info->user_ptr[1];
10049
10050 if (!rdev->ops->update_ft_ies)
10051 return -EOPNOTSUPP;
10052
10053 if (!info->attrs[NL80211_ATTR_MDID] ||
10054 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10055 return -EINVAL;
10056
10057 memset(&ft_params, 0, sizeof(ft_params));
10058 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10059 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10060 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10061
10062 return rdev_update_ft_ies(rdev, dev, &ft_params);
10063}
10064
Arend van Spriel5de17982013-04-18 15:49:00 +020010065static int nl80211_crit_protocol_start(struct sk_buff *skb,
10066 struct genl_info *info)
10067{
10068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10069 struct wireless_dev *wdev = info->user_ptr[1];
10070 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10071 u16 duration;
10072 int ret;
10073
10074 if (!rdev->ops->crit_proto_start)
10075 return -EOPNOTSUPP;
10076
10077 if (WARN_ON(!rdev->ops->crit_proto_stop))
10078 return -EINVAL;
10079
10080 if (rdev->crit_proto_nlportid)
10081 return -EBUSY;
10082
10083 /* determine protocol if provided */
10084 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10085 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10086
10087 if (proto >= NUM_NL80211_CRIT_PROTO)
10088 return -EINVAL;
10089
10090 /* timeout must be provided */
10091 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10092 return -EINVAL;
10093
10094 duration =
10095 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10096
10097 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10098 return -ERANGE;
10099
10100 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10101 if (!ret)
10102 rdev->crit_proto_nlportid = info->snd_portid;
10103
10104 return ret;
10105}
10106
10107static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10108 struct genl_info *info)
10109{
10110 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10111 struct wireless_dev *wdev = info->user_ptr[1];
10112
10113 if (!rdev->ops->crit_proto_stop)
10114 return -EOPNOTSUPP;
10115
10116 if (rdev->crit_proto_nlportid) {
10117 rdev->crit_proto_nlportid = 0;
10118 rdev_crit_proto_stop(rdev, wdev);
10119 }
10120 return 0;
10121}
10122
Johannes Bergad7e7182013-11-13 13:37:47 +010010123static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10124{
10125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10126 struct wireless_dev *wdev =
10127 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10128 int i, err;
10129 u32 vid, subcmd;
10130
10131 if (!rdev->wiphy.vendor_commands)
10132 return -EOPNOTSUPP;
10133
10134 if (IS_ERR(wdev)) {
10135 err = PTR_ERR(wdev);
10136 if (err != -EINVAL)
10137 return err;
10138 wdev = NULL;
10139 } else if (wdev->wiphy != &rdev->wiphy) {
10140 return -EINVAL;
10141 }
10142
10143 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10144 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10145 return -EINVAL;
10146
10147 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10148 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10149 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10150 const struct wiphy_vendor_command *vcmd;
10151 void *data = NULL;
10152 int len = 0;
10153
10154 vcmd = &rdev->wiphy.vendor_commands[i];
10155
10156 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10157 continue;
10158
10159 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10160 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10161 if (!wdev)
10162 return -EINVAL;
10163 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10164 !wdev->netdev)
10165 return -EINVAL;
10166
10167 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10168 if (wdev->netdev &&
10169 !netif_running(wdev->netdev))
10170 return -ENETDOWN;
10171 if (!wdev->netdev && !wdev->p2p_started)
10172 return -ENETDOWN;
10173 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010174
10175 if (!vcmd->doit)
10176 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010177 } else {
10178 wdev = NULL;
10179 }
10180
10181 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10182 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10183 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10184 }
10185
10186 rdev->cur_cmd_info = info;
10187 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10188 data, len);
10189 rdev->cur_cmd_info = NULL;
10190 return err;
10191 }
10192
10193 return -EOPNOTSUPP;
10194}
10195
Johannes Berg7bdbe402015-08-15 22:39:49 +030010196static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10197 struct netlink_callback *cb,
10198 struct cfg80211_registered_device **rdev,
10199 struct wireless_dev **wdev)
10200{
10201 u32 vid, subcmd;
10202 unsigned int i;
10203 int vcmd_idx = -1;
10204 int err;
10205 void *data = NULL;
10206 unsigned int data_len = 0;
10207
10208 rtnl_lock();
10209
10210 if (cb->args[0]) {
10211 /* subtract the 1 again here */
10212 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10213 struct wireless_dev *tmp;
10214
10215 if (!wiphy) {
10216 err = -ENODEV;
10217 goto out_unlock;
10218 }
10219 *rdev = wiphy_to_rdev(wiphy);
10220 *wdev = NULL;
10221
10222 if (cb->args[1]) {
10223 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
10224 if (tmp->identifier == cb->args[1] - 1) {
10225 *wdev = tmp;
10226 break;
10227 }
10228 }
10229 }
10230
10231 /* keep rtnl locked in successful case */
10232 return 0;
10233 }
10234
10235 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10236 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10237 nl80211_policy);
10238 if (err)
10239 goto out_unlock;
10240
10241 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10242 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10243 err = -EINVAL;
10244 goto out_unlock;
10245 }
10246
10247 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10248 nl80211_fam.attrbuf);
10249 if (IS_ERR(*wdev))
10250 *wdev = NULL;
10251
10252 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10253 nl80211_fam.attrbuf);
10254 if (IS_ERR(*rdev)) {
10255 err = PTR_ERR(*rdev);
10256 goto out_unlock;
10257 }
10258
10259 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10260 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10261
10262 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10263 const struct wiphy_vendor_command *vcmd;
10264
10265 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10266
10267 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10268 continue;
10269
10270 if (!vcmd->dumpit) {
10271 err = -EOPNOTSUPP;
10272 goto out_unlock;
10273 }
10274
10275 vcmd_idx = i;
10276 break;
10277 }
10278
10279 if (vcmd_idx < 0) {
10280 err = -EOPNOTSUPP;
10281 goto out_unlock;
10282 }
10283
10284 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10285 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10286 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10287 }
10288
10289 /* 0 is the first index - add 1 to parse only once */
10290 cb->args[0] = (*rdev)->wiphy_idx + 1;
10291 /* add 1 to know if it was NULL */
10292 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10293 cb->args[2] = vcmd_idx;
10294 cb->args[3] = (unsigned long)data;
10295 cb->args[4] = data_len;
10296
10297 /* keep rtnl locked in successful case */
10298 return 0;
10299 out_unlock:
10300 rtnl_unlock();
10301 return err;
10302}
10303
10304static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10305 struct netlink_callback *cb)
10306{
10307 struct cfg80211_registered_device *rdev;
10308 struct wireless_dev *wdev;
10309 unsigned int vcmd_idx;
10310 const struct wiphy_vendor_command *vcmd;
10311 void *data;
10312 int data_len;
10313 int err;
10314 struct nlattr *vendor_data;
10315
10316 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10317 if (err)
10318 return err;
10319
10320 vcmd_idx = cb->args[2];
10321 data = (void *)cb->args[3];
10322 data_len = cb->args[4];
10323 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10324
10325 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10326 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10327 if (!wdev)
10328 return -EINVAL;
10329 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10330 !wdev->netdev)
10331 return -EINVAL;
10332
10333 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10334 if (wdev->netdev &&
10335 !netif_running(wdev->netdev))
10336 return -ENETDOWN;
10337 if (!wdev->netdev && !wdev->p2p_started)
10338 return -ENETDOWN;
10339 }
10340 }
10341
10342 while (1) {
10343 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10344 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10345 NL80211_CMD_VENDOR);
10346 if (!hdr)
10347 break;
10348
10349 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10350 (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV,
10351 wdev_id(wdev)))) {
10352 genlmsg_cancel(skb, hdr);
10353 break;
10354 }
10355
10356 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10357 if (!vendor_data) {
10358 genlmsg_cancel(skb, hdr);
10359 break;
10360 }
10361
10362 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10363 (unsigned long *)&cb->args[5]);
10364 nla_nest_end(skb, vendor_data);
10365
10366 if (err == -ENOBUFS || err == -ENOENT) {
10367 genlmsg_cancel(skb, hdr);
10368 break;
10369 } else if (err) {
10370 genlmsg_cancel(skb, hdr);
10371 goto out;
10372 }
10373
10374 genlmsg_end(skb, hdr);
10375 }
10376
10377 err = skb->len;
10378 out:
10379 rtnl_unlock();
10380 return err;
10381}
10382
Johannes Bergad7e7182013-11-13 13:37:47 +010010383struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10384 enum nl80211_commands cmd,
10385 enum nl80211_attrs attr,
10386 int approxlen)
10387{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010388 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010389
10390 if (WARN_ON(!rdev->cur_cmd_info))
10391 return NULL;
10392
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010393 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010394 rdev->cur_cmd_info->snd_portid,
10395 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010396 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010397}
10398EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10399
10400int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10401{
10402 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10403 void *hdr = ((void **)skb->cb)[1];
10404 struct nlattr *data = ((void **)skb->cb)[2];
10405
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010406 /* clear CB data for netlink core to own from now on */
10407 memset(skb->cb, 0, sizeof(skb->cb));
10408
Johannes Bergad7e7182013-11-13 13:37:47 +010010409 if (WARN_ON(!rdev->cur_cmd_info)) {
10410 kfree_skb(skb);
10411 return -EINVAL;
10412 }
10413
10414 nla_nest_end(skb, data);
10415 genlmsg_end(skb, hdr);
10416 return genlmsg_reply(skb, rdev->cur_cmd_info);
10417}
10418EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10419
10420
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010421static int nl80211_set_qos_map(struct sk_buff *skb,
10422 struct genl_info *info)
10423{
10424 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10425 struct cfg80211_qos_map *qos_map = NULL;
10426 struct net_device *dev = info->user_ptr[1];
10427 u8 *pos, len, num_des, des_len, des;
10428 int ret;
10429
10430 if (!rdev->ops->set_qos_map)
10431 return -EOPNOTSUPP;
10432
10433 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10434 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10435 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10436
10437 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10438 len > IEEE80211_QOS_MAP_LEN_MAX)
10439 return -EINVAL;
10440
10441 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10442 if (!qos_map)
10443 return -ENOMEM;
10444
10445 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10446 if (num_des) {
10447 des_len = num_des *
10448 sizeof(struct cfg80211_dscp_exception);
10449 memcpy(qos_map->dscp_exception, pos, des_len);
10450 qos_map->num_des = num_des;
10451 for (des = 0; des < num_des; des++) {
10452 if (qos_map->dscp_exception[des].up > 7) {
10453 kfree(qos_map);
10454 return -EINVAL;
10455 }
10456 }
10457 pos += des_len;
10458 }
10459 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10460 }
10461
10462 wdev_lock(dev->ieee80211_ptr);
10463 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10464 if (!ret)
10465 ret = rdev_set_qos_map(rdev, dev, qos_map);
10466 wdev_unlock(dev->ieee80211_ptr);
10467
10468 kfree(qos_map);
10469 return ret;
10470}
10471
Johannes Berg960d01a2014-09-09 22:55:35 +030010472static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10473{
10474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10475 struct net_device *dev = info->user_ptr[1];
10476 struct wireless_dev *wdev = dev->ieee80211_ptr;
10477 const u8 *peer;
10478 u8 tsid, up;
10479 u16 admitted_time = 0;
10480 int err;
10481
Johannes Berg723e73a2014-10-22 09:25:06 +020010482 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010483 return -EOPNOTSUPP;
10484
10485 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10486 !info->attrs[NL80211_ATTR_USER_PRIO])
10487 return -EINVAL;
10488
10489 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10490 if (tsid >= IEEE80211_NUM_TIDS)
10491 return -EINVAL;
10492
10493 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10494 if (up >= IEEE80211_NUM_UPS)
10495 return -EINVAL;
10496
10497 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010498 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010499 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010500 * need more attributes for that (e.g. BA session requirement);
10501 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010502 */
10503 return -EINVAL;
10504 }
10505
10506 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10507
10508 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10509 admitted_time =
10510 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10511 if (!admitted_time)
10512 return -EINVAL;
10513 }
10514
10515 wdev_lock(wdev);
10516 switch (wdev->iftype) {
10517 case NL80211_IFTYPE_STATION:
10518 case NL80211_IFTYPE_P2P_CLIENT:
10519 if (wdev->current_bss)
10520 break;
10521 err = -ENOTCONN;
10522 goto out;
10523 default:
10524 err = -EOPNOTSUPP;
10525 goto out;
10526 }
10527
10528 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10529
10530 out:
10531 wdev_unlock(wdev);
10532 return err;
10533}
10534
10535static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10536{
10537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10538 struct net_device *dev = info->user_ptr[1];
10539 struct wireless_dev *wdev = dev->ieee80211_ptr;
10540 const u8 *peer;
10541 u8 tsid;
10542 int err;
10543
10544 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10545 return -EINVAL;
10546
10547 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10548 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10549
10550 wdev_lock(wdev);
10551 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10552 wdev_unlock(wdev);
10553
10554 return err;
10555}
10556
Arik Nemtsov1057d352014-11-19 12:54:26 +020010557static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10558 struct genl_info *info)
10559{
10560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10561 struct net_device *dev = info->user_ptr[1];
10562 struct wireless_dev *wdev = dev->ieee80211_ptr;
10563 struct cfg80211_chan_def chandef = {};
10564 const u8 *addr;
10565 u8 oper_class;
10566 int err;
10567
10568 if (!rdev->ops->tdls_channel_switch ||
10569 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10570 return -EOPNOTSUPP;
10571
10572 switch (dev->ieee80211_ptr->iftype) {
10573 case NL80211_IFTYPE_STATION:
10574 case NL80211_IFTYPE_P2P_CLIENT:
10575 break;
10576 default:
10577 return -EOPNOTSUPP;
10578 }
10579
10580 if (!info->attrs[NL80211_ATTR_MAC] ||
10581 !info->attrs[NL80211_ATTR_OPER_CLASS])
10582 return -EINVAL;
10583
10584 err = nl80211_parse_chandef(rdev, info, &chandef);
10585 if (err)
10586 return err;
10587
10588 /*
10589 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10590 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10591 * specification is not defined for them.
10592 */
10593 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10594 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10595 chandef.width != NL80211_CHAN_WIDTH_20)
10596 return -EINVAL;
10597
10598 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010599 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10600 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010601 return -EINVAL;
10602
10603 /* don't allow switching to DFS channels */
10604 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10605 return -EINVAL;
10606
10607 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10608 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10609
10610 wdev_lock(wdev);
10611 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10612 wdev_unlock(wdev);
10613
10614 return err;
10615}
10616
10617static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10618 struct genl_info *info)
10619{
10620 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10621 struct net_device *dev = info->user_ptr[1];
10622 struct wireless_dev *wdev = dev->ieee80211_ptr;
10623 const u8 *addr;
10624
10625 if (!rdev->ops->tdls_channel_switch ||
10626 !rdev->ops->tdls_cancel_channel_switch ||
10627 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10628 return -EOPNOTSUPP;
10629
10630 switch (dev->ieee80211_ptr->iftype) {
10631 case NL80211_IFTYPE_STATION:
10632 case NL80211_IFTYPE_P2P_CLIENT:
10633 break;
10634 default:
10635 return -EOPNOTSUPP;
10636 }
10637
10638 if (!info->attrs[NL80211_ATTR_MAC])
10639 return -EINVAL;
10640
10641 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10642
10643 wdev_lock(wdev);
10644 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10645 wdev_unlock(wdev);
10646
10647 return 0;
10648}
10649
Johannes Berg4c476992010-10-04 21:36:35 +020010650#define NL80211_FLAG_NEED_WIPHY 0x01
10651#define NL80211_FLAG_NEED_NETDEV 0x02
10652#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010653#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10654#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10655 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010656#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010657/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010658#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10659 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010660#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010661
Johannes Bergf84f7712013-11-14 17:14:45 +010010662static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010663 struct genl_info *info)
10664{
10665 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010666 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010667 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010668 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10669
10670 if (rtnl)
10671 rtnl_lock();
10672
10673 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010674 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010675 if (IS_ERR(rdev)) {
10676 if (rtnl)
10677 rtnl_unlock();
10678 return PTR_ERR(rdev);
10679 }
10680 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010681 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10682 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010683 ASSERT_RTNL();
10684
Johannes Berg89a54e42012-06-15 14:33:17 +020010685 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10686 info->attrs);
10687 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010688 if (rtnl)
10689 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010690 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010691 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010692
Johannes Berg89a54e42012-06-15 14:33:17 +020010693 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010694 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010695
Johannes Berg1bf614e2012-06-15 15:23:36 +020010696 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10697 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010698 if (rtnl)
10699 rtnl_unlock();
10700 return -EINVAL;
10701 }
10702
10703 info->user_ptr[1] = dev;
10704 } else {
10705 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010706 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010707
Johannes Berg1bf614e2012-06-15 15:23:36 +020010708 if (dev) {
10709 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10710 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010711 if (rtnl)
10712 rtnl_unlock();
10713 return -ENETDOWN;
10714 }
10715
10716 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010717 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10718 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010719 if (rtnl)
10720 rtnl_unlock();
10721 return -ENETDOWN;
10722 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010723 }
10724
Johannes Berg4c476992010-10-04 21:36:35 +020010725 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010726 }
10727
10728 return 0;
10729}
10730
Johannes Bergf84f7712013-11-14 17:14:45 +010010731static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010732 struct genl_info *info)
10733{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010734 if (info->user_ptr[1]) {
10735 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10736 struct wireless_dev *wdev = info->user_ptr[1];
10737
10738 if (wdev->netdev)
10739 dev_put(wdev->netdev);
10740 } else {
10741 dev_put(info->user_ptr[1]);
10742 }
10743 }
Johannes Berg5393b912014-09-10 15:00:16 +030010744
Johannes Berg4c476992010-10-04 21:36:35 +020010745 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10746 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010747
10748 /* If needed, clear the netlink message payload from the SKB
10749 * as it might contain key data that shouldn't stick around on
10750 * the heap after the SKB is freed. The netlink message header
10751 * is still needed for further processing, so leave it intact.
10752 */
10753 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10754 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10755
10756 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10757 }
Johannes Berg4c476992010-10-04 21:36:35 +020010758}
10759
Johannes Berg4534de82013-11-14 17:14:46 +010010760static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010761 {
10762 .cmd = NL80211_CMD_GET_WIPHY,
10763 .doit = nl80211_get_wiphy,
10764 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010765 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010766 .policy = nl80211_policy,
10767 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010768 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10769 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010770 },
10771 {
10772 .cmd = NL80211_CMD_SET_WIPHY,
10773 .doit = nl80211_set_wiphy,
10774 .policy = nl80211_policy,
10775 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010776 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010777 },
10778 {
10779 .cmd = NL80211_CMD_GET_INTERFACE,
10780 .doit = nl80211_get_interface,
10781 .dumpit = nl80211_dump_interface,
10782 .policy = nl80211_policy,
10783 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010784 .internal_flags = NL80211_FLAG_NEED_WDEV |
10785 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010786 },
10787 {
10788 .cmd = NL80211_CMD_SET_INTERFACE,
10789 .doit = nl80211_set_interface,
10790 .policy = nl80211_policy,
10791 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010792 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10793 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010794 },
10795 {
10796 .cmd = NL80211_CMD_NEW_INTERFACE,
10797 .doit = nl80211_new_interface,
10798 .policy = nl80211_policy,
10799 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010800 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10801 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010802 },
10803 {
10804 .cmd = NL80211_CMD_DEL_INTERFACE,
10805 .doit = nl80211_del_interface,
10806 .policy = nl80211_policy,
10807 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010808 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010809 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010810 },
Johannes Berg41ade002007-12-19 02:03:29 +010010811 {
10812 .cmd = NL80211_CMD_GET_KEY,
10813 .doit = nl80211_get_key,
10814 .policy = nl80211_policy,
10815 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010816 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010817 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010818 },
10819 {
10820 .cmd = NL80211_CMD_SET_KEY,
10821 .doit = nl80211_set_key,
10822 .policy = nl80211_policy,
10823 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010824 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010825 NL80211_FLAG_NEED_RTNL |
10826 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010827 },
10828 {
10829 .cmd = NL80211_CMD_NEW_KEY,
10830 .doit = nl80211_new_key,
10831 .policy = nl80211_policy,
10832 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010833 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010834 NL80211_FLAG_NEED_RTNL |
10835 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010836 },
10837 {
10838 .cmd = NL80211_CMD_DEL_KEY,
10839 .doit = nl80211_del_key,
10840 .policy = nl80211_policy,
10841 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010842 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010843 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010844 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010845 {
10846 .cmd = NL80211_CMD_SET_BEACON,
10847 .policy = nl80211_policy,
10848 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010849 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010850 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010851 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010852 },
10853 {
Johannes Berg88600202012-02-13 15:17:18 +010010854 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010855 .policy = nl80211_policy,
10856 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010857 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010858 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010859 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010860 },
10861 {
Johannes Berg88600202012-02-13 15:17:18 +010010862 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010863 .policy = nl80211_policy,
10864 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010865 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010866 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010867 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010868 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010869 {
10870 .cmd = NL80211_CMD_GET_STATION,
10871 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010872 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010873 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010874 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10875 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010876 },
10877 {
10878 .cmd = NL80211_CMD_SET_STATION,
10879 .doit = nl80211_set_station,
10880 .policy = nl80211_policy,
10881 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010882 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010883 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010884 },
10885 {
10886 .cmd = NL80211_CMD_NEW_STATION,
10887 .doit = nl80211_new_station,
10888 .policy = nl80211_policy,
10889 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010890 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010891 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010892 },
10893 {
10894 .cmd = NL80211_CMD_DEL_STATION,
10895 .doit = nl80211_del_station,
10896 .policy = nl80211_policy,
10897 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010898 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010899 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010900 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010901 {
10902 .cmd = NL80211_CMD_GET_MPATH,
10903 .doit = nl80211_get_mpath,
10904 .dumpit = nl80211_dump_mpath,
10905 .policy = nl80211_policy,
10906 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010907 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010908 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010909 },
10910 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010911 .cmd = NL80211_CMD_GET_MPP,
10912 .doit = nl80211_get_mpp,
10913 .dumpit = nl80211_dump_mpp,
10914 .policy = nl80211_policy,
10915 .flags = GENL_ADMIN_PERM,
10916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10917 NL80211_FLAG_NEED_RTNL,
10918 },
10919 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010920 .cmd = NL80211_CMD_SET_MPATH,
10921 .doit = nl80211_set_mpath,
10922 .policy = nl80211_policy,
10923 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010924 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010925 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010926 },
10927 {
10928 .cmd = NL80211_CMD_NEW_MPATH,
10929 .doit = nl80211_new_mpath,
10930 .policy = nl80211_policy,
10931 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010932 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010933 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010934 },
10935 {
10936 .cmd = NL80211_CMD_DEL_MPATH,
10937 .doit = nl80211_del_mpath,
10938 .policy = nl80211_policy,
10939 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010940 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010941 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010942 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010943 {
10944 .cmd = NL80211_CMD_SET_BSS,
10945 .doit = nl80211_set_bss,
10946 .policy = nl80211_policy,
10947 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010948 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010949 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010950 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010951 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010952 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010953 .doit = nl80211_get_reg_do,
10954 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010955 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010956 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010957 /* can be retrieved by unprivileged users */
10958 },
Johannes Bergb6863032015-10-15 09:25:18 +020010959#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010960 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010961 .cmd = NL80211_CMD_SET_REG,
10962 .doit = nl80211_set_reg,
10963 .policy = nl80211_policy,
10964 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010965 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010966 },
Johannes Bergb6863032015-10-15 09:25:18 +020010967#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010968 {
10969 .cmd = NL80211_CMD_REQ_SET_REG,
10970 .doit = nl80211_req_set_reg,
10971 .policy = nl80211_policy,
10972 .flags = GENL_ADMIN_PERM,
10973 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010974 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010975 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10976 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010977 .policy = nl80211_policy,
10978 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010979 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010980 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010981 },
10982 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010983 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10984 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010985 .policy = nl80211_policy,
10986 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010987 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010988 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010989 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010990 {
Johannes Berg2a519312009-02-10 21:25:55 +010010991 .cmd = NL80211_CMD_TRIGGER_SCAN,
10992 .doit = nl80211_trigger_scan,
10993 .policy = nl80211_policy,
10994 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010995 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010996 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010997 },
10998 {
Vidyullatha Kanchanapally91d3ab42015-10-30 19:14:49 +053010999 .cmd = NL80211_CMD_ABORT_SCAN,
11000 .doit = nl80211_abort_scan,
11001 .policy = nl80211_policy,
11002 .flags = GENL_ADMIN_PERM,
11003 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11004 NL80211_FLAG_NEED_RTNL,
11005 },
11006 {
Johannes Berg2a519312009-02-10 21:25:55 +010011007 .cmd = NL80211_CMD_GET_SCAN,
11008 .policy = nl80211_policy,
11009 .dumpit = nl80211_dump_scan,
11010 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020011011 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030011012 .cmd = NL80211_CMD_START_SCHED_SCAN,
11013 .doit = nl80211_start_sched_scan,
11014 .policy = nl80211_policy,
11015 .flags = GENL_ADMIN_PERM,
11016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11017 NL80211_FLAG_NEED_RTNL,
11018 },
11019 {
11020 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
11021 .doit = nl80211_stop_sched_scan,
11022 .policy = nl80211_policy,
11023 .flags = GENL_ADMIN_PERM,
11024 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11025 NL80211_FLAG_NEED_RTNL,
11026 },
11027 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020011028 .cmd = NL80211_CMD_AUTHENTICATE,
11029 .doit = nl80211_authenticate,
11030 .policy = nl80211_policy,
11031 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011032 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011033 NL80211_FLAG_NEED_RTNL |
11034 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011035 },
11036 {
11037 .cmd = NL80211_CMD_ASSOCIATE,
11038 .doit = nl80211_associate,
11039 .policy = nl80211_policy,
11040 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011041 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011042 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011043 },
11044 {
11045 .cmd = NL80211_CMD_DEAUTHENTICATE,
11046 .doit = nl80211_deauthenticate,
11047 .policy = nl80211_policy,
11048 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011049 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011050 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011051 },
11052 {
11053 .cmd = NL80211_CMD_DISASSOCIATE,
11054 .doit = nl80211_disassociate,
11055 .policy = nl80211_policy,
11056 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011057 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011058 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011059 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011060 {
11061 .cmd = NL80211_CMD_JOIN_IBSS,
11062 .doit = nl80211_join_ibss,
11063 .policy = nl80211_policy,
11064 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011065 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011066 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011067 },
11068 {
11069 .cmd = NL80211_CMD_LEAVE_IBSS,
11070 .doit = nl80211_leave_ibss,
11071 .policy = nl80211_policy,
11072 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011073 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011074 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011075 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011076#ifdef CONFIG_NL80211_TESTMODE
11077 {
11078 .cmd = NL80211_CMD_TESTMODE,
11079 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011080 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011081 .policy = nl80211_policy,
11082 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011083 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11084 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011085 },
11086#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011087 {
11088 .cmd = NL80211_CMD_CONNECT,
11089 .doit = nl80211_connect,
11090 .policy = nl80211_policy,
11091 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011092 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011093 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011094 },
11095 {
11096 .cmd = NL80211_CMD_DISCONNECT,
11097 .doit = nl80211_disconnect,
11098 .policy = nl80211_policy,
11099 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011100 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011101 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011102 },
Johannes Berg463d0182009-07-14 00:33:35 +020011103 {
11104 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11105 .doit = nl80211_wiphy_netns,
11106 .policy = nl80211_policy,
11107 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011108 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11109 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011110 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011111 {
11112 .cmd = NL80211_CMD_GET_SURVEY,
11113 .policy = nl80211_policy,
11114 .dumpit = nl80211_dump_survey,
11115 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011116 {
11117 .cmd = NL80211_CMD_SET_PMKSA,
11118 .doit = nl80211_setdel_pmksa,
11119 .policy = nl80211_policy,
11120 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011121 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011122 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011123 },
11124 {
11125 .cmd = NL80211_CMD_DEL_PMKSA,
11126 .doit = nl80211_setdel_pmksa,
11127 .policy = nl80211_policy,
11128 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011129 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011130 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011131 },
11132 {
11133 .cmd = NL80211_CMD_FLUSH_PMKSA,
11134 .doit = nl80211_flush_pmksa,
11135 .policy = nl80211_policy,
11136 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011137 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011138 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011139 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011140 {
11141 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11142 .doit = nl80211_remain_on_channel,
11143 .policy = nl80211_policy,
11144 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011145 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011146 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011147 },
11148 {
11149 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11150 .doit = nl80211_cancel_remain_on_channel,
11151 .policy = nl80211_policy,
11152 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011153 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011154 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011155 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011156 {
11157 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11158 .doit = nl80211_set_tx_bitrate_mask,
11159 .policy = nl80211_policy,
11160 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011161 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11162 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011163 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011164 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011165 .cmd = NL80211_CMD_REGISTER_FRAME,
11166 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011167 .policy = nl80211_policy,
11168 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011169 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011170 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011171 },
11172 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011173 .cmd = NL80211_CMD_FRAME,
11174 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011175 .policy = nl80211_policy,
11176 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011177 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011178 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011179 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011180 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011181 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11182 .doit = nl80211_tx_mgmt_cancel_wait,
11183 .policy = nl80211_policy,
11184 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011185 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011186 NL80211_FLAG_NEED_RTNL,
11187 },
11188 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011189 .cmd = NL80211_CMD_SET_POWER_SAVE,
11190 .doit = nl80211_set_power_save,
11191 .policy = nl80211_policy,
11192 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011193 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11194 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011195 },
11196 {
11197 .cmd = NL80211_CMD_GET_POWER_SAVE,
11198 .doit = nl80211_get_power_save,
11199 .policy = nl80211_policy,
11200 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011201 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11202 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011203 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011204 {
11205 .cmd = NL80211_CMD_SET_CQM,
11206 .doit = nl80211_set_cqm,
11207 .policy = nl80211_policy,
11208 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011209 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11210 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011211 },
Johannes Bergf444de02010-05-05 15:25:02 +020011212 {
11213 .cmd = NL80211_CMD_SET_CHANNEL,
11214 .doit = nl80211_set_channel,
11215 .policy = nl80211_policy,
11216 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011217 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11218 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011219 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011220 {
11221 .cmd = NL80211_CMD_SET_WDS_PEER,
11222 .doit = nl80211_set_wds_peer,
11223 .policy = nl80211_policy,
11224 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011225 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11226 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011227 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011228 {
11229 .cmd = NL80211_CMD_JOIN_MESH,
11230 .doit = nl80211_join_mesh,
11231 .policy = nl80211_policy,
11232 .flags = GENL_ADMIN_PERM,
11233 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11234 NL80211_FLAG_NEED_RTNL,
11235 },
11236 {
11237 .cmd = NL80211_CMD_LEAVE_MESH,
11238 .doit = nl80211_leave_mesh,
11239 .policy = nl80211_policy,
11240 .flags = GENL_ADMIN_PERM,
11241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11242 NL80211_FLAG_NEED_RTNL,
11243 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011244 {
11245 .cmd = NL80211_CMD_JOIN_OCB,
11246 .doit = nl80211_join_ocb,
11247 .policy = nl80211_policy,
11248 .flags = GENL_ADMIN_PERM,
11249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11250 NL80211_FLAG_NEED_RTNL,
11251 },
11252 {
11253 .cmd = NL80211_CMD_LEAVE_OCB,
11254 .doit = nl80211_leave_ocb,
11255 .policy = nl80211_policy,
11256 .flags = GENL_ADMIN_PERM,
11257 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11258 NL80211_FLAG_NEED_RTNL,
11259 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011260#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011261 {
11262 .cmd = NL80211_CMD_GET_WOWLAN,
11263 .doit = nl80211_get_wowlan,
11264 .policy = nl80211_policy,
11265 /* can be retrieved by unprivileged users */
11266 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11267 NL80211_FLAG_NEED_RTNL,
11268 },
11269 {
11270 .cmd = NL80211_CMD_SET_WOWLAN,
11271 .doit = nl80211_set_wowlan,
11272 .policy = nl80211_policy,
11273 .flags = GENL_ADMIN_PERM,
11274 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11275 NL80211_FLAG_NEED_RTNL,
11276 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011277#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011278 {
11279 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11280 .doit = nl80211_set_rekey_data,
11281 .policy = nl80211_policy,
11282 .flags = GENL_ADMIN_PERM,
11283 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011284 NL80211_FLAG_NEED_RTNL |
11285 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011286 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011287 {
11288 .cmd = NL80211_CMD_TDLS_MGMT,
11289 .doit = nl80211_tdls_mgmt,
11290 .policy = nl80211_policy,
11291 .flags = GENL_ADMIN_PERM,
11292 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11293 NL80211_FLAG_NEED_RTNL,
11294 },
11295 {
11296 .cmd = NL80211_CMD_TDLS_OPER,
11297 .doit = nl80211_tdls_oper,
11298 .policy = nl80211_policy,
11299 .flags = GENL_ADMIN_PERM,
11300 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11301 NL80211_FLAG_NEED_RTNL,
11302 },
Johannes Berg28946da2011-11-04 11:18:12 +010011303 {
11304 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11305 .doit = nl80211_register_unexpected_frame,
11306 .policy = nl80211_policy,
11307 .flags = GENL_ADMIN_PERM,
11308 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11309 NL80211_FLAG_NEED_RTNL,
11310 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011311 {
11312 .cmd = NL80211_CMD_PROBE_CLIENT,
11313 .doit = nl80211_probe_client,
11314 .policy = nl80211_policy,
11315 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011316 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011317 NL80211_FLAG_NEED_RTNL,
11318 },
Johannes Berg5e760232011-11-04 11:18:17 +010011319 {
11320 .cmd = NL80211_CMD_REGISTER_BEACONS,
11321 .doit = nl80211_register_beacons,
11322 .policy = nl80211_policy,
11323 .flags = GENL_ADMIN_PERM,
11324 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11325 NL80211_FLAG_NEED_RTNL,
11326 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011327 {
11328 .cmd = NL80211_CMD_SET_NOACK_MAP,
11329 .doit = nl80211_set_noack_map,
11330 .policy = nl80211_policy,
11331 .flags = GENL_ADMIN_PERM,
11332 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11333 NL80211_FLAG_NEED_RTNL,
11334 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011335 {
11336 .cmd = NL80211_CMD_START_P2P_DEVICE,
11337 .doit = nl80211_start_p2p_device,
11338 .policy = nl80211_policy,
11339 .flags = GENL_ADMIN_PERM,
11340 .internal_flags = NL80211_FLAG_NEED_WDEV |
11341 NL80211_FLAG_NEED_RTNL,
11342 },
11343 {
11344 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11345 .doit = nl80211_stop_p2p_device,
11346 .policy = nl80211_policy,
11347 .flags = GENL_ADMIN_PERM,
11348 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11349 NL80211_FLAG_NEED_RTNL,
11350 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011351 {
11352 .cmd = NL80211_CMD_SET_MCAST_RATE,
11353 .doit = nl80211_set_mcast_rate,
11354 .policy = nl80211_policy,
11355 .flags = GENL_ADMIN_PERM,
11356 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11357 NL80211_FLAG_NEED_RTNL,
11358 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011359 {
11360 .cmd = NL80211_CMD_SET_MAC_ACL,
11361 .doit = nl80211_set_mac_acl,
11362 .policy = nl80211_policy,
11363 .flags = GENL_ADMIN_PERM,
11364 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11365 NL80211_FLAG_NEED_RTNL,
11366 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011367 {
11368 .cmd = NL80211_CMD_RADAR_DETECT,
11369 .doit = nl80211_start_radar_detection,
11370 .policy = nl80211_policy,
11371 .flags = GENL_ADMIN_PERM,
11372 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11373 NL80211_FLAG_NEED_RTNL,
11374 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011375 {
11376 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11377 .doit = nl80211_get_protocol_features,
11378 .policy = nl80211_policy,
11379 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011380 {
11381 .cmd = NL80211_CMD_UPDATE_FT_IES,
11382 .doit = nl80211_update_ft_ies,
11383 .policy = nl80211_policy,
11384 .flags = GENL_ADMIN_PERM,
11385 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11386 NL80211_FLAG_NEED_RTNL,
11387 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011388 {
11389 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11390 .doit = nl80211_crit_protocol_start,
11391 .policy = nl80211_policy,
11392 .flags = GENL_ADMIN_PERM,
11393 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11394 NL80211_FLAG_NEED_RTNL,
11395 },
11396 {
11397 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11398 .doit = nl80211_crit_protocol_stop,
11399 .policy = nl80211_policy,
11400 .flags = GENL_ADMIN_PERM,
11401 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11402 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011403 },
11404 {
11405 .cmd = NL80211_CMD_GET_COALESCE,
11406 .doit = nl80211_get_coalesce,
11407 .policy = nl80211_policy,
11408 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11409 NL80211_FLAG_NEED_RTNL,
11410 },
11411 {
11412 .cmd = NL80211_CMD_SET_COALESCE,
11413 .doit = nl80211_set_coalesce,
11414 .policy = nl80211_policy,
11415 .flags = GENL_ADMIN_PERM,
11416 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11417 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011418 },
11419 {
11420 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11421 .doit = nl80211_channel_switch,
11422 .policy = nl80211_policy,
11423 .flags = GENL_ADMIN_PERM,
11424 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11425 NL80211_FLAG_NEED_RTNL,
11426 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011427 {
11428 .cmd = NL80211_CMD_VENDOR,
11429 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011430 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011431 .policy = nl80211_policy,
11432 .flags = GENL_ADMIN_PERM,
11433 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11434 NL80211_FLAG_NEED_RTNL,
11435 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011436 {
11437 .cmd = NL80211_CMD_SET_QOS_MAP,
11438 .doit = nl80211_set_qos_map,
11439 .policy = nl80211_policy,
11440 .flags = GENL_ADMIN_PERM,
11441 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11442 NL80211_FLAG_NEED_RTNL,
11443 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011444 {
11445 .cmd = NL80211_CMD_ADD_TX_TS,
11446 .doit = nl80211_add_tx_ts,
11447 .policy = nl80211_policy,
11448 .flags = GENL_ADMIN_PERM,
11449 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11450 NL80211_FLAG_NEED_RTNL,
11451 },
11452 {
11453 .cmd = NL80211_CMD_DEL_TX_TS,
11454 .doit = nl80211_del_tx_ts,
11455 .policy = nl80211_policy,
11456 .flags = GENL_ADMIN_PERM,
11457 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11458 NL80211_FLAG_NEED_RTNL,
11459 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011460 {
11461 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11462 .doit = nl80211_tdls_channel_switch,
11463 .policy = nl80211_policy,
11464 .flags = GENL_ADMIN_PERM,
11465 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11466 NL80211_FLAG_NEED_RTNL,
11467 },
11468 {
11469 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11470 .doit = nl80211_tdls_cancel_channel_switch,
11471 .policy = nl80211_policy,
11472 .flags = GENL_ADMIN_PERM,
11473 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11474 NL80211_FLAG_NEED_RTNL,
11475 },
Johannes Berg55682962007-09-20 13:09:35 -040011476};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011477
Johannes Berg55682962007-09-20 13:09:35 -040011478/* notification functions */
11479
Johannes Berg3bb20552014-05-26 13:52:25 +020011480void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11481 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011482{
11483 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011484 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011485
Johannes Berg3bb20552014-05-26 13:52:25 +020011486 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11487 cmd != NL80211_CMD_DEL_WIPHY);
11488
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011489 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011490 if (!msg)
11491 return;
11492
Johannes Berg3bb20552014-05-26 13:52:25 +020011493 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011494 nlmsg_free(msg);
11495 return;
11496 }
11497
Johannes Berg68eb5502013-11-19 15:19:38 +010011498 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011499 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011500}
11501
Johannes Berg362a4152009-05-24 16:43:15 +020011502static int nl80211_add_scan_req(struct sk_buff *msg,
11503 struct cfg80211_registered_device *rdev)
11504{
11505 struct cfg80211_scan_request *req = rdev->scan_req;
11506 struct nlattr *nest;
11507 int i;
11508
11509 if (WARN_ON(!req))
11510 return 0;
11511
11512 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11513 if (!nest)
11514 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011515 for (i = 0; i < req->n_ssids; i++) {
11516 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11517 goto nla_put_failure;
11518 }
Johannes Berg362a4152009-05-24 16:43:15 +020011519 nla_nest_end(msg, nest);
11520
11521 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11522 if (!nest)
11523 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011524 for (i = 0; i < req->n_channels; i++) {
11525 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11526 goto nla_put_failure;
11527 }
Johannes Berg362a4152009-05-24 16:43:15 +020011528 nla_nest_end(msg, nest);
11529
David S. Miller9360ffd2012-03-29 04:41:26 -040011530 if (req->ie &&
11531 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11532 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011533
Johannes Bergae917c92013-10-25 11:05:22 +020011534 if (req->flags &&
11535 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11536 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011537
Johannes Berg362a4152009-05-24 16:43:15 +020011538 return 0;
11539 nla_put_failure:
11540 return -ENOBUFS;
11541}
11542
Johannes Berga538e2d2009-06-16 19:56:42 +020011543static int nl80211_send_scan_msg(struct sk_buff *msg,
11544 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011545 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011546 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011547 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011548{
11549 void *hdr;
11550
Eric W. Biederman15e47302012-09-07 20:12:54 +000011551 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011552 if (!hdr)
11553 return -1;
11554
David S. Miller9360ffd2012-03-29 04:41:26 -040011555 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011556 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11557 wdev->netdev->ifindex)) ||
11558 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011559 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011560
Johannes Berg362a4152009-05-24 16:43:15 +020011561 /* ignore errors and send incomplete event anyway */
11562 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011563
Johannes Berg053c0952015-01-16 22:09:00 +010011564 genlmsg_end(msg, hdr);
11565 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011566
11567 nla_put_failure:
11568 genlmsg_cancel(msg, hdr);
11569 return -EMSGSIZE;
11570}
11571
Luciano Coelho807f8a82011-05-11 17:09:35 +030011572static int
11573nl80211_send_sched_scan_msg(struct sk_buff *msg,
11574 struct cfg80211_registered_device *rdev,
11575 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011576 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011577{
11578 void *hdr;
11579
Eric W. Biederman15e47302012-09-07 20:12:54 +000011580 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011581 if (!hdr)
11582 return -1;
11583
David S. Miller9360ffd2012-03-29 04:41:26 -040011584 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11585 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11586 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011587
Johannes Berg053c0952015-01-16 22:09:00 +010011588 genlmsg_end(msg, hdr);
11589 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011590
11591 nla_put_failure:
11592 genlmsg_cancel(msg, hdr);
11593 return -EMSGSIZE;
11594}
11595
Johannes Berga538e2d2009-06-16 19:56:42 +020011596void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011597 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011598{
11599 struct sk_buff *msg;
11600
Thomas Graf58050fc2012-06-28 03:57:45 +000011601 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011602 if (!msg)
11603 return;
11604
Johannes Bergfd014282012-06-18 19:17:03 +020011605 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011606 NL80211_CMD_TRIGGER_SCAN) < 0) {
11607 nlmsg_free(msg);
11608 return;
11609 }
11610
Johannes Berg68eb5502013-11-19 15:19:38 +010011611 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011612 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011613}
11614
Johannes Bergf9d15d12014-01-22 11:14:19 +020011615struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11616 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011617{
11618 struct sk_buff *msg;
11619
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011620 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011621 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011622 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011623
Johannes Bergfd014282012-06-18 19:17:03 +020011624 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011625 aborted ? NL80211_CMD_SCAN_ABORTED :
11626 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011627 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011628 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011629 }
11630
Johannes Bergf9d15d12014-01-22 11:14:19 +020011631 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011632}
11633
Johannes Bergf9d15d12014-01-22 11:14:19 +020011634void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11635 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011636{
Johannes Berg2a519312009-02-10 21:25:55 +010011637 if (!msg)
11638 return;
11639
Johannes Berg68eb5502013-11-19 15:19:38 +010011640 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011641 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011642}
11643
Luciano Coelho807f8a82011-05-11 17:09:35 +030011644void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11645 struct net_device *netdev)
11646{
11647 struct sk_buff *msg;
11648
11649 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11650 if (!msg)
11651 return;
11652
11653 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11654 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11655 nlmsg_free(msg);
11656 return;
11657 }
11658
Johannes Berg68eb5502013-11-19 15:19:38 +010011659 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011660 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011661}
11662
11663void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11664 struct net_device *netdev, u32 cmd)
11665{
11666 struct sk_buff *msg;
11667
Thomas Graf58050fc2012-06-28 03:57:45 +000011668 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011669 if (!msg)
11670 return;
11671
11672 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11673 nlmsg_free(msg);
11674 return;
11675 }
11676
Johannes Berg68eb5502013-11-19 15:19:38 +010011677 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011678 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011679}
11680
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011681static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11682 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011683{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011684 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011685 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11686 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011687
David S. Miller9360ffd2012-03-29 04:41:26 -040011688 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11689 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11690 NL80211_REGDOM_TYPE_WORLD))
11691 goto nla_put_failure;
11692 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11693 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11694 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11695 goto nla_put_failure;
11696 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11697 request->intersect) {
11698 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11699 NL80211_REGDOM_TYPE_INTERSECTION))
11700 goto nla_put_failure;
11701 } else {
11702 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11703 NL80211_REGDOM_TYPE_COUNTRY) ||
11704 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11705 request->alpha2))
11706 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011707 }
11708
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011709 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11710 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11711
11712 if (wiphy &&
11713 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11714 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011715
11716 if (wiphy &&
11717 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11718 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11719 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011720 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011721
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011722 return true;
11723
11724nla_put_failure:
11725 return false;
11726}
11727
11728/*
11729 * This can happen on global regulatory changes or device specific settings
11730 * based on custom regulatory domains.
11731 */
11732void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11733 struct regulatory_request *request)
11734{
11735 struct sk_buff *msg;
11736 void *hdr;
11737
11738 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11739 if (!msg)
11740 return;
11741
11742 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11743 if (!hdr) {
11744 nlmsg_free(msg);
11745 return;
11746 }
11747
11748 if (nl80211_reg_change_event_fill(msg, request) == false)
11749 goto nla_put_failure;
11750
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011751 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011752
Johannes Bergbc43b282009-07-25 10:54:13 +020011753 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011754 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011755 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011756 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011757
11758 return;
11759
11760nla_put_failure:
11761 genlmsg_cancel(msg, hdr);
11762 nlmsg_free(msg);
11763}
11764
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011765static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11766 struct net_device *netdev,
11767 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011768 enum nl80211_commands cmd, gfp_t gfp,
11769 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011770{
11771 struct sk_buff *msg;
11772 void *hdr;
11773
Johannes Berge6d6e342009-07-01 21:26:47 +020011774 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011775 if (!msg)
11776 return;
11777
11778 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11779 if (!hdr) {
11780 nlmsg_free(msg);
11781 return;
11782 }
11783
David S. Miller9360ffd2012-03-29 04:41:26 -040011784 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11785 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11786 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11787 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011788
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011789 if (uapsd_queues >= 0) {
11790 struct nlattr *nla_wmm =
11791 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11792 if (!nla_wmm)
11793 goto nla_put_failure;
11794
11795 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11796 uapsd_queues))
11797 goto nla_put_failure;
11798
11799 nla_nest_end(msg, nla_wmm);
11800 }
11801
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011802 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011803
Johannes Berg68eb5502013-11-19 15:19:38 +010011804 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011805 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011806 return;
11807
11808 nla_put_failure:
11809 genlmsg_cancel(msg, hdr);
11810 nlmsg_free(msg);
11811}
11812
11813void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011814 struct net_device *netdev, const u8 *buf,
11815 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011816{
11817 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011818 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011819}
11820
11821void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11822 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011823 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011824{
Johannes Berge6d6e342009-07-01 21:26:47 +020011825 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011826 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011827}
11828
Jouni Malinen53b46b82009-03-27 20:53:56 +020011829void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011830 struct net_device *netdev, const u8 *buf,
11831 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011832{
11833 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011834 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011835}
11836
Jouni Malinen53b46b82009-03-27 20:53:56 +020011837void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11838 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011839 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011840{
11841 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011842 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011843}
11844
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011845void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11846 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011847{
Johannes Berg947add32013-02-22 22:05:20 +010011848 struct wireless_dev *wdev = dev->ieee80211_ptr;
11849 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011850 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011851 const struct ieee80211_mgmt *mgmt = (void *)buf;
11852 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011853
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011854 if (WARN_ON(len < 2))
11855 return;
11856
11857 if (ieee80211_is_deauth(mgmt->frame_control))
11858 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11859 else
11860 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11861
11862 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011863 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011864}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011865EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011866
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011867static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11868 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011869 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011870{
11871 struct sk_buff *msg;
11872 void *hdr;
11873
Johannes Berge6d6e342009-07-01 21:26:47 +020011874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011875 if (!msg)
11876 return;
11877
11878 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11879 if (!hdr) {
11880 nlmsg_free(msg);
11881 return;
11882 }
11883
David S. Miller9360ffd2012-03-29 04:41:26 -040011884 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11885 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11886 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11887 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11888 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011889
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011890 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011891
Johannes Berg68eb5502013-11-19 15:19:38 +010011892 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011893 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011894 return;
11895
11896 nla_put_failure:
11897 genlmsg_cancel(msg, hdr);
11898 nlmsg_free(msg);
11899}
11900
11901void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011902 struct net_device *netdev, const u8 *addr,
11903 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011904{
11905 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011906 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011907}
11908
11909void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011910 struct net_device *netdev, const u8 *addr,
11911 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011912{
Johannes Berge6d6e342009-07-01 21:26:47 +020011913 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11914 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011915}
11916
Samuel Ortizb23aa672009-07-01 21:26:54 +020011917void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11918 struct net_device *netdev, const u8 *bssid,
11919 const u8 *req_ie, size_t req_ie_len,
11920 const u8 *resp_ie, size_t resp_ie_len,
11921 u16 status, gfp_t gfp)
11922{
11923 struct sk_buff *msg;
11924 void *hdr;
11925
Thomas Graf58050fc2012-06-28 03:57:45 +000011926 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011927 if (!msg)
11928 return;
11929
11930 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11931 if (!hdr) {
11932 nlmsg_free(msg);
11933 return;
11934 }
11935
David S. Miller9360ffd2012-03-29 04:41:26 -040011936 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11937 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11938 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11939 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11940 (req_ie &&
11941 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11942 (resp_ie &&
11943 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11944 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011945
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011946 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011947
Johannes Berg68eb5502013-11-19 15:19:38 +010011948 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011949 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011950 return;
11951
11952 nla_put_failure:
11953 genlmsg_cancel(msg, hdr);
11954 nlmsg_free(msg);
11955
11956}
11957
11958void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11959 struct net_device *netdev, const u8 *bssid,
11960 const u8 *req_ie, size_t req_ie_len,
11961 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11962{
11963 struct sk_buff *msg;
11964 void *hdr;
11965
Thomas Graf58050fc2012-06-28 03:57:45 +000011966 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011967 if (!msg)
11968 return;
11969
11970 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11971 if (!hdr) {
11972 nlmsg_free(msg);
11973 return;
11974 }
11975
David S. Miller9360ffd2012-03-29 04:41:26 -040011976 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11977 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11978 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11979 (req_ie &&
11980 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11981 (resp_ie &&
11982 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11983 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011984
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011985 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011986
Johannes Berg68eb5502013-11-19 15:19:38 +010011987 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011988 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011989 return;
11990
11991 nla_put_failure:
11992 genlmsg_cancel(msg, hdr);
11993 nlmsg_free(msg);
11994
11995}
11996
11997void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11998 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020011999 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020012000{
12001 struct sk_buff *msg;
12002 void *hdr;
12003
Thomas Graf58050fc2012-06-28 03:57:45 +000012004 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012005 if (!msg)
12006 return;
12007
12008 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
12009 if (!hdr) {
12010 nlmsg_free(msg);
12011 return;
12012 }
12013
David S. Miller9360ffd2012-03-29 04:41:26 -040012014 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12015 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12016 (from_ap && reason &&
12017 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
12018 (from_ap &&
12019 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
12020 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
12021 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020012022
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012023 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012024
Johannes Berg68eb5502013-11-19 15:19:38 +010012025 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012026 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020012027 return;
12028
12029 nla_put_failure:
12030 genlmsg_cancel(msg, hdr);
12031 nlmsg_free(msg);
12032
12033}
12034
Johannes Berg04a773a2009-04-19 21:24:32 +020012035void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
12036 struct net_device *netdev, const u8 *bssid,
12037 gfp_t gfp)
12038{
12039 struct sk_buff *msg;
12040 void *hdr;
12041
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012043 if (!msg)
12044 return;
12045
12046 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
12047 if (!hdr) {
12048 nlmsg_free(msg);
12049 return;
12050 }
12051
David S. Miller9360ffd2012-03-29 04:41:26 -040012052 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12053 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12054 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12055 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020012056
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012057 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012058
Johannes Berg68eb5502013-11-19 15:19:38 +010012059 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012060 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012061 return;
12062
12063 nla_put_failure:
12064 genlmsg_cancel(msg, hdr);
12065 nlmsg_free(msg);
12066}
12067
Johannes Berg947add32013-02-22 22:05:20 +010012068void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12069 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012070{
Johannes Berg947add32013-02-22 22:05:20 +010012071 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012072 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012073 struct sk_buff *msg;
12074 void *hdr;
12075
Johannes Berg947add32013-02-22 22:05:20 +010012076 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12077 return;
12078
12079 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12080
Javier Cardonac93b5e72011-04-07 15:08:34 -070012081 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12082 if (!msg)
12083 return;
12084
12085 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12086 if (!hdr) {
12087 nlmsg_free(msg);
12088 return;
12089 }
12090
David S. Miller9360ffd2012-03-29 04:41:26 -040012091 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012092 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12093 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012094 (ie_len && ie &&
12095 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12096 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012097
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012098 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012099
Johannes Berg68eb5502013-11-19 15:19:38 +010012100 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012101 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012102 return;
12103
12104 nla_put_failure:
12105 genlmsg_cancel(msg, hdr);
12106 nlmsg_free(msg);
12107}
Johannes Berg947add32013-02-22 22:05:20 +010012108EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012109
Jouni Malinena3b8b052009-03-27 21:59:49 +020012110void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12111 struct net_device *netdev, const u8 *addr,
12112 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012113 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012114{
12115 struct sk_buff *msg;
12116 void *hdr;
12117
Johannes Berge6d6e342009-07-01 21:26:47 +020012118 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012119 if (!msg)
12120 return;
12121
12122 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12123 if (!hdr) {
12124 nlmsg_free(msg);
12125 return;
12126 }
12127
David S. Miller9360ffd2012-03-29 04:41:26 -040012128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12129 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12130 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12131 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12132 (key_id != -1 &&
12133 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12134 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12135 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012136
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012137 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012138
Johannes Berg68eb5502013-11-19 15:19:38 +010012139 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012140 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012141 return;
12142
12143 nla_put_failure:
12144 genlmsg_cancel(msg, hdr);
12145 nlmsg_free(msg);
12146}
12147
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012148void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12149 struct ieee80211_channel *channel_before,
12150 struct ieee80211_channel *channel_after)
12151{
12152 struct sk_buff *msg;
12153 void *hdr;
12154 struct nlattr *nl_freq;
12155
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012156 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012157 if (!msg)
12158 return;
12159
12160 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12161 if (!hdr) {
12162 nlmsg_free(msg);
12163 return;
12164 }
12165
12166 /*
12167 * Since we are applying the beacon hint to a wiphy we know its
12168 * wiphy_idx is valid
12169 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012170 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12171 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012172
12173 /* Before */
12174 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12175 if (!nl_freq)
12176 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012177 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012178 goto nla_put_failure;
12179 nla_nest_end(msg, nl_freq);
12180
12181 /* After */
12182 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12183 if (!nl_freq)
12184 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012185 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012186 goto nla_put_failure;
12187 nla_nest_end(msg, nl_freq);
12188
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012189 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012190
Johannes Berg463d0182009-07-14 00:33:35 +020012191 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012192 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012193 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012194 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012195
12196 return;
12197
12198nla_put_failure:
12199 genlmsg_cancel(msg, hdr);
12200 nlmsg_free(msg);
12201}
12202
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012203static void nl80211_send_remain_on_chan_event(
12204 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012205 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012206 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012207 unsigned int duration, gfp_t gfp)
12208{
12209 struct sk_buff *msg;
12210 void *hdr;
12211
12212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12213 if (!msg)
12214 return;
12215
12216 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12217 if (!hdr) {
12218 nlmsg_free(msg);
12219 return;
12220 }
12221
David S. Miller9360ffd2012-03-29 04:41:26 -040012222 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012223 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12224 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020012225 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012226 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012227 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12228 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012229 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
12230 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012231
David S. Miller9360ffd2012-03-29 04:41:26 -040012232 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12233 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12234 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012235
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012236 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012237
Johannes Berg68eb5502013-11-19 15:19:38 +010012238 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012239 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012240 return;
12241
12242 nla_put_failure:
12243 genlmsg_cancel(msg, hdr);
12244 nlmsg_free(msg);
12245}
12246
Johannes Berg947add32013-02-22 22:05:20 +010012247void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12248 struct ieee80211_channel *chan,
12249 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012250{
Johannes Berg947add32013-02-22 22:05:20 +010012251 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012252 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012253
12254 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012255 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012256 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012257 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012258}
Johannes Berg947add32013-02-22 22:05:20 +010012259EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012260
Johannes Berg947add32013-02-22 22:05:20 +010012261void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12262 struct ieee80211_channel *chan,
12263 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012264{
Johannes Berg947add32013-02-22 22:05:20 +010012265 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012266 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012267
12268 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012269 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012270 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012271}
Johannes Berg947add32013-02-22 22:05:20 +010012272EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012273
Johannes Berg947add32013-02-22 22:05:20 +010012274void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12275 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012276{
Johannes Berg947add32013-02-22 22:05:20 +010012277 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012278 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012279 struct sk_buff *msg;
12280
Johannes Berg947add32013-02-22 22:05:20 +010012281 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12282
Thomas Graf58050fc2012-06-28 03:57:45 +000012283 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012284 if (!msg)
12285 return;
12286
Johannes Bergcf5ead82014-11-14 17:14:00 +010012287 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012288 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012289 nlmsg_free(msg);
12290 return;
12291 }
12292
Johannes Berg68eb5502013-11-19 15:19:38 +010012293 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012294 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012295}
Johannes Berg947add32013-02-22 22:05:20 +010012296EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012297
Johannes Bergcf5ead82014-11-14 17:14:00 +010012298void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12299 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012300{
Johannes Berg947add32013-02-22 22:05:20 +010012301 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012302 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012303 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012304 struct station_info empty_sinfo = {};
12305
12306 if (!sinfo)
12307 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012308
Johannes Berg947add32013-02-22 22:05:20 +010012309 trace_cfg80211_del_sta(dev, mac_addr);
12310
Thomas Graf58050fc2012-06-28 03:57:45 +000012311 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012312 if (!msg)
12313 return;
12314
Johannes Bergcf5ead82014-11-14 17:14:00 +010012315 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012316 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012317 nlmsg_free(msg);
12318 return;
12319 }
12320
Johannes Berg68eb5502013-11-19 15:19:38 +010012321 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012322 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012323}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012324EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012325
Johannes Berg947add32013-02-22 22:05:20 +010012326void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12327 enum nl80211_connect_failed_reason reason,
12328 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012329{
Johannes Berg947add32013-02-22 22:05:20 +010012330 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012331 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012332 struct sk_buff *msg;
12333 void *hdr;
12334
12335 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12336 if (!msg)
12337 return;
12338
12339 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12340 if (!hdr) {
12341 nlmsg_free(msg);
12342 return;
12343 }
12344
12345 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12346 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12347 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12348 goto nla_put_failure;
12349
12350 genlmsg_end(msg, hdr);
12351
Johannes Berg68eb5502013-11-19 15:19:38 +010012352 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012353 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012354 return;
12355
12356 nla_put_failure:
12357 genlmsg_cancel(msg, hdr);
12358 nlmsg_free(msg);
12359}
Johannes Berg947add32013-02-22 22:05:20 +010012360EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012361
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012362static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12363 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012364{
12365 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012366 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012367 struct sk_buff *msg;
12368 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012369 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012370
Eric W. Biederman15e47302012-09-07 20:12:54 +000012371 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012372 return false;
12373
12374 msg = nlmsg_new(100, gfp);
12375 if (!msg)
12376 return true;
12377
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012378 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012379 if (!hdr) {
12380 nlmsg_free(msg);
12381 return true;
12382 }
12383
David S. Miller9360ffd2012-03-29 04:41:26 -040012384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12385 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12386 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12387 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012388
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012389 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012390 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012391 return true;
12392
12393 nla_put_failure:
12394 genlmsg_cancel(msg, hdr);
12395 nlmsg_free(msg);
12396 return true;
12397}
12398
Johannes Berg947add32013-02-22 22:05:20 +010012399bool cfg80211_rx_spurious_frame(struct net_device *dev,
12400 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012401{
Johannes Berg947add32013-02-22 22:05:20 +010012402 struct wireless_dev *wdev = dev->ieee80211_ptr;
12403 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012404
Johannes Berg947add32013-02-22 22:05:20 +010012405 trace_cfg80211_rx_spurious_frame(dev, addr);
12406
12407 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12408 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12409 trace_cfg80211_return_bool(false);
12410 return false;
12411 }
12412 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12413 addr, gfp);
12414 trace_cfg80211_return_bool(ret);
12415 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012416}
Johannes Berg947add32013-02-22 22:05:20 +010012417EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12418
12419bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12420 const u8 *addr, gfp_t gfp)
12421{
12422 struct wireless_dev *wdev = dev->ieee80211_ptr;
12423 bool ret;
12424
12425 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12426
12427 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12428 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12429 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12430 trace_cfg80211_return_bool(false);
12431 return false;
12432 }
12433 ret = __nl80211_unexpected_frame(dev,
12434 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12435 addr, gfp);
12436 trace_cfg80211_return_bool(ret);
12437 return ret;
12438}
12439EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012440
Johannes Berg2e161f72010-08-12 15:38:38 +020012441int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012442 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012443 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012444 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012445{
Johannes Berg71bbc992012-06-15 15:30:18 +020012446 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012447 struct sk_buff *msg;
12448 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012449
12450 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12451 if (!msg)
12452 return -ENOMEM;
12453
Johannes Berg2e161f72010-08-12 15:38:38 +020012454 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012455 if (!hdr) {
12456 nlmsg_free(msg);
12457 return -ENOMEM;
12458 }
12459
David S. Miller9360ffd2012-03-29 04:41:26 -040012460 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012461 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12462 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012463 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012464 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12465 (sig_dbm &&
12466 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012467 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12468 (flags &&
12469 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012470 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012471
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012472 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012473
Eric W. Biederman15e47302012-09-07 20:12:54 +000012474 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012475
12476 nla_put_failure:
12477 genlmsg_cancel(msg, hdr);
12478 nlmsg_free(msg);
12479 return -ENOBUFS;
12480}
12481
Johannes Berg947add32013-02-22 22:05:20 +010012482void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12483 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012484{
Johannes Berg947add32013-02-22 22:05:20 +010012485 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012486 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012487 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012488 struct sk_buff *msg;
12489 void *hdr;
12490
Johannes Berg947add32013-02-22 22:05:20 +010012491 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12492
Jouni Malinen026331c2010-02-15 12:53:10 +020012493 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12494 if (!msg)
12495 return;
12496
Johannes Berg2e161f72010-08-12 15:38:38 +020012497 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012498 if (!hdr) {
12499 nlmsg_free(msg);
12500 return;
12501 }
12502
David S. Miller9360ffd2012-03-29 04:41:26 -040012503 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012504 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12505 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012506 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012507 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12508 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12509 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12510 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012511
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012512 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012513
Johannes Berg68eb5502013-11-19 15:19:38 +010012514 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012515 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012516 return;
12517
12518 nla_put_failure:
12519 genlmsg_cancel(msg, hdr);
12520 nlmsg_free(msg);
12521}
Johannes Berg947add32013-02-22 22:05:20 +010012522EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012523
Johannes Berg5b97f492014-11-26 12:37:43 +010012524static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12525 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012526{
Johannes Berg947add32013-02-22 22:05:20 +010012527 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012528 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12529 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12530 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012531
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012532 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012533 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012534
Johannes Berg5b97f492014-11-26 12:37:43 +010012535 cb = (void **)msg->cb;
12536
12537 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12538 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012539 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012540 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012541 }
12542
David S. Miller9360ffd2012-03-29 04:41:26 -040012543 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012544 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012545 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012546
Johannes Berg5b97f492014-11-26 12:37:43 +010012547 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012548 goto nla_put_failure;
12549
Johannes Berg5b97f492014-11-26 12:37:43 +010012550 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12551 if (!cb[1])
12552 goto nla_put_failure;
12553
12554 cb[2] = rdev;
12555
12556 return msg;
12557 nla_put_failure:
12558 nlmsg_free(msg);
12559 return NULL;
12560}
12561
12562static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12563{
12564 void **cb = (void **)msg->cb;
12565 struct cfg80211_registered_device *rdev = cb[2];
12566
12567 nla_nest_end(msg, cb[1]);
12568 genlmsg_end(msg, cb[0]);
12569
12570 memset(msg->cb, 0, sizeof(msg->cb));
12571
12572 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12573 NL80211_MCGRP_MLME, gfp);
12574}
12575
12576void cfg80211_cqm_rssi_notify(struct net_device *dev,
12577 enum nl80211_cqm_rssi_threshold_event rssi_event,
12578 gfp_t gfp)
12579{
12580 struct sk_buff *msg;
12581
12582 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12583
Johannes Berg98f03342014-11-26 12:42:02 +010012584 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12585 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12586 return;
12587
Johannes Berg5b97f492014-11-26 12:37:43 +010012588 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12589 if (!msg)
12590 return;
12591
David S. Miller9360ffd2012-03-29 04:41:26 -040012592 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12593 rssi_event))
12594 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012595
Johannes Berg5b97f492014-11-26 12:37:43 +010012596 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012597
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012598 return;
12599
12600 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012601 nlmsg_free(msg);
12602}
Johannes Berg947add32013-02-22 22:05:20 +010012603EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012604
Johannes Berg5b97f492014-11-26 12:37:43 +010012605void cfg80211_cqm_txe_notify(struct net_device *dev,
12606 const u8 *peer, u32 num_packets,
12607 u32 rate, u32 intvl, gfp_t gfp)
12608{
12609 struct sk_buff *msg;
12610
12611 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12612 if (!msg)
12613 return;
12614
12615 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12616 goto nla_put_failure;
12617
12618 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12619 goto nla_put_failure;
12620
12621 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12622 goto nla_put_failure;
12623
12624 cfg80211_send_cqm(msg, gfp);
12625 return;
12626
12627 nla_put_failure:
12628 nlmsg_free(msg);
12629}
12630EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12631
12632void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12633 const u8 *peer, u32 num_packets, gfp_t gfp)
12634{
12635 struct sk_buff *msg;
12636
12637 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12638
12639 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12640 if (!msg)
12641 return;
12642
12643 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12644 goto nla_put_failure;
12645
12646 cfg80211_send_cqm(msg, gfp);
12647 return;
12648
12649 nla_put_failure:
12650 nlmsg_free(msg);
12651}
12652EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12653
Johannes Berg98f03342014-11-26 12:42:02 +010012654void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12655{
12656 struct sk_buff *msg;
12657
12658 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12659 if (!msg)
12660 return;
12661
12662 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12663 goto nla_put_failure;
12664
12665 cfg80211_send_cqm(msg, gfp);
12666 return;
12667
12668 nla_put_failure:
12669 nlmsg_free(msg);
12670}
12671EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12672
Johannes Berg947add32013-02-22 22:05:20 +010012673static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12674 struct net_device *netdev, const u8 *bssid,
12675 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012676{
12677 struct sk_buff *msg;
12678 struct nlattr *rekey_attr;
12679 void *hdr;
12680
Thomas Graf58050fc2012-06-28 03:57:45 +000012681 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012682 if (!msg)
12683 return;
12684
12685 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12686 if (!hdr) {
12687 nlmsg_free(msg);
12688 return;
12689 }
12690
David S. Miller9360ffd2012-03-29 04:41:26 -040012691 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12692 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12693 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12694 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012695
12696 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12697 if (!rekey_attr)
12698 goto nla_put_failure;
12699
David S. Miller9360ffd2012-03-29 04:41:26 -040012700 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12701 NL80211_REPLAY_CTR_LEN, replay_ctr))
12702 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012703
12704 nla_nest_end(msg, rekey_attr);
12705
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012706 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012707
Johannes Berg68eb5502013-11-19 15:19:38 +010012708 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012709 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012710 return;
12711
12712 nla_put_failure:
12713 genlmsg_cancel(msg, hdr);
12714 nlmsg_free(msg);
12715}
12716
Johannes Berg947add32013-02-22 22:05:20 +010012717void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12718 const u8 *replay_ctr, gfp_t gfp)
12719{
12720 struct wireless_dev *wdev = dev->ieee80211_ptr;
12721 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012722 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012723
12724 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12725 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12726}
12727EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12728
12729static void
12730nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12731 struct net_device *netdev, int index,
12732 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012733{
12734 struct sk_buff *msg;
12735 struct nlattr *attr;
12736 void *hdr;
12737
Thomas Graf58050fc2012-06-28 03:57:45 +000012738 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012739 if (!msg)
12740 return;
12741
12742 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12743 if (!hdr) {
12744 nlmsg_free(msg);
12745 return;
12746 }
12747
David S. Miller9360ffd2012-03-29 04:41:26 -040012748 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12749 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12750 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012751
12752 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12753 if (!attr)
12754 goto nla_put_failure;
12755
David S. Miller9360ffd2012-03-29 04:41:26 -040012756 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12757 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12758 (preauth &&
12759 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12760 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012761
12762 nla_nest_end(msg, attr);
12763
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012764 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012765
Johannes Berg68eb5502013-11-19 15:19:38 +010012766 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012767 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012768 return;
12769
12770 nla_put_failure:
12771 genlmsg_cancel(msg, hdr);
12772 nlmsg_free(msg);
12773}
12774
Johannes Berg947add32013-02-22 22:05:20 +010012775void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12776 const u8 *bssid, bool preauth, gfp_t gfp)
12777{
12778 struct wireless_dev *wdev = dev->ieee80211_ptr;
12779 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012780 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012781
12782 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12783 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12784}
12785EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12786
12787static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12788 struct net_device *netdev,
12789 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012790 gfp_t gfp,
12791 enum nl80211_commands notif,
12792 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012793{
12794 struct sk_buff *msg;
12795 void *hdr;
12796
Thomas Graf58050fc2012-06-28 03:57:45 +000012797 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012798 if (!msg)
12799 return;
12800
Luciano Coelhof8d75522014-11-07 14:31:35 +020012801 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012802 if (!hdr) {
12803 nlmsg_free(msg);
12804 return;
12805 }
12806
Johannes Berg683b6d32012-11-08 21:25:48 +010012807 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12808 goto nla_put_failure;
12809
12810 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012811 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012812
Luciano Coelhof8d75522014-11-07 14:31:35 +020012813 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12814 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12815 goto nla_put_failure;
12816
Thomas Pedersen53145262012-04-06 13:35:47 -070012817 genlmsg_end(msg, hdr);
12818
Johannes Berg68eb5502013-11-19 15:19:38 +010012819 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012820 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012821 return;
12822
12823 nla_put_failure:
12824 genlmsg_cancel(msg, hdr);
12825 nlmsg_free(msg);
12826}
12827
Johannes Berg947add32013-02-22 22:05:20 +010012828void cfg80211_ch_switch_notify(struct net_device *dev,
12829 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012830{
Johannes Berg947add32013-02-22 22:05:20 +010012831 struct wireless_dev *wdev = dev->ieee80211_ptr;
12832 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012833 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012834
Simon Wunderliche487eae2013-11-21 18:19:51 +010012835 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012836
Simon Wunderliche487eae2013-11-21 18:19:51 +010012837 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012838
Michal Kazior9e0e2962014-01-29 14:22:27 +010012839 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012840 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012841 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12842 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012843}
12844EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12845
Luciano Coelhof8d75522014-11-07 14:31:35 +020012846void cfg80211_ch_switch_started_notify(struct net_device *dev,
12847 struct cfg80211_chan_def *chandef,
12848 u8 count)
12849{
12850 struct wireless_dev *wdev = dev->ieee80211_ptr;
12851 struct wiphy *wiphy = wdev->wiphy;
12852 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12853
12854 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12855
12856 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12857 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12858}
12859EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12860
Thomas Pedersen84f10702012-07-12 16:17:33 -070012861void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012862nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012863 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012864 enum nl80211_radar_event event,
12865 struct net_device *netdev, gfp_t gfp)
12866{
12867 struct sk_buff *msg;
12868 void *hdr;
12869
12870 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12871 if (!msg)
12872 return;
12873
12874 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12875 if (!hdr) {
12876 nlmsg_free(msg);
12877 return;
12878 }
12879
12880 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12881 goto nla_put_failure;
12882
12883 /* NOP and radar events don't need a netdev parameter */
12884 if (netdev) {
12885 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12886
12887 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12888 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12889 goto nla_put_failure;
12890 }
12891
12892 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12893 goto nla_put_failure;
12894
12895 if (nl80211_send_chandef(msg, chandef))
12896 goto nla_put_failure;
12897
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012898 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012899
Johannes Berg68eb5502013-11-19 15:19:38 +010012900 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012901 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012902 return;
12903
12904 nla_put_failure:
12905 genlmsg_cancel(msg, hdr);
12906 nlmsg_free(msg);
12907}
12908
Johannes Berg7f6cf312011-11-04 11:18:15 +010012909void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12910 u64 cookie, bool acked, gfp_t gfp)
12911{
12912 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012913 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012914 struct sk_buff *msg;
12915 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012916
Beni Lev4ee3e062012-08-27 12:49:39 +030012917 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12918
Thomas Graf58050fc2012-06-28 03:57:45 +000012919 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012920
Johannes Berg7f6cf312011-11-04 11:18:15 +010012921 if (!msg)
12922 return;
12923
12924 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12925 if (!hdr) {
12926 nlmsg_free(msg);
12927 return;
12928 }
12929
David S. Miller9360ffd2012-03-29 04:41:26 -040012930 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12931 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12932 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12933 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12934 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12935 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012936
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012937 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012938
Johannes Berg68eb5502013-11-19 15:19:38 +010012939 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012940 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012941 return;
12942
12943 nla_put_failure:
12944 genlmsg_cancel(msg, hdr);
12945 nlmsg_free(msg);
12946}
12947EXPORT_SYMBOL(cfg80211_probe_status);
12948
Johannes Berg5e760232011-11-04 11:18:17 +010012949void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12950 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012951 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012952{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012953 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012954 struct sk_buff *msg;
12955 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012956 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012957
Beni Lev4ee3e062012-08-27 12:49:39 +030012958 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12959
Ben Greear37c73b52012-10-26 14:49:25 -070012960 spin_lock_bh(&rdev->beacon_registrations_lock);
12961 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12962 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12963 if (!msg) {
12964 spin_unlock_bh(&rdev->beacon_registrations_lock);
12965 return;
12966 }
Johannes Berg5e760232011-11-04 11:18:17 +010012967
Ben Greear37c73b52012-10-26 14:49:25 -070012968 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12969 if (!hdr)
12970 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012971
Ben Greear37c73b52012-10-26 14:49:25 -070012972 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12973 (freq &&
12974 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12975 (sig_dbm &&
12976 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12977 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12978 goto nla_put_failure;
12979
12980 genlmsg_end(msg, hdr);
12981
12982 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012983 }
Ben Greear37c73b52012-10-26 14:49:25 -070012984 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012985 return;
12986
12987 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012988 spin_unlock_bh(&rdev->beacon_registrations_lock);
12989 if (hdr)
12990 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012991 nlmsg_free(msg);
12992}
12993EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12994
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012995#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012996static int cfg80211_net_detect_results(struct sk_buff *msg,
12997 struct cfg80211_wowlan_wakeup *wakeup)
12998{
12999 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
13000 struct nlattr *nl_results, *nl_match, *nl_freqs;
13001 int i, j;
13002
13003 nl_results = nla_nest_start(
13004 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
13005 if (!nl_results)
13006 return -EMSGSIZE;
13007
13008 for (i = 0; i < nd->n_matches; i++) {
13009 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
13010
13011 nl_match = nla_nest_start(msg, i);
13012 if (!nl_match)
13013 break;
13014
13015 /* The SSID attribute is optional in nl80211, but for
13016 * simplicity reasons it's always present in the
13017 * cfg80211 structure. If a driver can't pass the
13018 * SSID, that needs to be changed. A zero length SSID
13019 * is still a valid SSID (wildcard), so it cannot be
13020 * used for this purpose.
13021 */
13022 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
13023 match->ssid.ssid)) {
13024 nla_nest_cancel(msg, nl_match);
13025 goto out;
13026 }
13027
13028 if (match->n_channels) {
13029 nl_freqs = nla_nest_start(
13030 msg, NL80211_ATTR_SCAN_FREQUENCIES);
13031 if (!nl_freqs) {
13032 nla_nest_cancel(msg, nl_match);
13033 goto out;
13034 }
13035
13036 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020013037 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013038 nla_nest_cancel(msg, nl_freqs);
13039 nla_nest_cancel(msg, nl_match);
13040 goto out;
13041 }
13042 }
13043
13044 nla_nest_end(msg, nl_freqs);
13045 }
13046
13047 nla_nest_end(msg, nl_match);
13048 }
13049
13050out:
13051 nla_nest_end(msg, nl_results);
13052 return 0;
13053}
13054
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013055void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
13056 struct cfg80211_wowlan_wakeup *wakeup,
13057 gfp_t gfp)
13058{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013059 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013060 struct sk_buff *msg;
13061 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013062 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013063
13064 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13065
13066 if (wakeup)
13067 size += wakeup->packet_present_len;
13068
13069 msg = nlmsg_new(size, gfp);
13070 if (!msg)
13071 return;
13072
13073 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13074 if (!hdr)
13075 goto free_msg;
13076
13077 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13078 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13079 goto free_msg;
13080
13081 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13082 wdev->netdev->ifindex))
13083 goto free_msg;
13084
13085 if (wakeup) {
13086 struct nlattr *reasons;
13087
13088 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013089 if (!reasons)
13090 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013091
13092 if (wakeup->disconnect &&
13093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13094 goto free_msg;
13095 if (wakeup->magic_pkt &&
13096 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13097 goto free_msg;
13098 if (wakeup->gtk_rekey_failure &&
13099 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13100 goto free_msg;
13101 if (wakeup->eap_identity_req &&
13102 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13103 goto free_msg;
13104 if (wakeup->four_way_handshake &&
13105 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13106 goto free_msg;
13107 if (wakeup->rfkill_release &&
13108 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13109 goto free_msg;
13110
13111 if (wakeup->pattern_idx >= 0 &&
13112 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13113 wakeup->pattern_idx))
13114 goto free_msg;
13115
Johannes Bergae917c92013-10-25 11:05:22 +020013116 if (wakeup->tcp_match &&
13117 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13118 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013119
Johannes Bergae917c92013-10-25 11:05:22 +020013120 if (wakeup->tcp_connlost &&
13121 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13122 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013123
Johannes Bergae917c92013-10-25 11:05:22 +020013124 if (wakeup->tcp_nomoretokens &&
13125 nla_put_flag(msg,
13126 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13127 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013128
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013129 if (wakeup->packet) {
13130 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13131 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13132
13133 if (!wakeup->packet_80211) {
13134 pkt_attr =
13135 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13136 len_attr =
13137 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13138 }
13139
13140 if (wakeup->packet_len &&
13141 nla_put_u32(msg, len_attr, wakeup->packet_len))
13142 goto free_msg;
13143
13144 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13145 wakeup->packet))
13146 goto free_msg;
13147 }
13148
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013149 if (wakeup->net_detect &&
13150 cfg80211_net_detect_results(msg, wakeup))
13151 goto free_msg;
13152
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013153 nla_nest_end(msg, reasons);
13154 }
13155
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013156 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013157
Johannes Berg68eb5502013-11-19 15:19:38 +010013158 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013159 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013160 return;
13161
13162 free_msg:
13163 nlmsg_free(msg);
13164}
13165EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13166#endif
13167
Jouni Malinen3475b092012-11-16 22:49:57 +020013168void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13169 enum nl80211_tdls_operation oper,
13170 u16 reason_code, gfp_t gfp)
13171{
13172 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013173 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013174 struct sk_buff *msg;
13175 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013176
13177 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13178 reason_code);
13179
13180 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13181 if (!msg)
13182 return;
13183
13184 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13185 if (!hdr) {
13186 nlmsg_free(msg);
13187 return;
13188 }
13189
13190 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13191 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13192 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13193 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13194 (reason_code > 0 &&
13195 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13196 goto nla_put_failure;
13197
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013198 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013199
Johannes Berg68eb5502013-11-19 15:19:38 +010013200 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013201 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013202 return;
13203
13204 nla_put_failure:
13205 genlmsg_cancel(msg, hdr);
13206 nlmsg_free(msg);
13207}
13208EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13209
Jouni Malinen026331c2010-02-15 12:53:10 +020013210static int nl80211_netlink_notify(struct notifier_block * nb,
13211 unsigned long state,
13212 void *_notify)
13213{
13214 struct netlink_notify *notify = _notify;
13215 struct cfg80211_registered_device *rdev;
13216 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013217 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013218
13219 if (state != NETLINK_URELEASE)
13220 return NOTIFY_DONE;
13221
13222 rcu_read_lock();
13223
Johannes Berg5e760232011-11-04 11:18:17 +010013224 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013225 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013226 bool schedule_scan_stop = false;
13227 struct cfg80211_sched_scan_request *sched_scan_req =
13228 rcu_dereference(rdev->sched_scan_req);
13229
13230 if (sched_scan_req && notify->portid &&
13231 sched_scan_req->owner_nlportid == notify->portid)
13232 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013233
13234 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013235 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013236
Johannes Berg78f22b62014-03-24 17:57:27 +010013237 if (wdev->owner_nlportid == notify->portid)
13238 schedule_destroy_work = true;
13239 }
13240
Ben Greear37c73b52012-10-26 14:49:25 -070013241 spin_lock_bh(&rdev->beacon_registrations_lock);
13242 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13243 list) {
13244 if (reg->nlportid == notify->portid) {
13245 list_del(&reg->list);
13246 kfree(reg);
13247 break;
13248 }
13249 }
13250 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013251
13252 if (schedule_destroy_work) {
13253 struct cfg80211_iface_destroy *destroy;
13254
13255 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13256 if (destroy) {
13257 destroy->nlportid = notify->portid;
13258 spin_lock(&rdev->destroy_list_lock);
13259 list_add(&destroy->list, &rdev->destroy_list);
13260 spin_unlock(&rdev->destroy_list_lock);
13261 schedule_work(&rdev->destroy_work);
13262 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013263 } else if (schedule_scan_stop) {
13264 sched_scan_req->owner_nlportid = 0;
13265
13266 if (rdev->ops->sched_scan_stop &&
13267 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13268 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013269 }
Johannes Berg5e760232011-11-04 11:18:17 +010013270 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013271
13272 rcu_read_unlock();
13273
Ilan peer05050752015-03-04 00:32:06 -050013274 /*
13275 * It is possible that the user space process that is controlling the
13276 * indoor setting disappeared, so notify the regulatory core.
13277 */
13278 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013279 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013280}
13281
13282static struct notifier_block nl80211_netlink_notifier = {
13283 .notifier_call = nl80211_netlink_notify,
13284};
13285
Jouni Malinen355199e2013-02-27 17:14:27 +020013286void cfg80211_ft_event(struct net_device *netdev,
13287 struct cfg80211_ft_event_params *ft_event)
13288{
13289 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013290 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013291 struct sk_buff *msg;
13292 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013293
13294 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13295
13296 if (!ft_event->target_ap)
13297 return;
13298
13299 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13300 if (!msg)
13301 return;
13302
13303 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013304 if (!hdr)
13305 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013306
Johannes Bergae917c92013-10-25 11:05:22 +020013307 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13308 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13309 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13310 goto out;
13311
13312 if (ft_event->ies &&
13313 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13314 goto out;
13315 if (ft_event->ric_ies &&
13316 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13317 ft_event->ric_ies))
13318 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013319
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013320 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013321
Johannes Berg68eb5502013-11-19 15:19:38 +010013322 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013323 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013324 return;
13325 out:
13326 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013327}
13328EXPORT_SYMBOL(cfg80211_ft_event);
13329
Arend van Spriel5de17982013-04-18 15:49:00 +020013330void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13331{
13332 struct cfg80211_registered_device *rdev;
13333 struct sk_buff *msg;
13334 void *hdr;
13335 u32 nlportid;
13336
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013337 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013338 if (!rdev->crit_proto_nlportid)
13339 return;
13340
13341 nlportid = rdev->crit_proto_nlportid;
13342 rdev->crit_proto_nlportid = 0;
13343
13344 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13345 if (!msg)
13346 return;
13347
13348 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13349 if (!hdr)
13350 goto nla_put_failure;
13351
13352 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13353 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13354 goto nla_put_failure;
13355
13356 genlmsg_end(msg, hdr);
13357
13358 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13359 return;
13360
13361 nla_put_failure:
13362 if (hdr)
13363 genlmsg_cancel(msg, hdr);
13364 nlmsg_free(msg);
13365
13366}
13367EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13368
Johannes Berg348baf02014-01-24 14:06:29 +010013369void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13370{
13371 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013372 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013373 struct sk_buff *msg;
13374 void *hdr;
13375
13376 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13377 if (!msg)
13378 return;
13379
13380 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13381 if (!hdr)
13382 goto out;
13383
13384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13385 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
13386 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13387 goto out;
13388
13389 genlmsg_end(msg, hdr);
13390
13391 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13392 NL80211_MCGRP_MLME, GFP_KERNEL);
13393 return;
13394 out:
13395 nlmsg_free(msg);
13396}
13397
Johannes Berg55682962007-09-20 13:09:35 -040013398/* initialisation/exit functions */
13399
13400int nl80211_init(void)
13401{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013402 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013403
Johannes Berg2a94fe42013-11-19 15:19:39 +010013404 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13405 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013406 if (err)
13407 return err;
13408
Jouni Malinen026331c2010-02-15 12:53:10 +020013409 err = netlink_register_notifier(&nl80211_netlink_notifier);
13410 if (err)
13411 goto err_out;
13412
Johannes Berg55682962007-09-20 13:09:35 -040013413 return 0;
13414 err_out:
13415 genl_unregister_family(&nl80211_fam);
13416 return err;
13417}
13418
13419void nl80211_exit(void)
13420{
Jouni Malinen026331c2010-02-15 12:53:10 +020013421 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013422 genl_unregister_family(&nl80211_fam);
13423}