blob: 28c29e7da7499f4a1d3f830a982215504259edcf [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg7bdbe402015-08-15 22:39:49 +03006 * Copyright 2015 Intel Deutschland GmbH
Johannes Berg55682962007-09-20 13:09:35 -04007 */
8
9#include <linux/if.h>
10#include <linux/module.h>
11#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040013#include <linux/list.h>
14#include <linux/if_ether.h>
15#include <linux/ieee80211.h>
16#include <linux/nl80211.h>
17#include <linux/rtnetlink.h>
18#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010019#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020020#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040021#include <net/genetlink.h>
22#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020023#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010024#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040025#include "core.h"
26#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070027#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030028#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040029
Jouni Malinen5fb628e2011-08-10 23:54:35 +030030static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
31 struct genl_info *info,
32 struct cfg80211_crypto_settings *settings,
33 int cipher_limit);
34
Johannes Bergf84f7712013-11-14 17:14:45 +010035static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020036 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010037static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020038 struct genl_info *info);
39
Johannes Berg55682962007-09-20 13:09:35 -040040/* the netlink family */
41static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070042 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
43 .name = NL80211_GENL_NAME, /* have users key off the name instead */
44 .hdrsize = 0, /* no private header */
45 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040046 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020047 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020048 .pre_doit = nl80211_pre_doit,
49 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040050};
51
Johannes Berg2a94fe42013-11-19 15:19:39 +010052/* multicast groups */
53enum nl80211_multicast_groups {
54 NL80211_MCGRP_CONFIG,
55 NL80211_MCGRP_SCAN,
56 NL80211_MCGRP_REGULATORY,
57 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010058 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010059 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
60};
61
62static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010063 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
64 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
65 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
66 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
67 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010068#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010069 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010070#endif
71};
72
Johannes Berg89a54e42012-06-15 14:33:17 +020073/* returns ERR_PTR values */
74static struct wireless_dev *
75__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040076{
Johannes Berg89a54e42012-06-15 14:33:17 +020077 struct cfg80211_registered_device *rdev;
78 struct wireless_dev *result = NULL;
79 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
80 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
81 u64 wdev_id;
82 int wiphy_idx = -1;
83 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040084
Johannes Berg5fe231e2013-05-08 21:45:15 +020085 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040086
Johannes Berg89a54e42012-06-15 14:33:17 +020087 if (!have_ifidx && !have_wdev_id)
88 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040089
Johannes Berg89a54e42012-06-15 14:33:17 +020090 if (have_ifidx)
91 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
92 if (have_wdev_id) {
93 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
94 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040095 }
96
Johannes Berg89a54e42012-06-15 14:33:17 +020097 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
98 struct wireless_dev *wdev;
99
100 if (wiphy_net(&rdev->wiphy) != netns)
101 continue;
102
103 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
104 continue;
105
Johannes Berg89a54e42012-06-15 14:33:17 +0200106 list_for_each_entry(wdev, &rdev->wdev_list, list) {
107 if (have_ifidx && wdev->netdev &&
108 wdev->netdev->ifindex == ifidx) {
109 result = wdev;
110 break;
111 }
112 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
113 result = wdev;
114 break;
115 }
116 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200117
118 if (result)
119 break;
120 }
121
122 if (result)
123 return result;
124 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400125}
126
Johannes Berga9455402012-06-15 13:32:49 +0200127static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200128__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200129{
Johannes Berg7fee4772012-06-15 14:09:58 +0200130 struct cfg80211_registered_device *rdev = NULL, *tmp;
131 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200132
Johannes Berg5fe231e2013-05-08 21:45:15 +0200133 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200134
Johannes Berg878d9ec2012-06-15 14:18:32 +0200135 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200136 !attrs[NL80211_ATTR_IFINDEX] &&
137 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200138 return ERR_PTR(-EINVAL);
139
Johannes Berg878d9ec2012-06-15 14:18:32 +0200140 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200141 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200142 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200143
Johannes Berg89a54e42012-06-15 14:33:17 +0200144 if (attrs[NL80211_ATTR_WDEV]) {
145 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
146 struct wireless_dev *wdev;
147 bool found = false;
148
149 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
150 if (tmp) {
151 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200152 list_for_each_entry(wdev, &tmp->wdev_list, list) {
153 if (wdev->identifier != (u32)wdev_id)
154 continue;
155 found = true;
156 break;
157 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200158
159 if (!found)
160 tmp = NULL;
161
162 if (rdev && tmp != rdev)
163 return ERR_PTR(-EINVAL);
164 rdev = tmp;
165 }
166 }
167
Johannes Berg878d9ec2012-06-15 14:18:32 +0200168 if (attrs[NL80211_ATTR_IFINDEX]) {
169 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800170 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200171 if (netdev) {
172 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800173 tmp = wiphy_to_rdev(
174 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200175 else
176 tmp = NULL;
177
Johannes Berg7fee4772012-06-15 14:09:58 +0200178 /* not wireless device -- return error */
179 if (!tmp)
180 return ERR_PTR(-EINVAL);
181
182 /* mismatch -- return error */
183 if (rdev && tmp != rdev)
184 return ERR_PTR(-EINVAL);
185
186 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
Johannes Berga9455402012-06-15 13:32:49 +0200188 }
189
Johannes Berg4f7eff12012-06-15 14:14:22 +0200190 if (!rdev)
191 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200192
Johannes Berg4f7eff12012-06-15 14:14:22 +0200193 if (netns != wiphy_net(&rdev->wiphy))
194 return ERR_PTR(-ENODEV);
195
196 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200197}
198
199/*
200 * This function returns a pointer to the driver
201 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200202 *
203 * The result of this can be a PTR_ERR and hence must
204 * be checked with IS_ERR() for errors.
205 */
206static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200207cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200208{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200209 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200210}
211
Johannes Berg55682962007-09-20 13:09:35 -0400212/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300213static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400214 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
215 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700216 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200217 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100218
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200219 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530220 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100221 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
223 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
224
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200225 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
227 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
228 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100229 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200230 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400231
232 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
234 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100235
Eliad Pellere007b852011-11-24 18:13:56 +0200236 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
237 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100238
Johannes Bergb9454e82009-07-08 13:29:08 +0200239 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100240 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
241 .len = WLAN_MAX_KEY_LEN },
242 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
243 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
244 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200245 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200246 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100247
248 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
249 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
250 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
251 .len = IEEE80211_MAX_DATA_LEN },
252 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
253 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100254 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
255 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
256 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
257 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
258 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100259 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100260 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200261 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100262 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800263 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100264 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300265
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700266 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
267 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
268
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300269 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
271 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200272 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
273 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100274 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300275
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800276 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700277 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700278
Johannes Berg6c739412011-11-03 09:27:01 +0100279 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200280
281 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
282 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
283 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100284 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
285 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200286
287 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
288 .len = IEEE80211_MAX_SSID_LEN },
289 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
290 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200291 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300292 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300293 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300294 [NL80211_ATTR_STA_FLAGS2] = {
295 .len = sizeof(struct nl80211_sta_flag_update),
296 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300297 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300298 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
299 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200300 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
301 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
302 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200303 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100304 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100305 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
306 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100307 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
308 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200309 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200310 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
311 .len = IEEE80211_MAX_DATA_LEN },
312 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200313 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200314 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300315 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200316 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300317 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
318 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200319 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900320 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
321 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100322 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100323 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100324 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200325 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700326 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300327 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200328 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200329 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300330 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300331 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
332 .len = IEEE80211_MAX_DATA_LEN },
333 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
334 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530335 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300336 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530337 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300338 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
341 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
342 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300343 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100344 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200345 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
346 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700347 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800348 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
349 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
350 .len = NL80211_HT_CAPABILITY_LEN
351 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100352 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530353 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530354 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200355 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700356 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300357 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000358 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700359 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100360 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
361 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530362 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
363 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200364 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
365 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100366 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100367 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
368 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
369 .len = NL80211_VHT_CAPABILITY_LEN,
370 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200371 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
372 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
373 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300374 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200375 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
376 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
377 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300378 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
379 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530380 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
381 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200382 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100383 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100384 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
386 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800387 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
388 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200389 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
390 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530391 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200392 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300393 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300394 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300395 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
396 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
397 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300398 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200399 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200400 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200401 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200402 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500403 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400404};
405
Johannes Berge31b8212010-10-05 19:39:30 +0200406/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000407static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200408 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200409 [NL80211_KEY_IDX] = { .type = NLA_U8 },
410 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200411 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200412 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
413 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200414 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100415 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
416};
417
418/* policy for the key default flags */
419static const struct nla_policy
420nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
421 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
422 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200423};
424
Johannes Bergff1b6e62011-05-04 15:37:28 +0200425/* policy for WoWLAN attributes */
426static const struct nla_policy
427nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
428 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
431 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200432 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
435 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100436 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300437 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100438};
439
440static const struct nla_policy
441nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
442 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
443 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
444 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
445 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
446 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
448 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
449 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
450 },
451 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
452 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
453 },
454 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
455 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
456 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200457};
458
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700459/* policy for coalesce rule attributes */
460static const struct nla_policy
461nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
462 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
463 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
464 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
465};
466
Johannes Berge5497d72011-07-05 16:35:40 +0200467/* policy for GTK rekey offload attributes */
468static const struct nla_policy
469nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
470 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
471 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
472 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
473};
474
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300475static const struct nla_policy
476nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200477 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300478 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700479 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300480};
481
Avraham Stern3b06d272015-10-12 09:51:34 +0300482static const struct nla_policy
483nl80211_plan_policy[NL80211_SCHED_SCAN_PLAN_MAX + 1] = {
484 [NL80211_SCHED_SCAN_PLAN_INTERVAL] = { .type = NLA_U32 },
485 [NL80211_SCHED_SCAN_PLAN_ITERATIONS] = { .type = NLA_U32 },
486};
487
Johannes Berg97990a02013-04-19 01:02:55 +0200488static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
489 struct netlink_callback *cb,
490 struct cfg80211_registered_device **rdev,
491 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100492{
Johannes Berg67748892010-10-04 21:14:06 +0200493 int err;
494
Johannes Berg67748892010-10-04 21:14:06 +0200495 rtnl_lock();
496
Johannes Berg97990a02013-04-19 01:02:55 +0200497 if (!cb->args[0]) {
498 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
499 nl80211_fam.attrbuf, nl80211_fam.maxattr,
500 nl80211_policy);
501 if (err)
502 goto out_unlock;
503
504 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
505 nl80211_fam.attrbuf);
506 if (IS_ERR(*wdev)) {
507 err = PTR_ERR(*wdev);
508 goto out_unlock;
509 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800510 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200511 /* 0 is the first index - add 1 to parse only once */
512 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200513 cb->args[1] = (*wdev)->identifier;
514 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200515 /* subtract the 1 again here */
516 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200517 struct wireless_dev *tmp;
518
519 if (!wiphy) {
520 err = -ENODEV;
521 goto out_unlock;
522 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800523 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200524 *wdev = NULL;
525
Johannes Berg97990a02013-04-19 01:02:55 +0200526 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
527 if (tmp->identifier == cb->args[1]) {
528 *wdev = tmp;
529 break;
530 }
531 }
Johannes Berg97990a02013-04-19 01:02:55 +0200532
533 if (!*wdev) {
534 err = -ENODEV;
535 goto out_unlock;
536 }
Johannes Berg67748892010-10-04 21:14:06 +0200537 }
538
Johannes Berg67748892010-10-04 21:14:06 +0200539 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200540 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200541 rtnl_unlock();
542 return err;
543}
544
Johannes Berg97990a02013-04-19 01:02:55 +0200545static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200546{
Johannes Berg67748892010-10-04 21:14:06 +0200547 rtnl_unlock();
548}
549
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100550/* IE validation */
551static bool is_valid_ie_attr(const struct nlattr *attr)
552{
553 const u8 *pos;
554 int len;
555
556 if (!attr)
557 return true;
558
559 pos = nla_data(attr);
560 len = nla_len(attr);
561
562 while (len) {
563 u8 elemlen;
564
565 if (len < 2)
566 return false;
567 len -= 2;
568
569 elemlen = pos[1];
570 if (elemlen > len)
571 return false;
572
573 len -= elemlen;
574 pos += 2 + elemlen;
575 }
576
577 return true;
578}
579
Johannes Berg55682962007-09-20 13:09:35 -0400580/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000581static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400582 int flags, u8 cmd)
583{
584 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000585 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400586}
587
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400588static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100589 struct ieee80211_channel *chan,
590 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400591{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200592 /* Some channels must be completely excluded from the
593 * list to protect old user-space tools from breaking
594 */
595 if (!large && chan->flags &
596 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
597 return 0;
598
David S. Miller9360ffd2012-03-29 04:41:26 -0400599 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
600 chan->center_freq))
601 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400602
David S. Miller9360ffd2012-03-29 04:41:26 -0400603 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
604 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
605 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200606 if (chan->flags & IEEE80211_CHAN_NO_IR) {
607 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
608 goto nla_put_failure;
609 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
610 goto nla_put_failure;
611 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100612 if (chan->flags & IEEE80211_CHAN_RADAR) {
613 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
614 goto nla_put_failure;
615 if (large) {
616 u32 time;
617
618 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
619
620 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
621 chan->dfs_state))
622 goto nla_put_failure;
623 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
624 time))
625 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100626 if (nla_put_u32(msg,
627 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
628 chan->dfs_cac_ms))
629 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100630 }
631 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400632
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100633 if (large) {
634 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
635 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
636 goto nla_put_failure;
637 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
638 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
639 goto nla_put_failure;
640 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
641 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
642 goto nla_put_failure;
643 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
644 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
645 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200646 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
647 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
648 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300649 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
650 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200651 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200652 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
653 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
654 goto nla_put_failure;
655 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
656 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
657 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100658 }
659
David S. Miller9360ffd2012-03-29 04:41:26 -0400660 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
661 DBM_TO_MBM(chan->max_power)))
662 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400663
664 return 0;
665
666 nla_put_failure:
667 return -ENOBUFS;
668}
669
Johannes Berg55682962007-09-20 13:09:35 -0400670/* netlink command implementations */
671
Johannes Bergb9454e82009-07-08 13:29:08 +0200672struct key_parse {
673 struct key_params p;
674 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200675 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200676 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100677 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200678};
679
680static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
681{
682 struct nlattr *tb[NL80211_KEY_MAX + 1];
683 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
684 nl80211_key_policy);
685 if (err)
686 return err;
687
688 k->def = !!tb[NL80211_KEY_DEFAULT];
689 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
690
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100691 if (k->def) {
692 k->def_uni = true;
693 k->def_multi = true;
694 }
695 if (k->defmgmt)
696 k->def_multi = true;
697
Johannes Bergb9454e82009-07-08 13:29:08 +0200698 if (tb[NL80211_KEY_IDX])
699 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
700
701 if (tb[NL80211_KEY_DATA]) {
702 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
703 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
704 }
705
706 if (tb[NL80211_KEY_SEQ]) {
707 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
708 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
709 }
710
711 if (tb[NL80211_KEY_CIPHER])
712 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
713
Johannes Berge31b8212010-10-05 19:39:30 +0200714 if (tb[NL80211_KEY_TYPE]) {
715 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
716 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
717 return -EINVAL;
718 }
719
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100720 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
721 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100722 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
723 tb[NL80211_KEY_DEFAULT_TYPES],
724 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100725 if (err)
726 return err;
727
728 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
729 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
730 }
731
Johannes Bergb9454e82009-07-08 13:29:08 +0200732 return 0;
733}
734
735static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
736{
737 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
738 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
739 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
740 }
741
742 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
743 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
744 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
745 }
746
747 if (info->attrs[NL80211_ATTR_KEY_IDX])
748 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
749
750 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
751 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
752
753 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
754 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
755
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100756 if (k->def) {
757 k->def_uni = true;
758 k->def_multi = true;
759 }
760 if (k->defmgmt)
761 k->def_multi = true;
762
Johannes Berge31b8212010-10-05 19:39:30 +0200763 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
764 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
765 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
766 return -EINVAL;
767 }
768
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100769 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
770 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
771 int err = nla_parse_nested(
772 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
773 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
774 nl80211_key_default_policy);
775 if (err)
776 return err;
777
778 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
779 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
780 }
781
Johannes Bergb9454e82009-07-08 13:29:08 +0200782 return 0;
783}
784
785static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
786{
787 int err;
788
789 memset(k, 0, sizeof(*k));
790 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200791 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200792
793 if (info->attrs[NL80211_ATTR_KEY])
794 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
795 else
796 err = nl80211_parse_key_old(info, k);
797
798 if (err)
799 return err;
800
801 if (k->def && k->defmgmt)
802 return -EINVAL;
803
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100804 if (k->defmgmt) {
805 if (k->def_uni || !k->def_multi)
806 return -EINVAL;
807 }
808
Johannes Bergb9454e82009-07-08 13:29:08 +0200809 if (k->idx != -1) {
810 if (k->defmgmt) {
811 if (k->idx < 4 || k->idx > 5)
812 return -EINVAL;
813 } else if (k->def) {
814 if (k->idx < 0 || k->idx > 3)
815 return -EINVAL;
816 } else {
817 if (k->idx < 0 || k->idx > 5)
818 return -EINVAL;
819 }
820 }
821
822 return 0;
823}
824
Johannes Bergfffd0932009-07-08 14:22:54 +0200825static struct cfg80211_cached_keys *
826nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530827 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200828{
829 struct key_parse parse;
830 struct nlattr *key;
831 struct cfg80211_cached_keys *result;
832 int rem, err, def = 0;
833
834 result = kzalloc(sizeof(*result), GFP_KERNEL);
835 if (!result)
836 return ERR_PTR(-ENOMEM);
837
838 result->def = -1;
839 result->defmgmt = -1;
840
841 nla_for_each_nested(key, keys, rem) {
842 memset(&parse, 0, sizeof(parse));
843 parse.idx = -1;
844
845 err = nl80211_parse_key_new(key, &parse);
846 if (err)
847 goto error;
848 err = -EINVAL;
849 if (!parse.p.key)
850 goto error;
851 if (parse.idx < 0 || parse.idx > 4)
852 goto error;
853 if (parse.def) {
854 if (def)
855 goto error;
856 def = 1;
857 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100858 if (!parse.def_uni || !parse.def_multi)
859 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200860 } else if (parse.defmgmt)
861 goto error;
862 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200863 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200864 if (err)
865 goto error;
866 result->params[parse.idx].cipher = parse.p.cipher;
867 result->params[parse.idx].key_len = parse.p.key_len;
868 result->params[parse.idx].key = result->data[parse.idx];
869 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530870
871 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
872 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
873 if (no_ht)
874 *no_ht = true;
875 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200876 }
877
878 return result;
879 error:
880 kfree(result);
881 return ERR_PTR(err);
882}
883
884static int nl80211_key_allowed(struct wireless_dev *wdev)
885{
886 ASSERT_WDEV_LOCK(wdev);
887
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 switch (wdev->iftype) {
889 case NL80211_IFTYPE_AP:
890 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200891 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700892 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200893 break;
894 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200895 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200896 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200897 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200898 return -ENOLINK;
899 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100900 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100901 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100902 case NL80211_IFTYPE_MONITOR:
903 case NL80211_IFTYPE_P2P_DEVICE:
904 case NL80211_IFTYPE_WDS:
905 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200906 return -EINVAL;
907 }
908
909 return 0;
910}
911
Jouni Malinen664834d2014-01-15 00:01:44 +0200912static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
913 struct nlattr *tb)
914{
915 struct ieee80211_channel *chan;
916
917 if (tb == NULL)
918 return NULL;
919 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
920 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
921 return NULL;
922 return chan;
923}
924
Johannes Berg7527a782011-05-13 10:58:57 +0200925static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
926{
927 struct nlattr *nl_modes = nla_nest_start(msg, attr);
928 int i;
929
930 if (!nl_modes)
931 goto nla_put_failure;
932
933 i = 0;
934 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400935 if ((ifmodes & 1) && nla_put_flag(msg, i))
936 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200937 ifmodes >>= 1;
938 i++;
939 }
940
941 nla_nest_end(msg, nl_modes);
942 return 0;
943
944nla_put_failure:
945 return -ENOBUFS;
946}
947
948static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100949 struct sk_buff *msg,
950 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200951{
952 struct nlattr *nl_combis;
953 int i, j;
954
955 nl_combis = nla_nest_start(msg,
956 NL80211_ATTR_INTERFACE_COMBINATIONS);
957 if (!nl_combis)
958 goto nla_put_failure;
959
960 for (i = 0; i < wiphy->n_iface_combinations; i++) {
961 const struct ieee80211_iface_combination *c;
962 struct nlattr *nl_combi, *nl_limits;
963
964 c = &wiphy->iface_combinations[i];
965
966 nl_combi = nla_nest_start(msg, i + 1);
967 if (!nl_combi)
968 goto nla_put_failure;
969
970 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
971 if (!nl_limits)
972 goto nla_put_failure;
973
974 for (j = 0; j < c->n_limits; j++) {
975 struct nlattr *nl_limit;
976
977 nl_limit = nla_nest_start(msg, j + 1);
978 if (!nl_limit)
979 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400980 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
981 c->limits[j].max))
982 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200983 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
984 c->limits[j].types))
985 goto nla_put_failure;
986 nla_nest_end(msg, nl_limit);
987 }
988
989 nla_nest_end(msg, nl_limits);
990
David S. Miller9360ffd2012-03-29 04:41:26 -0400991 if (c->beacon_int_infra_match &&
992 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
993 goto nla_put_failure;
994 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
995 c->num_different_channels) ||
996 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
997 c->max_interfaces))
998 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100999 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +02001000 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
1001 c->radar_detect_widths) ||
1002 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
1003 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +01001004 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +02001005
1006 nla_nest_end(msg, nl_combi);
1007 }
1008
1009 nla_nest_end(msg, nl_combis);
1010
1011 return 0;
1012nla_put_failure:
1013 return -ENOBUFS;
1014}
1015
Johannes Berg3713b4e2013-02-14 16:19:38 +01001016#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001017static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1018 struct sk_buff *msg)
1019{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001020 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001021 struct nlattr *nl_tcp;
1022
1023 if (!tcp)
1024 return 0;
1025
1026 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1027 if (!nl_tcp)
1028 return -ENOBUFS;
1029
1030 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1031 tcp->data_payload_max))
1032 return -ENOBUFS;
1033
1034 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1035 tcp->data_payload_max))
1036 return -ENOBUFS;
1037
1038 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1039 return -ENOBUFS;
1040
1041 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1042 sizeof(*tcp->tok), tcp->tok))
1043 return -ENOBUFS;
1044
1045 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1046 tcp->data_interval_max))
1047 return -ENOBUFS;
1048
1049 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1050 tcp->wake_payload_max))
1051 return -ENOBUFS;
1052
1053 nla_nest_end(msg, nl_tcp);
1054 return 0;
1055}
1056
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001058 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001059 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001060{
1061 struct nlattr *nl_wowlan;
1062
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064 return 0;
1065
1066 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1067 if (!nl_wowlan)
1068 return -ENOBUFS;
1069
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001071 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001073 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001074 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001077 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001078 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001079 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001080 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001081 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001082 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001083 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001084 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001085 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1086 return -ENOBUFS;
1087
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001088 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001089 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1091 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1092 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1093 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001094 };
1095
1096 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1097 sizeof(pat), &pat))
1098 return -ENOBUFS;
1099 }
1100
Luciano Coelho75453cc2015-01-09 14:06:37 +02001101 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1102 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1103 rdev->wiphy.wowlan->max_nd_match_sets))
1104 return -ENOBUFS;
1105
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001106 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001107 return -ENOBUFS;
1108
Johannes Berg3713b4e2013-02-14 16:19:38 +01001109 nla_nest_end(msg, nl_wowlan);
1110
1111 return 0;
1112}
1113#endif
1114
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001115static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001116 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001117{
1118 struct nl80211_coalesce_rule_support rule;
1119
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001120 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001121 return 0;
1122
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001123 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1124 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1125 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1126 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1127 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1128 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001129
1130 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1131 return -ENOBUFS;
1132
1133 return 0;
1134}
1135
Johannes Berg3713b4e2013-02-14 16:19:38 +01001136static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1137 struct ieee80211_supported_band *sband)
1138{
1139 struct nlattr *nl_rates, *nl_rate;
1140 struct ieee80211_rate *rate;
1141 int i;
1142
1143 /* add HT info */
1144 if (sband->ht_cap.ht_supported &&
1145 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1146 sizeof(sband->ht_cap.mcs),
1147 &sband->ht_cap.mcs) ||
1148 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1149 sband->ht_cap.cap) ||
1150 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1151 sband->ht_cap.ampdu_factor) ||
1152 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1153 sband->ht_cap.ampdu_density)))
1154 return -ENOBUFS;
1155
1156 /* add VHT info */
1157 if (sband->vht_cap.vht_supported &&
1158 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1159 sizeof(sband->vht_cap.vht_mcs),
1160 &sband->vht_cap.vht_mcs) ||
1161 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1162 sband->vht_cap.cap)))
1163 return -ENOBUFS;
1164
1165 /* add bitrates */
1166 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1167 if (!nl_rates)
1168 return -ENOBUFS;
1169
1170 for (i = 0; i < sband->n_bitrates; i++) {
1171 nl_rate = nla_nest_start(msg, i);
1172 if (!nl_rate)
1173 return -ENOBUFS;
1174
1175 rate = &sband->bitrates[i];
1176 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1177 rate->bitrate))
1178 return -ENOBUFS;
1179 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1180 nla_put_flag(msg,
1181 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1182 return -ENOBUFS;
1183
1184 nla_nest_end(msg, nl_rate);
1185 }
1186
1187 nla_nest_end(msg, nl_rates);
1188
1189 return 0;
1190}
1191
1192static int
1193nl80211_send_mgmt_stypes(struct sk_buff *msg,
1194 const struct ieee80211_txrx_stypes *mgmt_stypes)
1195{
1196 u16 stypes;
1197 struct nlattr *nl_ftypes, *nl_ifs;
1198 enum nl80211_iftype ift;
1199 int i;
1200
1201 if (!mgmt_stypes)
1202 return 0;
1203
1204 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1205 if (!nl_ifs)
1206 return -ENOBUFS;
1207
1208 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1209 nl_ftypes = nla_nest_start(msg, ift);
1210 if (!nl_ftypes)
1211 return -ENOBUFS;
1212 i = 0;
1213 stypes = mgmt_stypes[ift].tx;
1214 while (stypes) {
1215 if ((stypes & 1) &&
1216 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1217 (i << 4) | IEEE80211_FTYPE_MGMT))
1218 return -ENOBUFS;
1219 stypes >>= 1;
1220 i++;
1221 }
1222 nla_nest_end(msg, nl_ftypes);
1223 }
1224
1225 nla_nest_end(msg, nl_ifs);
1226
1227 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1228 if (!nl_ifs)
1229 return -ENOBUFS;
1230
1231 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1232 nl_ftypes = nla_nest_start(msg, ift);
1233 if (!nl_ftypes)
1234 return -ENOBUFS;
1235 i = 0;
1236 stypes = mgmt_stypes[ift].rx;
1237 while (stypes) {
1238 if ((stypes & 1) &&
1239 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1240 (i << 4) | IEEE80211_FTYPE_MGMT))
1241 return -ENOBUFS;
1242 stypes >>= 1;
1243 i++;
1244 }
1245 nla_nest_end(msg, nl_ftypes);
1246 }
1247 nla_nest_end(msg, nl_ifs);
1248
1249 return 0;
1250}
1251
Johannes Berg86e8cf92013-06-19 10:57:22 +02001252struct nl80211_dump_wiphy_state {
1253 s64 filter_wiphy;
1254 long start;
1255 long split_start, band_start, chan_start;
1256 bool split;
1257};
1258
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001259static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001260 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001261 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001262 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001263{
1264 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001265 struct nlattr *nl_bands, *nl_band;
1266 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001267 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001268 enum ieee80211_band band;
1269 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001270 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001271 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001272 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001273 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001274
Johannes Berg3bb20552014-05-26 13:52:25 +02001275 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001276 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 return -ENOBUFS;
1278
Johannes Berg86e8cf92013-06-19 10:57:22 +02001279 if (WARN_ON(!state))
1280 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001281
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001282 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001283 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001284 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001285 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001287 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001288
Johannes Berg3bb20552014-05-26 13:52:25 +02001289 if (cmd != NL80211_CMD_NEW_WIPHY)
1290 goto finish;
1291
Johannes Berg86e8cf92013-06-19 10:57:22 +02001292 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 case 0:
1294 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001295 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001296 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001297 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001299 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001300 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001303 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001305 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001307 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001308 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Avraham Stern3b06d272015-10-12 09:51:34 +03001313 rdev->wiphy.max_match_sets) ||
1314 nla_put_u32(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_PLANS,
1315 rdev->wiphy.max_sched_scan_plans) ||
1316 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_INTERVAL,
1317 rdev->wiphy.max_sched_scan_plan_interval) ||
1318 nla_put_u32(msg, NL80211_ATTR_MAX_SCAN_PLAN_ITERATIONS,
1319 rdev->wiphy.max_sched_scan_plan_iterations))
Johannes Bergee688b002008-01-24 19:38:39 +01001320 goto nla_put_failure;
1321
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001322 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1324 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001326 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1327 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001328 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1330 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001331 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001332 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1333 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001335 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1336 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001339 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001340 state->split_start++;
1341 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 break;
1343 case 1:
1344 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001345 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1346 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001347 goto nla_put_failure;
1348
Johannes Berg3713b4e2013-02-14 16:19:38 +01001349 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001350 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001351 goto nla_put_failure;
1352
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001353 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1355 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001356
Johannes Berg3713b4e2013-02-14 16:19:38 +01001357 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001358 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001359 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001360 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001362
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001363 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001364 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001365 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001366 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001367
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001368 if ((rdev->wiphy.available_antennas_tx ||
1369 rdev->wiphy.available_antennas_rx) &&
1370 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 u32 tx_ant = 0, rx_ant = 0;
1372 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001373 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 if (!res) {
1375 if (nla_put_u32(msg,
1376 NL80211_ATTR_WIPHY_ANTENNA_TX,
1377 tx_ant) ||
1378 nla_put_u32(msg,
1379 NL80211_ATTR_WIPHY_ANTENNA_RX,
1380 rx_ant))
1381 goto nla_put_failure;
1382 }
Johannes Bergee688b002008-01-24 19:38:39 +01001383 }
1384
Johannes Berg86e8cf92013-06-19 10:57:22 +02001385 state->split_start++;
1386 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001387 break;
1388 case 2:
1389 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001390 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001391 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001392 state->split_start++;
1393 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394 break;
1395 case 3:
1396 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1397 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001398 goto nla_put_failure;
1399
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 for (band = state->band_start;
1401 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001402 struct ieee80211_supported_band *sband;
1403
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001404 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001405
1406 if (!sband)
1407 continue;
1408
1409 nl_band = nla_nest_start(msg, band);
1410 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001411 goto nla_put_failure;
1412
Johannes Berg86e8cf92013-06-19 10:57:22 +02001413 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001414 case 0:
1415 if (nl80211_send_band_rateinfo(msg, sband))
1416 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001417 state->chan_start++;
1418 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 break;
1420 default:
1421 /* add frequencies */
1422 nl_freqs = nla_nest_start(
1423 msg, NL80211_BAND_ATTR_FREQS);
1424 if (!nl_freqs)
1425 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001426
Johannes Berg86e8cf92013-06-19 10:57:22 +02001427 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 i < sband->n_channels;
1429 i++) {
1430 nl_freq = nla_nest_start(msg, i);
1431 if (!nl_freq)
1432 goto nla_put_failure;
1433
1434 chan = &sband->channels[i];
1435
Johannes Berg86e8cf92013-06-19 10:57:22 +02001436 if (nl80211_msg_put_channel(
1437 msg, chan,
1438 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001439 goto nla_put_failure;
1440
1441 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001442 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 break;
1444 }
1445 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001447 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001448 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 nla_nest_end(msg, nl_freqs);
1450 }
1451
1452 nla_nest_end(msg, nl_band);
1453
Johannes Berg86e8cf92013-06-19 10:57:22 +02001454 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001456 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 band--;
1458 break;
1459 }
Johannes Bergee688b002008-01-24 19:38:39 +01001460 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001462
Johannes Berg3713b4e2013-02-14 16:19:38 +01001463 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001464 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001466 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001467
Johannes Berg3713b4e2013-02-14 16:19:38 +01001468 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001469 if (state->band_start == 0 && state->chan_start == 0)
1470 state->split_start++;
1471 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001472 break;
1473 case 4:
1474 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1475 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001476 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001477
1478 i = 0;
1479#define CMD(op, n) \
1480 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001481 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001482 i++; \
1483 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1484 goto nla_put_failure; \
1485 } \
1486 } while (0)
1487
1488 CMD(add_virtual_intf, NEW_INTERFACE);
1489 CMD(change_virtual_intf, SET_INTERFACE);
1490 CMD(add_key, NEW_KEY);
1491 CMD(start_ap, START_AP);
1492 CMD(add_station, NEW_STATION);
1493 CMD(add_mpath, NEW_MPATH);
1494 CMD(update_mesh_config, SET_MESH_CONFIG);
1495 CMD(change_bss, SET_BSS);
1496 CMD(auth, AUTHENTICATE);
1497 CMD(assoc, ASSOCIATE);
1498 CMD(deauth, DEAUTHENTICATE);
1499 CMD(disassoc, DISASSOCIATE);
1500 CMD(join_ibss, JOIN_IBSS);
1501 CMD(join_mesh, JOIN_MESH);
1502 CMD(set_pmksa, SET_PMKSA);
1503 CMD(del_pmksa, DEL_PMKSA);
1504 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001505 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1507 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1508 CMD(mgmt_tx, FRAME);
1509 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001510 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 i++;
1512 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1513 goto nla_put_failure;
1514 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001515 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1516 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001517 i++;
1518 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1519 goto nla_put_failure;
1520 }
1521 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001522 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001523 CMD(tdls_mgmt, TDLS_MGMT);
1524 CMD(tdls_oper, TDLS_OPER);
1525 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001526 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001527 CMD(sched_scan_start, START_SCHED_SCAN);
1528 CMD(probe_client, PROBE_CLIENT);
1529 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001531 i++;
1532 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1533 goto nla_put_failure;
1534 }
1535 CMD(start_p2p_device, START_P2P_DEVICE);
1536 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001537#ifdef CONFIG_NL80211_TESTMODE
1538 CMD(testmode_cmd, TESTMODE);
1539#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001540 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001541 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1542 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001543 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001544 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001545 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001546 if (rdev->wiphy.features &
1547 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001548 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001549 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001550 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001551#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001552
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001553 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 i++;
1555 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001556 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001557 }
1558
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 i++;
1561 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1562 goto nla_put_failure;
1563 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001564
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001566 state->split_start++;
1567 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 break;
1569 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001570 if (rdev->ops->remain_on_channel &&
1571 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 nla_put_u32(msg,
1573 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001574 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001575 goto nla_put_failure;
1576
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001577 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001578 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1579 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001580
Johannes Berg3713b4e2013-02-14 16:19:38 +01001581 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1582 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 state->split_start++;
1584 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001585 break;
1586 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001587#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001589 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001590 state->split_start++;
1591 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 break;
1593#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001594 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001595#endif
1596 case 7:
1597 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001599 goto nla_put_failure;
1600
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001601 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001602 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001604
Johannes Berg86e8cf92013-06-19 10:57:22 +02001605 state->split_start++;
1606 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001607 break;
1608 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001609 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001611 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612 goto nla_put_failure;
1613
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001615 /*
1616 * We can only add the per-channel limit information if the
1617 * dump is split, otherwise it makes it too big. Therefore
1618 * only advertise it in that case.
1619 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001620 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001621 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1622 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 goto nla_put_failure;
1624
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001625 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001626 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001627 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1628 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001629 goto nla_put_failure;
1630
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001631 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1632 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001633 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001634 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 goto nla_put_failure;
1636
1637 /*
1638 * Any information below this point is only available to
1639 * applications that can deal with it being split. This
1640 * helps ensure that newly added capabilities don't break
1641 * older tools by overrunning their buffers.
1642 *
1643 * We still increment split_start so that in the split
1644 * case we'll continue with more data in the next round,
1645 * but break unconditionally so unsplit data stops here.
1646 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001647 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001648 break;
1649 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001650 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001651 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001652 rdev->wiphy.extended_capabilities_len,
1653 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001654 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001655 rdev->wiphy.extended_capabilities_len,
1656 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001657 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001658
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001659 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001660 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001661 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1662 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001663 goto nla_put_failure;
1664
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001665 state->split_start++;
1666 break;
1667 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001668 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001669 goto nla_put_failure;
1670
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001672 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1673 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1674 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001675
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001676 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001677 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001678 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001679 goto nla_put_failure;
1680
Johannes Bergad7e7182013-11-13 13:37:47 +01001681 state->split_start++;
1682 break;
1683 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001684 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001685 const struct nl80211_vendor_cmd_info *info;
1686 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001687
Johannes Berg567ffc32013-12-18 14:43:31 +01001688 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1689 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001690 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001691
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001692 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1693 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001694 if (nla_put(msg, i + 1, sizeof(*info), info))
1695 goto nla_put_failure;
1696 }
1697 nla_nest_end(msg, nested);
1698 }
1699
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001700 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001701 const struct nl80211_vendor_cmd_info *info;
1702 struct nlattr *nested;
1703
1704 nested = nla_nest_start(msg,
1705 NL80211_ATTR_VENDOR_EVENTS);
1706 if (!nested)
1707 goto nla_put_failure;
1708
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001709 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1710 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001711 if (nla_put(msg, i + 1, sizeof(*info), info))
1712 goto nla_put_failure;
1713 }
1714 nla_nest_end(msg, nested);
1715 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001716 state->split_start++;
1717 break;
1718 case 12:
1719 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1720 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1721 rdev->wiphy.max_num_csa_counters))
1722 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001723
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001724 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1725 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1726 goto nla_put_failure;
1727
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001728 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1729 sizeof(rdev->wiphy.ext_features),
1730 rdev->wiphy.ext_features))
1731 goto nla_put_failure;
1732
Johannes Berg3713b4e2013-02-14 16:19:38 +01001733 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001734 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001735 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001736 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001737 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001738 genlmsg_end(msg, hdr);
1739 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001740
1741 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001742 genlmsg_cancel(msg, hdr);
1743 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001744}
1745
Johannes Berg86e8cf92013-06-19 10:57:22 +02001746static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1747 struct netlink_callback *cb,
1748 struct nl80211_dump_wiphy_state *state)
1749{
1750 struct nlattr **tb = nl80211_fam.attrbuf;
1751 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1752 tb, nl80211_fam.maxattr, nl80211_policy);
1753 /* ignore parse errors for backward compatibility */
1754 if (ret)
1755 return 0;
1756
1757 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1758 if (tb[NL80211_ATTR_WIPHY])
1759 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1760 if (tb[NL80211_ATTR_WDEV])
1761 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1762 if (tb[NL80211_ATTR_IFINDEX]) {
1763 struct net_device *netdev;
1764 struct cfg80211_registered_device *rdev;
1765 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1766
Ying Xue7f2b8562014-01-15 10:23:45 +08001767 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001768 if (!netdev)
1769 return -ENODEV;
1770 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001771 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001772 netdev->ieee80211_ptr->wiphy);
1773 state->filter_wiphy = rdev->wiphy_idx;
1774 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001775 }
1776
1777 return 0;
1778}
1779
Johannes Berg55682962007-09-20 13:09:35 -04001780static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1781{
Johannes Berg645e77d2013-03-01 14:03:49 +01001782 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001783 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001784 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001785
Johannes Berg5fe231e2013-05-08 21:45:15 +02001786 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001787 if (!state) {
1788 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001789 if (!state) {
1790 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001791 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001792 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001793 state->filter_wiphy = -1;
1794 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1795 if (ret) {
1796 kfree(state);
1797 rtnl_unlock();
1798 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001799 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001800 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001801 }
1802
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001803 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1804 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001805 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001806 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001807 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001808 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001809 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001810 continue;
1811 /* attempt to fit multiple wiphy data chunks into the skb */
1812 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001813 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1814 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001815 NETLINK_CB(cb->skb).portid,
1816 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001817 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001818 if (ret < 0) {
1819 /*
1820 * If sending the wiphy data didn't fit (ENOBUFS
1821 * or EMSGSIZE returned), this SKB is still
1822 * empty (so it's not too big because another
1823 * wiphy dataset is already in the skb) and
1824 * we've not tried to adjust the dump allocation
1825 * yet ... then adjust the alloc size to be
1826 * bigger, and return 1 but with the empty skb.
1827 * This results in an empty message being RX'ed
1828 * in userspace, but that is ignored.
1829 *
1830 * We can then retry with the larger buffer.
1831 */
1832 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001833 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001834 cb->min_dump_alloc < 4096) {
1835 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001836 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001837 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001838 return 1;
1839 }
1840 idx--;
1841 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001842 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001843 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001844 break;
Johannes Berg55682962007-09-20 13:09:35 -04001845 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001846 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001847
Johannes Berg86e8cf92013-06-19 10:57:22 +02001848 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001849
1850 return skb->len;
1851}
1852
Johannes Berg86e8cf92013-06-19 10:57:22 +02001853static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1854{
1855 kfree((void *)cb->args[0]);
1856 return 0;
1857}
1858
Johannes Berg55682962007-09-20 13:09:35 -04001859static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1860{
1861 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001863 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001864
Johannes Berg645e77d2013-03-01 14:03:49 +01001865 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001866 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001867 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001868
Johannes Berg3bb20552014-05-26 13:52:25 +02001869 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1870 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001871 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001872 nlmsg_free(msg);
1873 return -ENOBUFS;
1874 }
Johannes Berg55682962007-09-20 13:09:35 -04001875
Johannes Berg134e6372009-07-10 09:51:34 +00001876 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001877}
1878
Jouni Malinen31888482008-10-30 16:59:24 +02001879static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1880 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1881 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1882 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1883 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1884 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1885};
1886
1887static int parse_txq_params(struct nlattr *tb[],
1888 struct ieee80211_txq_params *txq_params)
1889{
Johannes Berga3304b02012-03-28 11:04:24 +02001890 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001891 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1892 !tb[NL80211_TXQ_ATTR_AIFS])
1893 return -EINVAL;
1894
Johannes Berga3304b02012-03-28 11:04:24 +02001895 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001896 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1897 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1898 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1899 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1900
Johannes Berga3304b02012-03-28 11:04:24 +02001901 if (txq_params->ac >= NL80211_NUM_ACS)
1902 return -EINVAL;
1903
Jouni Malinen31888482008-10-30 16:59:24 +02001904 return 0;
1905}
1906
Johannes Bergf444de02010-05-05 15:25:02 +02001907static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1908{
1909 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001910 * You can only set the channel explicitly for WDS interfaces,
1911 * all others have their channel managed via their respective
1912 * "establish a connection" command (connect, join, ...)
1913 *
1914 * For AP/GO and mesh mode, the channel can be set with the
1915 * channel userspace API, but is only stored and passed to the
1916 * low-level driver when the AP starts or the mesh is joined.
1917 * This is for backward compatibility, userspace can also give
1918 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001919 *
1920 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001921 * whatever else is going on, so they have their own special
1922 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001923 */
1924 return !wdev ||
1925 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001926 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001927 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1928 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001929}
1930
Johannes Berg683b6d32012-11-08 21:25:48 +01001931static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1932 struct genl_info *info,
1933 struct cfg80211_chan_def *chandef)
1934{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301935 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001936
1937 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1938 return -EINVAL;
1939
1940 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1941
1942 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001943 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1944 chandef->center_freq1 = control_freq;
1945 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001946
1947 /* Primary channel not allowed */
1948 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1949 return -EINVAL;
1950
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001951 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1952 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001953
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001954 chantype = nla_get_u32(
1955 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1956
1957 switch (chantype) {
1958 case NL80211_CHAN_NO_HT:
1959 case NL80211_CHAN_HT20:
1960 case NL80211_CHAN_HT40PLUS:
1961 case NL80211_CHAN_HT40MINUS:
1962 cfg80211_chandef_create(chandef, chandef->chan,
1963 chantype);
1964 break;
1965 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001966 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001967 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001968 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1969 chandef->width =
1970 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1971 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1972 chandef->center_freq1 =
1973 nla_get_u32(
1974 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1975 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1976 chandef->center_freq2 =
1977 nla_get_u32(
1978 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1979 }
1980
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001981 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001982 return -EINVAL;
1983
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001984 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1985 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001986 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001987
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001988 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1989 chandef->width == NL80211_CHAN_WIDTH_10) &&
1990 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1991 return -EINVAL;
1992
Johannes Berg683b6d32012-11-08 21:25:48 +01001993 return 0;
1994}
1995
Johannes Bergf444de02010-05-05 15:25:02 +02001996static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001997 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001998 struct genl_info *info)
1999{
Johannes Berg683b6d32012-11-08 21:25:48 +01002000 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02002001 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002002 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03002003 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002004
Jouni Malinene16821b2014-04-28 11:22:08 +03002005 if (dev)
2006 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002007 if (!nl80211_can_set_dev_channel(wdev))
2008 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03002009 if (wdev)
2010 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002011
Johannes Berg683b6d32012-11-08 21:25:48 +01002012 result = nl80211_parse_chandef(rdev, info, &chandef);
2013 if (result)
2014 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002015
Johannes Berge8c9bd52012-06-06 08:18:22 +02002016 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002017 case NL80211_IFTYPE_AP:
2018 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002019 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2020 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002021 result = -EINVAL;
2022 break;
2023 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002024 if (wdev->beacon_interval) {
2025 if (!dev || !rdev->ops->set_ap_chanwidth ||
2026 !(rdev->wiphy.features &
2027 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2028 result = -EBUSY;
2029 break;
2030 }
2031
2032 /* Only allow dynamic channel width changes */
2033 if (chandef.chan != wdev->preset_chandef.chan) {
2034 result = -EBUSY;
2035 break;
2036 }
2037 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2038 if (result)
2039 break;
2040 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002041 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002042 result = 0;
2043 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002044 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002045 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002046 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002047 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002048 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002049 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002050 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002051 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002052 }
Johannes Bergf444de02010-05-05 15:25:02 +02002053
2054 return result;
2055}
2056
2057static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2058{
Johannes Berg4c476992010-10-04 21:36:35 +02002059 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2060 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002061
Jouni Malinene16821b2014-04-28 11:22:08 +03002062 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002063}
2064
Bill Jordane8347eb2010-10-01 13:54:28 -04002065static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2066{
Johannes Berg43b19952010-10-07 13:10:30 +02002067 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2068 struct net_device *dev = info->user_ptr[1];
2069 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002070 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002071
2072 if (!info->attrs[NL80211_ATTR_MAC])
2073 return -EINVAL;
2074
Johannes Berg43b19952010-10-07 13:10:30 +02002075 if (netif_running(dev))
2076 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002077
Johannes Berg43b19952010-10-07 13:10:30 +02002078 if (!rdev->ops->set_wds_peer)
2079 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002080
Johannes Berg43b19952010-10-07 13:10:30 +02002081 if (wdev->iftype != NL80211_IFTYPE_WDS)
2082 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002083
2084 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002085 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002086}
2087
2088
Johannes Berg55682962007-09-20 13:09:35 -04002089static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2090{
2091 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002092 struct net_device *netdev = NULL;
2093 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002094 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002095 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002096 u32 changed;
2097 u8 retry_short = 0, retry_long = 0;
2098 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002099 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002100
Johannes Berg5fe231e2013-05-08 21:45:15 +02002101 ASSERT_RTNL();
2102
Johannes Bergf444de02010-05-05 15:25:02 +02002103 /*
2104 * Try to find the wiphy and netdev. Normally this
2105 * function shouldn't need the netdev, but this is
2106 * done for backward compatibility -- previously
2107 * setting the channel was done per wiphy, but now
2108 * it is per netdev. Previous userland like hostapd
2109 * also passed a netdev to set_wiphy, so that it is
2110 * possible to let that go to the right netdev!
2111 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002112
Johannes Bergf444de02010-05-05 15:25:02 +02002113 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2114 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2115
Ying Xue7f2b8562014-01-15 10:23:45 +08002116 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002117 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002118 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002119 else
Johannes Bergf444de02010-05-05 15:25:02 +02002120 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002121 }
2122
Johannes Bergf444de02010-05-05 15:25:02 +02002123 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002124 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2125 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002126 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002127 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002128 wdev = NULL;
2129 netdev = NULL;
2130 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002131 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002132 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002133
2134 /*
2135 * end workaround code, by now the rdev is available
2136 * and locked, and wdev may or may not be NULL.
2137 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002138
2139 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002140 result = cfg80211_dev_rename(
2141 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002142
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002143 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002144 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002145
Jouni Malinen31888482008-10-30 16:59:24 +02002146 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2147 struct ieee80211_txq_params txq_params;
2148 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2149
Ying Xue7f2b8562014-01-15 10:23:45 +08002150 if (!rdev->ops->set_txq_params)
2151 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002152
Ying Xue7f2b8562014-01-15 10:23:45 +08002153 if (!netdev)
2154 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002155
Johannes Berg133a3ff2011-11-03 14:50:13 +01002156 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002157 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2158 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002159
Ying Xue7f2b8562014-01-15 10:23:45 +08002160 if (!netif_running(netdev))
2161 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002162
Jouni Malinen31888482008-10-30 16:59:24 +02002163 nla_for_each_nested(nl_txq_params,
2164 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2165 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002166 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2167 nla_data(nl_txq_params),
2168 nla_len(nl_txq_params),
2169 txq_params_policy);
2170 if (result)
2171 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002172 result = parse_txq_params(tb, &txq_params);
2173 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002174 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002175
Hila Gonene35e4d22012-06-27 17:19:42 +03002176 result = rdev_set_txq_params(rdev, netdev,
2177 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002178 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002179 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002180 }
2181 }
2182
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002183 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002184 result = __nl80211_set_channel(
2185 rdev,
2186 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2187 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002188 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002189 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002190 }
2191
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002192 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002193 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002194 enum nl80211_tx_power_setting type;
2195 int idx, mbm = 0;
2196
Johannes Bergc8442112012-10-24 10:17:18 +02002197 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2198 txp_wdev = NULL;
2199
Ying Xue7f2b8562014-01-15 10:23:45 +08002200 if (!rdev->ops->set_tx_power)
2201 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002202
2203 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2204 type = nla_get_u32(info->attrs[idx]);
2205
2206 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002207 (type != NL80211_TX_POWER_AUTOMATIC))
2208 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002209
2210 if (type != NL80211_TX_POWER_AUTOMATIC) {
2211 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2212 mbm = nla_get_u32(info->attrs[idx]);
2213 }
2214
Johannes Bergc8442112012-10-24 10:17:18 +02002215 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002216 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002217 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002218 }
2219
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002220 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2221 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2222 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002223 if ((!rdev->wiphy.available_antennas_tx &&
2224 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002225 !rdev->ops->set_antenna)
2226 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002227
2228 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2229 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2230
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002231 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002232 * available antenna masks, except for the "all" mask */
2233 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002234 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2235 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002236
Bruno Randolf7f531e02010-12-16 11:30:22 +09002237 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2238 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002239
Hila Gonene35e4d22012-06-27 17:19:42 +03002240 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002241 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002242 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002243 }
2244
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002245 changed = 0;
2246
2247 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2248 retry_short = nla_get_u8(
2249 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002250 if (retry_short == 0)
2251 return -EINVAL;
2252
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002253 changed |= WIPHY_PARAM_RETRY_SHORT;
2254 }
2255
2256 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2257 retry_long = nla_get_u8(
2258 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002259 if (retry_long == 0)
2260 return -EINVAL;
2261
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002262 changed |= WIPHY_PARAM_RETRY_LONG;
2263 }
2264
2265 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2266 frag_threshold = nla_get_u32(
2267 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002268 if (frag_threshold < 256)
2269 return -EINVAL;
2270
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002271 if (frag_threshold != (u32) -1) {
2272 /*
2273 * Fragments (apart from the last one) are required to
2274 * have even length. Make the fragmentation code
2275 * simpler by stripping LSB should someone try to use
2276 * odd threshold value.
2277 */
2278 frag_threshold &= ~0x1;
2279 }
2280 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2281 }
2282
2283 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2284 rts_threshold = nla_get_u32(
2285 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2286 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2287 }
2288
Lukáš Turek81077e82009-12-21 22:50:47 +01002289 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002290 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2291 return -EINVAL;
2292
Lukáš Turek81077e82009-12-21 22:50:47 +01002293 coverage_class = nla_get_u8(
2294 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2295 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2296 }
2297
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002298 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2299 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2300 return -EOPNOTSUPP;
2301
2302 changed |= WIPHY_PARAM_DYN_ACK;
2303 }
2304
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002305 if (changed) {
2306 u8 old_retry_short, old_retry_long;
2307 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002308 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002309
Ying Xue7f2b8562014-01-15 10:23:45 +08002310 if (!rdev->ops->set_wiphy_params)
2311 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002312
2313 old_retry_short = rdev->wiphy.retry_short;
2314 old_retry_long = rdev->wiphy.retry_long;
2315 old_frag_threshold = rdev->wiphy.frag_threshold;
2316 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002317 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002318
2319 if (changed & WIPHY_PARAM_RETRY_SHORT)
2320 rdev->wiphy.retry_short = retry_short;
2321 if (changed & WIPHY_PARAM_RETRY_LONG)
2322 rdev->wiphy.retry_long = retry_long;
2323 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2324 rdev->wiphy.frag_threshold = frag_threshold;
2325 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2326 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002327 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2328 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002329
Hila Gonene35e4d22012-06-27 17:19:42 +03002330 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002331 if (result) {
2332 rdev->wiphy.retry_short = old_retry_short;
2333 rdev->wiphy.retry_long = old_retry_long;
2334 rdev->wiphy.frag_threshold = old_frag_threshold;
2335 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002336 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002337 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002338 }
2339 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002340 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002341}
2342
Johannes Berg71bbc992012-06-15 15:30:18 +02002343static inline u64 wdev_id(struct wireless_dev *wdev)
2344{
2345 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002346 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002347}
Johannes Berg55682962007-09-20 13:09:35 -04002348
Johannes Berg683b6d32012-11-08 21:25:48 +01002349static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002350 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002351{
Johannes Berg601555c2014-11-27 17:26:56 +01002352 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2353 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002354
Johannes Berg683b6d32012-11-08 21:25:48 +01002355 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2356 chandef->chan->center_freq))
2357 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002358 switch (chandef->width) {
2359 case NL80211_CHAN_WIDTH_20_NOHT:
2360 case NL80211_CHAN_WIDTH_20:
2361 case NL80211_CHAN_WIDTH_40:
2362 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2363 cfg80211_get_chandef_type(chandef)))
2364 return -ENOBUFS;
2365 break;
2366 default:
2367 break;
2368 }
2369 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2370 return -ENOBUFS;
2371 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2372 return -ENOBUFS;
2373 if (chandef->center_freq2 &&
2374 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002375 return -ENOBUFS;
2376 return 0;
2377}
2378
Eric W. Biederman15e47302012-09-07 20:12:54 +00002379static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002380 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002381 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002382{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002383 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002384 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002385 void *hdr;
2386
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002387 if (removal)
2388 cmd = NL80211_CMD_DEL_INTERFACE;
2389
2390 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002391 if (!hdr)
2392 return -1;
2393
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002394 if (dev &&
2395 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002396 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002397 goto nla_put_failure;
2398
2399 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2400 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002401 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002402 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002403 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2404 rdev->devlist_generation ^
2405 (cfg80211_rdev_list_generation << 2)))
2406 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002407
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002408 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002409 int ret;
2410 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002411
Johannes Berg683b6d32012-11-08 21:25:48 +01002412 ret = rdev_get_channel(rdev, wdev, &chandef);
2413 if (ret == 0) {
2414 if (nl80211_send_chandef(msg, &chandef))
2415 goto nla_put_failure;
2416 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002417 }
2418
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002419 if (rdev->ops->get_tx_power) {
2420 int dbm, ret;
2421
2422 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2423 if (ret == 0 &&
2424 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2425 DBM_TO_MBM(dbm)))
2426 goto nla_put_failure;
2427 }
2428
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002429 if (wdev->ssid_len) {
2430 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2431 goto nla_put_failure;
2432 }
2433
Johannes Berg053c0952015-01-16 22:09:00 +01002434 genlmsg_end(msg, hdr);
2435 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002436
2437 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002438 genlmsg_cancel(msg, hdr);
2439 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002440}
2441
2442static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2443{
2444 int wp_idx = 0;
2445 int if_idx = 0;
2446 int wp_start = cb->args[0];
2447 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002448 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002449 struct wireless_dev *wdev;
2450
Johannes Berg5fe231e2013-05-08 21:45:15 +02002451 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002452 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2453 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002454 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002455 if (wp_idx < wp_start) {
2456 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002457 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002458 }
Johannes Berg55682962007-09-20 13:09:35 -04002459 if_idx = 0;
2460
Johannes Berg89a54e42012-06-15 14:33:17 +02002461 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002462 if (if_idx < if_start) {
2463 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002464 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002465 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002466 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002467 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002468 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002469 goto out;
2470 }
2471 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002472 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002473
2474 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002475 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002476 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002477 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002478
2479 cb->args[0] = wp_idx;
2480 cb->args[1] = if_idx;
2481
2482 return skb->len;
2483}
2484
2485static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2486{
2487 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002489 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002490
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002491 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002492 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002493 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002494
Eric W. Biederman15e47302012-09-07 20:12:54 +00002495 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002496 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002497 nlmsg_free(msg);
2498 return -ENOBUFS;
2499 }
Johannes Berg55682962007-09-20 13:09:35 -04002500
Johannes Berg134e6372009-07-10 09:51:34 +00002501 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002502}
2503
Michael Wu66f7ac52008-01-31 19:48:22 +01002504static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2505 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2506 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2507 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2508 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2509 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002510 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002511};
2512
2513static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2514{
2515 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2516 int flag;
2517
2518 *mntrflags = 0;
2519
2520 if (!nla)
2521 return -EINVAL;
2522
2523 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2524 nla, mntr_flags_policy))
2525 return -EINVAL;
2526
2527 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2528 if (flags[flag])
2529 *mntrflags |= (1<<flag);
2530
2531 return 0;
2532}
2533
Johannes Berg9bc383d2009-11-19 11:55:19 +01002534static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002535 struct net_device *netdev, u8 use_4addr,
2536 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002537{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002538 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002539 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002540 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002541 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002542 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002543
2544 switch (iftype) {
2545 case NL80211_IFTYPE_AP_VLAN:
2546 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2547 return 0;
2548 break;
2549 case NL80211_IFTYPE_STATION:
2550 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2551 return 0;
2552 break;
2553 default:
2554 break;
2555 }
2556
2557 return -EOPNOTSUPP;
2558}
2559
Johannes Berg55682962007-09-20 13:09:35 -04002560static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2561{
Johannes Berg4c476992010-10-04 21:36:35 +02002562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002563 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002564 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002565 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002566 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002567 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002568 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002569
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002570 memset(&params, 0, sizeof(params));
2571
Johannes Berg04a773a2009-04-19 21:24:32 +02002572 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002573
Johannes Berg723b0382008-09-16 20:22:09 +02002574 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002575 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002576 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002577 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002578 if (ntype > NL80211_IFTYPE_MAX)
2579 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002580 }
2581
Johannes Berg92ffe052008-09-16 20:39:36 +02002582 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002583 struct wireless_dev *wdev = dev->ieee80211_ptr;
2584
Johannes Berg4c476992010-10-04 21:36:35 +02002585 if (ntype != NL80211_IFTYPE_MESH_POINT)
2586 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002587 if (netif_running(dev))
2588 return -EBUSY;
2589
2590 wdev_lock(wdev);
2591 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2592 IEEE80211_MAX_MESH_ID_LEN);
2593 wdev->mesh_id_up_len =
2594 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2595 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2596 wdev->mesh_id_up_len);
2597 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002598 }
2599
Felix Fietkau8b787642009-11-10 18:53:10 +01002600 if (info->attrs[NL80211_ATTR_4ADDR]) {
2601 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2602 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002603 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002604 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002605 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002606 } else {
2607 params.use_4addr = -1;
2608 }
2609
Johannes Berg92ffe052008-09-16 20:39:36 +02002610 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002611 if (ntype != NL80211_IFTYPE_MONITOR)
2612 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002613 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2614 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002615 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002616 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002617
2618 flags = &_flags;
2619 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002620 }
Johannes Berg3b858752009-03-12 09:55:09 +01002621
Luciano Coelho18003292013-08-29 13:26:57 +03002622 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002623 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2624 return -EOPNOTSUPP;
2625
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002626 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002627 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002628 else
2629 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002630
Johannes Berg9bc383d2009-11-19 11:55:19 +01002631 if (!err && params.use_4addr != -1)
2632 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2633
Johannes Berg55682962007-09-20 13:09:35 -04002634 return err;
2635}
2636
2637static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2638{
Johannes Berg4c476992010-10-04 21:36:35 +02002639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002640 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002641 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002642 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002643 int err;
2644 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002645 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002646
Johannes Berg78f22b62014-03-24 17:57:27 +01002647 /* to avoid failing a new interface creation due to pending removal */
2648 cfg80211_destroy_ifaces(rdev);
2649
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002650 memset(&params, 0, sizeof(params));
2651
Johannes Berg55682962007-09-20 13:09:35 -04002652 if (!info->attrs[NL80211_ATTR_IFNAME])
2653 return -EINVAL;
2654
2655 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2656 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2657 if (type > NL80211_IFTYPE_MAX)
2658 return -EINVAL;
2659 }
2660
Johannes Berg79c97e92009-07-07 03:56:12 +02002661 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002662 !(rdev->wiphy.interface_modes & (1 << type)))
2663 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002664
Ben Greeare8f479b2014-10-22 12:23:05 -07002665 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2666 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2667 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002668 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2669 ETH_ALEN);
2670 if (!is_valid_ether_addr(params.macaddr))
2671 return -EADDRNOTAVAIL;
2672 }
2673
Johannes Berg9bc383d2009-11-19 11:55:19 +01002674 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002675 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002676 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002677 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002678 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002679 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002680
Michael Wu66f7ac52008-01-31 19:48:22 +01002681 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2682 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2683 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002684
Luciano Coelho18003292013-08-29 13:26:57 +03002685 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002686 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2687 return -EOPNOTSUPP;
2688
Johannes Berga18c7192015-02-24 10:56:42 +01002689 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2690 if (!msg)
2691 return -ENOMEM;
2692
Hila Gonene35e4d22012-06-27 17:19:42 +03002693 wdev = rdev_add_virtual_intf(rdev,
2694 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002695 NET_NAME_USER, type, err ? NULL : &flags,
2696 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002697 if (WARN_ON(!wdev)) {
2698 nlmsg_free(msg);
2699 return -EPROTO;
2700 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002701 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002702 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002703 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002704
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002705 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002706 wdev->owner_nlportid = info->snd_portid;
2707
Johannes Berg98104fde2012-06-16 00:19:54 +02002708 switch (type) {
2709 case NL80211_IFTYPE_MESH_POINT:
2710 if (!info->attrs[NL80211_ATTR_MESH_ID])
2711 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002712 wdev_lock(wdev);
2713 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2714 IEEE80211_MAX_MESH_ID_LEN);
2715 wdev->mesh_id_up_len =
2716 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2717 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2718 wdev->mesh_id_up_len);
2719 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002720 break;
2721 case NL80211_IFTYPE_P2P_DEVICE:
2722 /*
2723 * P2P Device doesn't have a netdev, so doesn't go
2724 * through the netdev notifier and must be added here
2725 */
2726 mutex_init(&wdev->mtx);
2727 INIT_LIST_HEAD(&wdev->event_list);
2728 spin_lock_init(&wdev->event_lock);
2729 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2730 spin_lock_init(&wdev->mgmt_registrations_lock);
2731
Johannes Berg98104fde2012-06-16 00:19:54 +02002732 wdev->identifier = ++rdev->wdev_id;
2733 list_add_rcu(&wdev->list, &rdev->wdev_list);
2734 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002735 break;
2736 default:
2737 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002738 }
2739
Eric W. Biederman15e47302012-09-07 20:12:54 +00002740 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002741 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002742 nlmsg_free(msg);
2743 return -ENOBUFS;
2744 }
2745
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002746 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2747 if (event) {
2748 if (nl80211_send_iface(event, 0, 0, 0,
2749 rdev, wdev, false) < 0) {
2750 nlmsg_free(event);
2751 goto out;
2752 }
2753
2754 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2755 event, 0, NL80211_MCGRP_CONFIG,
2756 GFP_KERNEL);
2757 }
2758
2759out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002760 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002761}
2762
2763static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2764{
Johannes Berg4c476992010-10-04 21:36:35 +02002765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002766 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002767 struct sk_buff *msg;
2768 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002769
Johannes Berg4c476992010-10-04 21:36:35 +02002770 if (!rdev->ops->del_virtual_intf)
2771 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002772
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002773 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2774 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2775 nlmsg_free(msg);
2776 msg = NULL;
2777 }
2778
Johannes Berg84efbb82012-06-16 00:00:26 +02002779 /*
2780 * If we remove a wireless device without a netdev then clear
2781 * user_ptr[1] so that nl80211_post_doit won't dereference it
2782 * to check if it needs to do dev_put(). Otherwise it crashes
2783 * since the wdev has been freed, unlike with a netdev where
2784 * we need the dev_put() for the netdev to really be freed.
2785 */
2786 if (!wdev->netdev)
2787 info->user_ptr[1] = NULL;
2788
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002789 status = rdev_del_virtual_intf(rdev, wdev);
2790 if (status >= 0 && msg)
2791 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2792 msg, 0, NL80211_MCGRP_CONFIG,
2793 GFP_KERNEL);
2794 else
2795 nlmsg_free(msg);
2796
2797 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002798}
2799
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002800static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2801{
2802 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2803 struct net_device *dev = info->user_ptr[1];
2804 u16 noack_map;
2805
2806 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2807 return -EINVAL;
2808
2809 if (!rdev->ops->set_noack_map)
2810 return -EOPNOTSUPP;
2811
2812 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2813
Hila Gonene35e4d22012-06-27 17:19:42 +03002814 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002815}
2816
Johannes Berg41ade002007-12-19 02:03:29 +01002817struct get_key_cookie {
2818 struct sk_buff *msg;
2819 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002820 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002821};
2822
2823static void get_key_callback(void *c, struct key_params *params)
2824{
Johannes Bergb9454e82009-07-08 13:29:08 +02002825 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002826 struct get_key_cookie *cookie = c;
2827
David S. Miller9360ffd2012-03-29 04:41:26 -04002828 if ((params->key &&
2829 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2830 params->key_len, params->key)) ||
2831 (params->seq &&
2832 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2833 params->seq_len, params->seq)) ||
2834 (params->cipher &&
2835 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2836 params->cipher)))
2837 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002838
Johannes Bergb9454e82009-07-08 13:29:08 +02002839 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2840 if (!key)
2841 goto nla_put_failure;
2842
David S. Miller9360ffd2012-03-29 04:41:26 -04002843 if ((params->key &&
2844 nla_put(cookie->msg, NL80211_KEY_DATA,
2845 params->key_len, params->key)) ||
2846 (params->seq &&
2847 nla_put(cookie->msg, NL80211_KEY_SEQ,
2848 params->seq_len, params->seq)) ||
2849 (params->cipher &&
2850 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2851 params->cipher)))
2852 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002853
David S. Miller9360ffd2012-03-29 04:41:26 -04002854 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2855 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002856
2857 nla_nest_end(cookie->msg, key);
2858
Johannes Berg41ade002007-12-19 02:03:29 +01002859 return;
2860 nla_put_failure:
2861 cookie->error = 1;
2862}
2863
2864static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2865{
Johannes Berg4c476992010-10-04 21:36:35 +02002866 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002867 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002868 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002869 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002870 const u8 *mac_addr = NULL;
2871 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002872 struct get_key_cookie cookie = {
2873 .error = 0,
2874 };
2875 void *hdr;
2876 struct sk_buff *msg;
2877
2878 if (info->attrs[NL80211_ATTR_KEY_IDX])
2879 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2880
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002881 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002882 return -EINVAL;
2883
2884 if (info->attrs[NL80211_ATTR_MAC])
2885 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2886
Johannes Berge31b8212010-10-05 19:39:30 +02002887 pairwise = !!mac_addr;
2888 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2889 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2890 if (kt >= NUM_NL80211_KEYTYPES)
2891 return -EINVAL;
2892 if (kt != NL80211_KEYTYPE_GROUP &&
2893 kt != NL80211_KEYTYPE_PAIRWISE)
2894 return -EINVAL;
2895 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2896 }
2897
Johannes Berg4c476992010-10-04 21:36:35 +02002898 if (!rdev->ops->get_key)
2899 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002900
Johannes Berg0fa7b392015-01-23 11:10:12 +01002901 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2902 return -ENOENT;
2903
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002904 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002905 if (!msg)
2906 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002907
Eric W. Biederman15e47302012-09-07 20:12:54 +00002908 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002909 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002910 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002911 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002912
2913 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002914 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002915
David S. Miller9360ffd2012-03-29 04:41:26 -04002916 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2917 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2918 goto nla_put_failure;
2919 if (mac_addr &&
2920 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2921 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002922
Hila Gonene35e4d22012-06-27 17:19:42 +03002923 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2924 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002925
2926 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002927 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002928
2929 if (cookie.error)
2930 goto nla_put_failure;
2931
2932 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002933 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002934
2935 nla_put_failure:
2936 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002937 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002938 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002939 return err;
2940}
2941
2942static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2943{
Johannes Berg4c476992010-10-04 21:36:35 +02002944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002945 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002946 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002947 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002948
Johannes Bergb9454e82009-07-08 13:29:08 +02002949 err = nl80211_parse_key(info, &key);
2950 if (err)
2951 return err;
2952
2953 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002954 return -EINVAL;
2955
Johannes Bergb9454e82009-07-08 13:29:08 +02002956 /* only support setting default key */
2957 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002958 return -EINVAL;
2959
Johannes Bergfffd0932009-07-08 14:22:54 +02002960 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002961
2962 if (key.def) {
2963 if (!rdev->ops->set_default_key) {
2964 err = -EOPNOTSUPP;
2965 goto out;
2966 }
2967
2968 err = nl80211_key_allowed(dev->ieee80211_ptr);
2969 if (err)
2970 goto out;
2971
Hila Gonene35e4d22012-06-27 17:19:42 +03002972 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002973 key.def_uni, key.def_multi);
2974
2975 if (err)
2976 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002977
Johannes Berg3d23e342009-09-29 23:27:28 +02002978#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002979 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002980#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002981 } else {
2982 if (key.def_uni || !key.def_multi) {
2983 err = -EINVAL;
2984 goto out;
2985 }
2986
2987 if (!rdev->ops->set_default_mgmt_key) {
2988 err = -EOPNOTSUPP;
2989 goto out;
2990 }
2991
2992 err = nl80211_key_allowed(dev->ieee80211_ptr);
2993 if (err)
2994 goto out;
2995
Hila Gonene35e4d22012-06-27 17:19:42 +03002996 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002997 if (err)
2998 goto out;
2999
3000#ifdef CONFIG_CFG80211_WEXT
3001 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
3002#endif
3003 }
3004
3005 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02003006 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003007
Johannes Berg41ade002007-12-19 02:03:29 +01003008 return err;
3009}
3010
3011static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3012{
Johannes Berg4c476992010-10-04 21:36:35 +02003013 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003014 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003015 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003016 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003017 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003018
Johannes Bergb9454e82009-07-08 13:29:08 +02003019 err = nl80211_parse_key(info, &key);
3020 if (err)
3021 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003022
Johannes Bergb9454e82009-07-08 13:29:08 +02003023 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003024 return -EINVAL;
3025
Johannes Berg41ade002007-12-19 02:03:29 +01003026 if (info->attrs[NL80211_ATTR_MAC])
3027 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3028
Johannes Berge31b8212010-10-05 19:39:30 +02003029 if (key.type == -1) {
3030 if (mac_addr)
3031 key.type = NL80211_KEYTYPE_PAIRWISE;
3032 else
3033 key.type = NL80211_KEYTYPE_GROUP;
3034 }
3035
3036 /* for now */
3037 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3038 key.type != NL80211_KEYTYPE_GROUP)
3039 return -EINVAL;
3040
Johannes Berg4c476992010-10-04 21:36:35 +02003041 if (!rdev->ops->add_key)
3042 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003043
Johannes Berge31b8212010-10-05 19:39:30 +02003044 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3045 key.type == NL80211_KEYTYPE_PAIRWISE,
3046 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003047 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003048
3049 wdev_lock(dev->ieee80211_ptr);
3050 err = nl80211_key_allowed(dev->ieee80211_ptr);
3051 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003052 err = rdev_add_key(rdev, dev, key.idx,
3053 key.type == NL80211_KEYTYPE_PAIRWISE,
3054 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003055 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003056
Johannes Berg41ade002007-12-19 02:03:29 +01003057 return err;
3058}
3059
3060static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3061{
Johannes Berg4c476992010-10-04 21:36:35 +02003062 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003063 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003064 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003065 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003066 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003067
Johannes Bergb9454e82009-07-08 13:29:08 +02003068 err = nl80211_parse_key(info, &key);
3069 if (err)
3070 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003071
3072 if (info->attrs[NL80211_ATTR_MAC])
3073 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3074
Johannes Berge31b8212010-10-05 19:39:30 +02003075 if (key.type == -1) {
3076 if (mac_addr)
3077 key.type = NL80211_KEYTYPE_PAIRWISE;
3078 else
3079 key.type = NL80211_KEYTYPE_GROUP;
3080 }
3081
3082 /* for now */
3083 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3084 key.type != NL80211_KEYTYPE_GROUP)
3085 return -EINVAL;
3086
Johannes Berg4c476992010-10-04 21:36:35 +02003087 if (!rdev->ops->del_key)
3088 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003089
Johannes Bergfffd0932009-07-08 14:22:54 +02003090 wdev_lock(dev->ieee80211_ptr);
3091 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003092
Johannes Berg0fa7b392015-01-23 11:10:12 +01003093 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003094 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3095 err = -ENOENT;
3096
Johannes Bergfffd0932009-07-08 14:22:54 +02003097 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003098 err = rdev_del_key(rdev, dev, key.idx,
3099 key.type == NL80211_KEYTYPE_PAIRWISE,
3100 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003101
Johannes Berg3d23e342009-09-29 23:27:28 +02003102#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003103 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003104 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003105 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003106 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003107 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3108 }
3109#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003110 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003111
Johannes Berg41ade002007-12-19 02:03:29 +01003112 return err;
3113}
3114
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303115/* This function returns an error or the number of nested attributes */
3116static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3117{
3118 struct nlattr *attr;
3119 int n_entries = 0, tmp;
3120
3121 nla_for_each_nested(attr, nl_attr, tmp) {
3122 if (nla_len(attr) != ETH_ALEN)
3123 return -EINVAL;
3124
3125 n_entries++;
3126 }
3127
3128 return n_entries;
3129}
3130
3131/*
3132 * This function parses ACL information and allocates memory for ACL data.
3133 * On successful return, the calling function is responsible to free the
3134 * ACL buffer returned by this function.
3135 */
3136static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3137 struct genl_info *info)
3138{
3139 enum nl80211_acl_policy acl_policy;
3140 struct nlattr *attr;
3141 struct cfg80211_acl_data *acl;
3142 int i = 0, n_entries, tmp;
3143
3144 if (!wiphy->max_acl_mac_addrs)
3145 return ERR_PTR(-EOPNOTSUPP);
3146
3147 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3148 return ERR_PTR(-EINVAL);
3149
3150 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3151 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3152 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3153 return ERR_PTR(-EINVAL);
3154
3155 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3156 return ERR_PTR(-EINVAL);
3157
3158 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3159 if (n_entries < 0)
3160 return ERR_PTR(n_entries);
3161
3162 if (n_entries > wiphy->max_acl_mac_addrs)
3163 return ERR_PTR(-ENOTSUPP);
3164
3165 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3166 GFP_KERNEL);
3167 if (!acl)
3168 return ERR_PTR(-ENOMEM);
3169
3170 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3171 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3172 i++;
3173 }
3174
3175 acl->n_acl_entries = n_entries;
3176 acl->acl_policy = acl_policy;
3177
3178 return acl;
3179}
3180
3181static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3182{
3183 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3184 struct net_device *dev = info->user_ptr[1];
3185 struct cfg80211_acl_data *acl;
3186 int err;
3187
3188 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3189 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3190 return -EOPNOTSUPP;
3191
3192 if (!dev->ieee80211_ptr->beacon_interval)
3193 return -EINVAL;
3194
3195 acl = parse_acl_data(&rdev->wiphy, info);
3196 if (IS_ERR(acl))
3197 return PTR_ERR(acl);
3198
3199 err = rdev_set_mac_acl(rdev, dev, acl);
3200
3201 kfree(acl);
3202
3203 return err;
3204}
3205
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003206static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003207 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003208{
Johannes Berg88600202012-02-13 15:17:18 +01003209 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003210
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003211 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3212 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3213 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3214 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003215 return -EINVAL;
3216
Johannes Berg88600202012-02-13 15:17:18 +01003217 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003218
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003219 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3220 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3221 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003222 if (!bcn->head_len)
3223 return -EINVAL;
3224 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003225 }
3226
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003227 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3228 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3229 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003230 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003231 }
3232
Johannes Berg4c476992010-10-04 21:36:35 +02003233 if (!haveinfo)
3234 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003235
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003236 if (attrs[NL80211_ATTR_IE]) {
3237 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3238 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003239 }
3240
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003241 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003242 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003243 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003244 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003245 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003246 }
3247
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003248 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003249 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003250 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003251 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003252 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003253 }
3254
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003255 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3256 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3257 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003258 }
3259
Johannes Berg88600202012-02-13 15:17:18 +01003260 return 0;
3261}
3262
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003263static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3264 struct cfg80211_ap_settings *params)
3265{
3266 struct wireless_dev *wdev;
3267 bool ret = false;
3268
Johannes Berg89a54e42012-06-15 14:33:17 +02003269 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003270 if (wdev->iftype != NL80211_IFTYPE_AP &&
3271 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3272 continue;
3273
Johannes Berg683b6d32012-11-08 21:25:48 +01003274 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003275 continue;
3276
Johannes Berg683b6d32012-11-08 21:25:48 +01003277 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003278 ret = true;
3279 break;
3280 }
3281
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003282 return ret;
3283}
3284
Jouni Malinene39e5b52012-09-30 19:29:39 +03003285static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3286 enum nl80211_auth_type auth_type,
3287 enum nl80211_commands cmd)
3288{
3289 if (auth_type > NL80211_AUTHTYPE_MAX)
3290 return false;
3291
3292 switch (cmd) {
3293 case NL80211_CMD_AUTHENTICATE:
3294 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3295 auth_type == NL80211_AUTHTYPE_SAE)
3296 return false;
3297 return true;
3298 case NL80211_CMD_CONNECT:
3299 case NL80211_CMD_START_AP:
3300 /* SAE not supported yet */
3301 if (auth_type == NL80211_AUTHTYPE_SAE)
3302 return false;
3303 return true;
3304 default:
3305 return false;
3306 }
3307}
3308
Johannes Berg88600202012-02-13 15:17:18 +01003309static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3310{
3311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3312 struct net_device *dev = info->user_ptr[1];
3313 struct wireless_dev *wdev = dev->ieee80211_ptr;
3314 struct cfg80211_ap_settings params;
3315 int err;
3316
3317 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3318 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3319 return -EOPNOTSUPP;
3320
3321 if (!rdev->ops->start_ap)
3322 return -EOPNOTSUPP;
3323
3324 if (wdev->beacon_interval)
3325 return -EALREADY;
3326
3327 memset(&params, 0, sizeof(params));
3328
3329 /* these are required for START_AP */
3330 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3331 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3332 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3333 return -EINVAL;
3334
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003335 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003336 if (err)
3337 return err;
3338
3339 params.beacon_interval =
3340 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3341 params.dtim_period =
3342 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3343
3344 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3345 if (err)
3346 return err;
3347
3348 /*
3349 * In theory, some of these attributes should be required here
3350 * but since they were not used when the command was originally
3351 * added, keep them optional for old user space programs to let
3352 * them continue to work with drivers that do not need the
3353 * additional information -- drivers must check!
3354 */
3355 if (info->attrs[NL80211_ATTR_SSID]) {
3356 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3357 params.ssid_len =
3358 nla_len(info->attrs[NL80211_ATTR_SSID]);
3359 if (params.ssid_len == 0 ||
3360 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3361 return -EINVAL;
3362 }
3363
3364 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3365 params.hidden_ssid = nla_get_u32(
3366 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3367 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3368 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3369 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3370 return -EINVAL;
3371 }
3372
3373 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3374
3375 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3376 params.auth_type = nla_get_u32(
3377 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003378 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3379 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003380 return -EINVAL;
3381 } else
3382 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3383
3384 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3385 NL80211_MAX_NR_CIPHER_SUITES);
3386 if (err)
3387 return err;
3388
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303389 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3390 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3391 return -EOPNOTSUPP;
3392 params.inactivity_timeout = nla_get_u16(
3393 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3394 }
3395
Johannes Berg53cabad2012-11-14 15:17:28 +01003396 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3397 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3398 return -EINVAL;
3399 params.p2p_ctwindow =
3400 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3401 if (params.p2p_ctwindow > 127)
3402 return -EINVAL;
3403 if (params.p2p_ctwindow != 0 &&
3404 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3405 return -EINVAL;
3406 }
3407
3408 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3409 u8 tmp;
3410
3411 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3412 return -EINVAL;
3413 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3414 if (tmp > 1)
3415 return -EINVAL;
3416 params.p2p_opp_ps = tmp;
3417 if (params.p2p_opp_ps != 0 &&
3418 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3419 return -EINVAL;
3420 }
3421
Johannes Bergaa430da2012-05-16 23:50:18 +02003422 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003423 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3424 if (err)
3425 return err;
3426 } else if (wdev->preset_chandef.chan) {
3427 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003428 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003429 return -EINVAL;
3430
Arik Nemtsov923b3522015-07-08 15:41:44 +03003431 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3432 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003433 return -EINVAL;
3434
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303435 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3436 params.acl = parse_acl_data(&rdev->wiphy, info);
3437 if (IS_ERR(params.acl))
3438 return PTR_ERR(params.acl);
3439 }
3440
Eliad Peller18998c32014-09-10 14:07:34 +03003441 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3442 params.smps_mode =
3443 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3444 switch (params.smps_mode) {
3445 case NL80211_SMPS_OFF:
3446 break;
3447 case NL80211_SMPS_STATIC:
3448 if (!(rdev->wiphy.features &
3449 NL80211_FEATURE_STATIC_SMPS))
3450 return -EINVAL;
3451 break;
3452 case NL80211_SMPS_DYNAMIC:
3453 if (!(rdev->wiphy.features &
3454 NL80211_FEATURE_DYNAMIC_SMPS))
3455 return -EINVAL;
3456 break;
3457 default:
3458 return -EINVAL;
3459 }
3460 } else {
3461 params.smps_mode = NL80211_SMPS_OFF;
3462 }
3463
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003464 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003465 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003466 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003467 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003468 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003469 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003470 wdev->ssid_len = params.ssid_len;
3471 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003472 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003473 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303474
3475 kfree(params.acl);
3476
Johannes Berg56d18932011-05-09 18:41:15 +02003477 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003478}
3479
Johannes Berg88600202012-02-13 15:17:18 +01003480static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3481{
3482 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3483 struct net_device *dev = info->user_ptr[1];
3484 struct wireless_dev *wdev = dev->ieee80211_ptr;
3485 struct cfg80211_beacon_data params;
3486 int err;
3487
3488 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3489 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3490 return -EOPNOTSUPP;
3491
3492 if (!rdev->ops->change_beacon)
3493 return -EOPNOTSUPP;
3494
3495 if (!wdev->beacon_interval)
3496 return -EINVAL;
3497
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003498 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003499 if (err)
3500 return err;
3501
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003502 wdev_lock(wdev);
3503 err = rdev_change_beacon(rdev, dev, &params);
3504 wdev_unlock(wdev);
3505
3506 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003507}
3508
3509static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003510{
Johannes Berg4c476992010-10-04 21:36:35 +02003511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3512 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003513
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003514 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003515}
3516
Johannes Berg5727ef12007-12-19 02:03:34 +01003517static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3518 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3519 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3520 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003521 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003522 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003523 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003524};
3525
Johannes Bergeccb8e82009-05-11 21:57:56 +03003526static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003527 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003528 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003529{
3530 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003531 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003532 int flag;
3533
Johannes Bergeccb8e82009-05-11 21:57:56 +03003534 /*
3535 * Try parsing the new attribute first so userspace
3536 * can specify both for older kernels.
3537 */
3538 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3539 if (nla) {
3540 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003541
Johannes Bergeccb8e82009-05-11 21:57:56 +03003542 sta_flags = nla_data(nla);
3543 params->sta_flags_mask = sta_flags->mask;
3544 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003545 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003546 if ((params->sta_flags_mask |
3547 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3548 return -EINVAL;
3549 return 0;
3550 }
3551
3552 /* if present, parse the old attribute */
3553
3554 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003555 if (!nla)
3556 return 0;
3557
3558 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3559 nla, sta_flags_policy))
3560 return -EINVAL;
3561
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003562 /*
3563 * Only allow certain flags for interface types so that
3564 * other attributes are silently ignored. Remember that
3565 * this is backward compatibility code with old userspace
3566 * and shouldn't be hit in other cases anyway.
3567 */
3568 switch (iftype) {
3569 case NL80211_IFTYPE_AP:
3570 case NL80211_IFTYPE_AP_VLAN:
3571 case NL80211_IFTYPE_P2P_GO:
3572 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3573 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3574 BIT(NL80211_STA_FLAG_WME) |
3575 BIT(NL80211_STA_FLAG_MFP);
3576 break;
3577 case NL80211_IFTYPE_P2P_CLIENT:
3578 case NL80211_IFTYPE_STATION:
3579 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3580 BIT(NL80211_STA_FLAG_TDLS_PEER);
3581 break;
3582 case NL80211_IFTYPE_MESH_POINT:
3583 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3584 BIT(NL80211_STA_FLAG_MFP) |
3585 BIT(NL80211_STA_FLAG_AUTHORIZED);
3586 default:
3587 return -EINVAL;
3588 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003589
Johannes Berg3383b5a2012-05-10 20:14:43 +02003590 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3591 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003592 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003593
Johannes Berg3383b5a2012-05-10 20:14:43 +02003594 /* no longer support new API additions in old API */
3595 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3596 return -EINVAL;
3597 }
3598 }
3599
Johannes Berg5727ef12007-12-19 02:03:34 +01003600 return 0;
3601}
3602
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003603static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3604 int attr)
3605{
3606 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003607 u32 bitrate;
3608 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003609 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003610
3611 rate = nla_nest_start(msg, attr);
3612 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003613 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003614
3615 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3616 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003617 /* report 16-bit bitrate only if we can */
3618 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003619 if (bitrate > 0 &&
3620 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3621 return false;
3622 if (bitrate_compat > 0 &&
3623 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3624 return false;
3625
Johannes Bergb51f3be2015-01-15 16:14:02 +01003626 switch (info->bw) {
3627 case RATE_INFO_BW_5:
3628 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3629 break;
3630 case RATE_INFO_BW_10:
3631 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3632 break;
3633 default:
3634 WARN_ON(1);
3635 /* fall through */
3636 case RATE_INFO_BW_20:
3637 rate_flg = 0;
3638 break;
3639 case RATE_INFO_BW_40:
3640 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3641 break;
3642 case RATE_INFO_BW_80:
3643 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3644 break;
3645 case RATE_INFO_BW_160:
3646 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3647 break;
3648 }
3649
3650 if (rate_flg && nla_put_flag(msg, rate_flg))
3651 return false;
3652
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003653 if (info->flags & RATE_INFO_FLAGS_MCS) {
3654 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3655 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003656 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3657 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3658 return false;
3659 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3660 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3661 return false;
3662 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3663 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003664 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3665 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3666 return false;
3667 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003668
3669 nla_nest_end(msg, rate);
3670 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003671}
3672
Felix Fietkau119363c2013-04-22 16:29:30 +02003673static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3674 int id)
3675{
3676 void *attr;
3677 int i = 0;
3678
3679 if (!mask)
3680 return true;
3681
3682 attr = nla_nest_start(msg, id);
3683 if (!attr)
3684 return false;
3685
3686 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3687 if (!(mask & BIT(i)))
3688 continue;
3689
3690 if (nla_put_u8(msg, i, signal[i]))
3691 return false;
3692 }
3693
3694 nla_nest_end(msg, attr);
3695
3696 return true;
3697}
3698
Johannes Bergcf5ead82014-11-14 17:14:00 +01003699static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3700 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003701 struct cfg80211_registered_device *rdev,
3702 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003703 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003704{
3705 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003706 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003707
Johannes Bergcf5ead82014-11-14 17:14:00 +01003708 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003709 if (!hdr)
3710 return -1;
3711
David S. Miller9360ffd2012-03-29 04:41:26 -04003712 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3713 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3714 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3715 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003716
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003717 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3718 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003719 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003720
3721#define PUT_SINFO(attr, memb, type) do { \
3722 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3723 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3724 sinfo->memb)) \
3725 goto nla_put_failure; \
3726 } while (0)
3727
3728 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3729 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3730
3731 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3732 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003733 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003734 (u32)sinfo->rx_bytes))
3735 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003736
3737 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3738 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003739 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3740 (u32)sinfo->tx_bytes))
3741 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003742
3743 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3744 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3745 PUT_SINFO(LLID, llid, u16);
3746 PUT_SINFO(PLID, plid, u16);
3747 PUT_SINFO(PLINK_STATE, plink_state, u8);
3748
John W. Linville66266b32012-03-15 13:25:41 -04003749 switch (rdev->wiphy.signal_type) {
3750 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003751 PUT_SINFO(SIGNAL, signal, u8);
3752 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003753 break;
3754 default:
3755 break;
3756 }
Johannes Berg319090b2014-11-17 14:08:11 +01003757 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003758 if (!nl80211_put_signal(msg, sinfo->chains,
3759 sinfo->chain_signal,
3760 NL80211_STA_INFO_CHAIN_SIGNAL))
3761 goto nla_put_failure;
3762 }
Johannes Berg319090b2014-11-17 14:08:11 +01003763 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003764 if (!nl80211_put_signal(msg, sinfo->chains,
3765 sinfo->chain_signal_avg,
3766 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3767 goto nla_put_failure;
3768 }
Johannes Berg319090b2014-11-17 14:08:11 +01003769 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003770 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3771 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003772 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003773 }
Johannes Berg319090b2014-11-17 14:08:11 +01003774 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003775 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3776 NL80211_STA_INFO_RX_BITRATE))
3777 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003778 }
Johannes Berg319090b2014-11-17 14:08:11 +01003779
3780 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3781 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3782 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3783 PUT_SINFO(TX_FAILED, tx_failed, u32);
3784 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3785 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3786 PUT_SINFO(LOCAL_PM, local_pm, u32);
3787 PUT_SINFO(PEER_PM, peer_pm, u32);
3788 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3789
3790 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003791 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3792 if (!bss_param)
3793 goto nla_put_failure;
3794
David S. Miller9360ffd2012-03-29 04:41:26 -04003795 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3796 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3797 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3798 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3799 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3800 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3801 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3802 sinfo->bss_param.dtim_period) ||
3803 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3804 sinfo->bss_param.beacon_interval))
3805 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003806
3807 nla_nest_end(msg, bss_param);
3808 }
Johannes Berg319090b2014-11-17 14:08:11 +01003809 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003810 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3811 sizeof(struct nl80211_sta_flag_update),
3812 &sinfo->sta_flags))
3813 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003814
3815 PUT_SINFO(T_OFFSET, t_offset, u64);
3816 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003817 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3818 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003819
3820#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003821
3822 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3823 struct nlattr *tidsattr;
3824 int tid;
3825
3826 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3827 if (!tidsattr)
3828 goto nla_put_failure;
3829
3830 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3831 struct cfg80211_tid_stats *tidstats;
3832 struct nlattr *tidattr;
3833
3834 tidstats = &sinfo->pertid[tid];
3835
3836 if (!tidstats->filled)
3837 continue;
3838
3839 tidattr = nla_nest_start(msg, tid + 1);
3840 if (!tidattr)
3841 goto nla_put_failure;
3842
3843#define PUT_TIDVAL(attr, memb, type) do { \
3844 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3845 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3846 tidstats->memb)) \
3847 goto nla_put_failure; \
3848 } while (0)
3849
3850 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3851 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3852 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3853 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3854
3855#undef PUT_TIDVAL
3856 nla_nest_end(msg, tidattr);
3857 }
3858
3859 nla_nest_end(msg, tidsattr);
3860 }
3861
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003862 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003863
Johannes Berg319090b2014-11-17 14:08:11 +01003864 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003865 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3866 sinfo->assoc_req_ies))
3867 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003868
Johannes Berg053c0952015-01-16 22:09:00 +01003869 genlmsg_end(msg, hdr);
3870 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003871
3872 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003873 genlmsg_cancel(msg, hdr);
3874 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003875}
3876
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003877static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003878 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003879{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003880 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003881 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003882 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003883 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003884 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003885 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003886
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003887 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003888 if (err)
3889 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003890
Johannes Berg97990a02013-04-19 01:02:55 +02003891 if (!wdev->netdev) {
3892 err = -EINVAL;
3893 goto out_err;
3894 }
3895
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003896 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003897 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003898 goto out_err;
3899 }
3900
Johannes Bergbba95fe2008-07-29 13:22:51 +02003901 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003902 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003903 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003904 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003905 if (err == -ENOENT)
3906 break;
3907 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003908 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003909
Johannes Bergcf5ead82014-11-14 17:14:00 +01003910 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003911 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003912 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003913 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003914 &sinfo) < 0)
3915 goto out;
3916
3917 sta_idx++;
3918 }
3919
3920
3921 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003922 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003923 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003924 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003925 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003926
3927 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003928}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003929
Johannes Berg5727ef12007-12-19 02:03:34 +01003930static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3931{
Johannes Berg4c476992010-10-04 21:36:35 +02003932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3933 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003934 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003935 struct sk_buff *msg;
3936 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003937 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003938
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003939 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003940
3941 if (!info->attrs[NL80211_ATTR_MAC])
3942 return -EINVAL;
3943
3944 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3945
Johannes Berg4c476992010-10-04 21:36:35 +02003946 if (!rdev->ops->get_station)
3947 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003948
Hila Gonene35e4d22012-06-27 17:19:42 +03003949 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003950 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003951 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003952
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003953 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003954 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003955 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003956
Johannes Bergcf5ead82014-11-14 17:14:00 +01003957 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3958 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003959 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003960 nlmsg_free(msg);
3961 return -ENOBUFS;
3962 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003963
Johannes Berg4c476992010-10-04 21:36:35 +02003964 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003965}
3966
Johannes Berg77ee7c82013-02-15 00:48:33 +01003967int cfg80211_check_station_change(struct wiphy *wiphy,
3968 struct station_parameters *params,
3969 enum cfg80211_station_type statype)
3970{
3971 if (params->listen_interval != -1)
3972 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003973 if (params->aid &&
3974 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003975 return -EINVAL;
3976
3977 /* When you run into this, adjust the code below for the new flag */
3978 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3979
3980 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003981 case CFG80211_STA_MESH_PEER_KERNEL:
3982 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003983 /*
3984 * No ignoring the TDLS flag here -- the userspace mesh
3985 * code doesn't have the bug of including TDLS in the
3986 * mask everywhere.
3987 */
3988 if (params->sta_flags_mask &
3989 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3990 BIT(NL80211_STA_FLAG_MFP) |
3991 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3992 return -EINVAL;
3993 break;
3994 case CFG80211_STA_TDLS_PEER_SETUP:
3995 case CFG80211_STA_TDLS_PEER_ACTIVE:
3996 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3997 return -EINVAL;
3998 /* ignore since it can't change */
3999 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4000 break;
4001 default:
4002 /* disallow mesh-specific things */
4003 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4004 return -EINVAL;
4005 if (params->local_pm)
4006 return -EINVAL;
4007 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4008 return -EINVAL;
4009 }
4010
4011 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4012 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4013 /* TDLS can't be set, ... */
4014 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4015 return -EINVAL;
4016 /*
4017 * ... but don't bother the driver with it. This works around
4018 * a hostapd/wpa_supplicant issue -- it always includes the
4019 * TLDS_PEER flag in the mask even for AP mode.
4020 */
4021 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4022 }
4023
Ayala Beker47edb112015-09-21 15:49:53 +03004024 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4025 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004026 /* reject other things that can't change */
4027 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4028 return -EINVAL;
4029 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4030 return -EINVAL;
4031 if (params->supported_rates)
4032 return -EINVAL;
4033 if (params->ext_capab || params->ht_capa || params->vht_capa)
4034 return -EINVAL;
4035 }
4036
Ayala Beker47edb112015-09-21 15:49:53 +03004037 if (statype != CFG80211_STA_AP_CLIENT &&
4038 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004039 if (params->vlan)
4040 return -EINVAL;
4041 }
4042
4043 switch (statype) {
4044 case CFG80211_STA_AP_MLME_CLIENT:
4045 /* Use this only for authorizing/unauthorizing a station */
4046 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4047 return -EOPNOTSUPP;
4048 break;
4049 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004050 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004051 /* accept only the listed bits */
4052 if (params->sta_flags_mask &
4053 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4054 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4055 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4056 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4057 BIT(NL80211_STA_FLAG_WME) |
4058 BIT(NL80211_STA_FLAG_MFP)))
4059 return -EINVAL;
4060
4061 /* but authenticated/associated only if driver handles it */
4062 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4063 params->sta_flags_mask &
4064 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4065 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4066 return -EINVAL;
4067 break;
4068 case CFG80211_STA_IBSS:
4069 case CFG80211_STA_AP_STA:
4070 /* reject any changes other than AUTHORIZED */
4071 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4072 return -EINVAL;
4073 break;
4074 case CFG80211_STA_TDLS_PEER_SETUP:
4075 /* reject any changes other than AUTHORIZED or WME */
4076 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4077 BIT(NL80211_STA_FLAG_WME)))
4078 return -EINVAL;
4079 /* force (at least) rates when authorizing */
4080 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4081 !params->supported_rates)
4082 return -EINVAL;
4083 break;
4084 case CFG80211_STA_TDLS_PEER_ACTIVE:
4085 /* reject any changes */
4086 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004087 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004088 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4089 return -EINVAL;
4090 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004091 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004092 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4093 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004094 return -EINVAL;
4095 break;
4096 }
4097
4098 return 0;
4099}
4100EXPORT_SYMBOL(cfg80211_check_station_change);
4101
Johannes Berg5727ef12007-12-19 02:03:34 +01004102/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004103 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004104 */
Johannes Berg80b99892011-11-18 16:23:01 +01004105static struct net_device *get_vlan(struct genl_info *info,
4106 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004107{
Johannes Berg463d0182009-07-14 00:33:35 +02004108 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004109 struct net_device *v;
4110 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004111
Johannes Berg80b99892011-11-18 16:23:01 +01004112 if (!vlanattr)
4113 return NULL;
4114
4115 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4116 if (!v)
4117 return ERR_PTR(-ENODEV);
4118
4119 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4120 ret = -EINVAL;
4121 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004122 }
Johannes Berg80b99892011-11-18 16:23:01 +01004123
Johannes Berg77ee7c82013-02-15 00:48:33 +01004124 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4125 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4126 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4127 ret = -EINVAL;
4128 goto error;
4129 }
4130
Johannes Berg80b99892011-11-18 16:23:01 +01004131 if (!netif_running(v)) {
4132 ret = -ENETDOWN;
4133 goto error;
4134 }
4135
4136 return v;
4137 error:
4138 dev_put(v);
4139 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004140}
4141
Johannes Berg94e860f2014-01-20 23:58:15 +01004142static const struct nla_policy
4143nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004144 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4145 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4146};
4147
Johannes Bergff276692013-02-15 00:09:01 +01004148static int nl80211_parse_sta_wme(struct genl_info *info,
4149 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004150{
Jouni Malinendf881292013-02-14 21:10:54 +02004151 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4152 struct nlattr *nla;
4153 int err;
4154
Jouni Malinendf881292013-02-14 21:10:54 +02004155 /* parse WME attributes if present */
4156 if (!info->attrs[NL80211_ATTR_STA_WME])
4157 return 0;
4158
4159 nla = info->attrs[NL80211_ATTR_STA_WME];
4160 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4161 nl80211_sta_wme_policy);
4162 if (err)
4163 return err;
4164
4165 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4166 params->uapsd_queues = nla_get_u8(
4167 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4168 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4169 return -EINVAL;
4170
4171 if (tb[NL80211_STA_WME_MAX_SP])
4172 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4173
4174 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4175 return -EINVAL;
4176
4177 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4178
4179 return 0;
4180}
4181
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304182static int nl80211_parse_sta_channel_info(struct genl_info *info,
4183 struct station_parameters *params)
4184{
4185 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4186 params->supported_channels =
4187 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4188 params->supported_channels_len =
4189 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4190 /*
4191 * Need to include at least one (first channel, number of
4192 * channels) tuple for each subband, and must have proper
4193 * tuples for the rest of the data as well.
4194 */
4195 if (params->supported_channels_len < 2)
4196 return -EINVAL;
4197 if (params->supported_channels_len % 2)
4198 return -EINVAL;
4199 }
4200
4201 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4202 params->supported_oper_classes =
4203 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4204 params->supported_oper_classes_len =
4205 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4206 /*
4207 * The value of the Length field of the Supported Operating
4208 * Classes element is between 2 and 253.
4209 */
4210 if (params->supported_oper_classes_len < 2 ||
4211 params->supported_oper_classes_len > 253)
4212 return -EINVAL;
4213 }
4214 return 0;
4215}
4216
Johannes Bergff276692013-02-15 00:09:01 +01004217static int nl80211_set_station_tdls(struct genl_info *info,
4218 struct station_parameters *params)
4219{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304220 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004221 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004222 if (info->attrs[NL80211_ATTR_PEER_AID])
4223 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004224 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4225 params->ht_capa =
4226 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4227 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4228 params->vht_capa =
4229 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4230
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304231 err = nl80211_parse_sta_channel_info(info, params);
4232 if (err)
4233 return err;
4234
Johannes Bergff276692013-02-15 00:09:01 +01004235 return nl80211_parse_sta_wme(info, params);
4236}
4237
Johannes Berg5727ef12007-12-19 02:03:34 +01004238static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4239{
Johannes Berg4c476992010-10-04 21:36:35 +02004240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004241 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004242 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004243 u8 *mac_addr;
4244 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004245
4246 memset(&params, 0, sizeof(params));
4247
4248 params.listen_interval = -1;
4249
Johannes Berg77ee7c82013-02-15 00:48:33 +01004250 if (!rdev->ops->change_station)
4251 return -EOPNOTSUPP;
4252
Johannes Berg5727ef12007-12-19 02:03:34 +01004253 if (info->attrs[NL80211_ATTR_STA_AID])
4254 return -EINVAL;
4255
4256 if (!info->attrs[NL80211_ATTR_MAC])
4257 return -EINVAL;
4258
4259 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4260
4261 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4262 params.supported_rates =
4263 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4264 params.supported_rates_len =
4265 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4266 }
4267
Jouni Malinen9d62a982013-02-14 21:10:13 +02004268 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4269 params.capability =
4270 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4271 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4272 }
4273
4274 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4275 params.ext_capab =
4276 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4277 params.ext_capab_len =
4278 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4279 }
4280
Jouni Malinendf881292013-02-14 21:10:54 +02004281 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004282 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004283
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004284 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004285 return -EINVAL;
4286
Johannes Bergf8bacc22013-02-14 23:27:01 +01004287 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004288 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004289 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4290 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4291 return -EINVAL;
4292 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004293
Johannes Bergf8bacc22013-02-14 23:27:01 +01004294 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004295 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004296 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4297 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4298 return -EINVAL;
4299 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4300 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004301
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004302 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4303 enum nl80211_mesh_power_mode pm = nla_get_u32(
4304 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4305
4306 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4307 pm > NL80211_MESH_POWER_MAX)
4308 return -EINVAL;
4309
4310 params.local_pm = pm;
4311 }
4312
Johannes Berg77ee7c82013-02-15 00:48:33 +01004313 /* Include parameters for TDLS peer (will check later) */
4314 err = nl80211_set_station_tdls(info, &params);
4315 if (err)
4316 return err;
4317
4318 params.vlan = get_vlan(info, rdev);
4319 if (IS_ERR(params.vlan))
4320 return PTR_ERR(params.vlan);
4321
Johannes Berga97f4422009-06-18 17:23:43 +02004322 switch (dev->ieee80211_ptr->iftype) {
4323 case NL80211_IFTYPE_AP:
4324 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004325 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004326 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004327 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004328 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004329 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004330 break;
4331 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004332 err = -EOPNOTSUPP;
4333 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004334 }
4335
Johannes Berg77ee7c82013-02-15 00:48:33 +01004336 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004337 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004338
Johannes Berg77ee7c82013-02-15 00:48:33 +01004339 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004340 if (params.vlan)
4341 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004342
Johannes Berg5727ef12007-12-19 02:03:34 +01004343 return err;
4344}
4345
4346static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4347{
Johannes Berg4c476992010-10-04 21:36:35 +02004348 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004349 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004350 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004351 struct station_parameters params;
4352 u8 *mac_addr = NULL;
4353
4354 memset(&params, 0, sizeof(params));
4355
Johannes Berg984c3112013-02-14 23:43:25 +01004356 if (!rdev->ops->add_station)
4357 return -EOPNOTSUPP;
4358
Johannes Berg5727ef12007-12-19 02:03:34 +01004359 if (!info->attrs[NL80211_ATTR_MAC])
4360 return -EINVAL;
4361
Johannes Berg5727ef12007-12-19 02:03:34 +01004362 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4363 return -EINVAL;
4364
4365 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4366 return -EINVAL;
4367
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004368 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4369 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004370 return -EINVAL;
4371
Johannes Berg5727ef12007-12-19 02:03:34 +01004372 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4373 params.supported_rates =
4374 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4375 params.supported_rates_len =
4376 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4377 params.listen_interval =
4378 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004379
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004380 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004381 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004382 else
4383 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004384 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4385 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004386
Jouni Malinen9d62a982013-02-14 21:10:13 +02004387 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4388 params.capability =
4389 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4390 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4391 }
4392
4393 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4394 params.ext_capab =
4395 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4396 params.ext_capab_len =
4397 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4398 }
4399
Jouni Malinen36aedc92008-08-25 11:58:58 +03004400 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4401 params.ht_capa =
4402 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004403
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004404 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4405 params.vht_capa =
4406 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4407
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004408 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4409 params.opmode_notif_used = true;
4410 params.opmode_notif =
4411 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4412 }
4413
Johannes Bergf8bacc22013-02-14 23:27:01 +01004414 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004415 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004416 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4417 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4418 return -EINVAL;
4419 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004420
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304421 err = nl80211_parse_sta_channel_info(info, &params);
4422 if (err)
4423 return err;
4424
Johannes Bergff276692013-02-15 00:09:01 +01004425 err = nl80211_parse_sta_wme(info, &params);
4426 if (err)
4427 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004428
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004429 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004430 return -EINVAL;
4431
Johannes Berg496fcc22015-03-12 08:53:27 +02004432 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4433 * as userspace might just pass through the capabilities from the IEs
4434 * directly, rather than enforcing this restriction and returning an
4435 * error in this case.
4436 */
4437 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4438 params.ht_capa = NULL;
4439 params.vht_capa = NULL;
4440 }
4441
Johannes Berg77ee7c82013-02-15 00:48:33 +01004442 /* When you run into this, adjust the code below for the new flag */
4443 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4444
Johannes Bergbdd90d52011-12-14 12:20:27 +01004445 switch (dev->ieee80211_ptr->iftype) {
4446 case NL80211_IFTYPE_AP:
4447 case NL80211_IFTYPE_AP_VLAN:
4448 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004449 /* ignore WME attributes if iface/sta is not capable */
4450 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4451 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4452 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004453
Johannes Bergbdd90d52011-12-14 12:20:27 +01004454 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004455 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4456 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004457 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004458 /* but don't bother the driver with it */
4459 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004460
Johannes Bergd582cff2012-10-26 17:53:44 +02004461 /* allow authenticated/associated only if driver handles it */
4462 if (!(rdev->wiphy.features &
4463 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4464 params.sta_flags_mask &
4465 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4466 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4467 return -EINVAL;
4468
Johannes Bergbdd90d52011-12-14 12:20:27 +01004469 /* must be last in here for error handling */
4470 params.vlan = get_vlan(info, rdev);
4471 if (IS_ERR(params.vlan))
4472 return PTR_ERR(params.vlan);
4473 break;
4474 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004475 /* ignore uAPSD data */
4476 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4477
Johannes Bergd582cff2012-10-26 17:53:44 +02004478 /* associated is disallowed */
4479 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4480 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004481 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004482 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4483 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004484 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004485 break;
4486 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004487 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004488 /* ignore uAPSD data */
4489 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4490
Johannes Berg77ee7c82013-02-15 00:48:33 +01004491 /* these are disallowed */
4492 if (params.sta_flags_mask &
4493 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4494 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004495 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004496 /* Only TDLS peers can be added */
4497 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4498 return -EINVAL;
4499 /* Can only add if TDLS ... */
4500 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4501 return -EOPNOTSUPP;
4502 /* ... with external setup is supported */
4503 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4504 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004505 /*
4506 * Older wpa_supplicant versions always mark the TDLS peer
4507 * as authorized, but it shouldn't yet be.
4508 */
4509 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004510 break;
4511 default:
4512 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004513 }
4514
Johannes Bergbdd90d52011-12-14 12:20:27 +01004515 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004516
Hila Gonene35e4d22012-06-27 17:19:42 +03004517 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004518
Johannes Berg5727ef12007-12-19 02:03:34 +01004519 if (params.vlan)
4520 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004521 return err;
4522}
4523
4524static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4525{
Johannes Berg4c476992010-10-04 21:36:35 +02004526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4527 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004528 struct station_del_parameters params;
4529
4530 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004531
4532 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004533 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004534
Johannes Berge80cf852009-05-11 14:43:13 +02004535 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004536 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004537 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004538 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4539 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004540
Johannes Berg4c476992010-10-04 21:36:35 +02004541 if (!rdev->ops->del_station)
4542 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004543
Jouni Malinen98856862014-10-20 13:20:45 +03004544 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4545 params.subtype =
4546 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4547 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4548 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4549 return -EINVAL;
4550 } else {
4551 /* Default to Deauthentication frame */
4552 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4553 }
4554
4555 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4556 params.reason_code =
4557 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4558 if (params.reason_code == 0)
4559 return -EINVAL; /* 0 is reserved */
4560 } else {
4561 /* Default to reason code 2 */
4562 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4563 }
4564
Jouni Malinen89c771e2014-10-10 20:52:40 +03004565 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004566}
4567
Eric W. Biederman15e47302012-09-07 20:12:54 +00004568static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004569 int flags, struct net_device *dev,
4570 u8 *dst, u8 *next_hop,
4571 struct mpath_info *pinfo)
4572{
4573 void *hdr;
4574 struct nlattr *pinfoattr;
4575
Henning Rogge1ef4c852014-11-04 16:14:58 +01004576 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004577 if (!hdr)
4578 return -1;
4579
David S. Miller9360ffd2012-03-29 04:41:26 -04004580 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4581 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4582 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4583 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4584 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004585
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004586 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4587 if (!pinfoattr)
4588 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004589 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4590 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4591 pinfo->frame_qlen))
4592 goto nla_put_failure;
4593 if (((pinfo->filled & MPATH_INFO_SN) &&
4594 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4595 ((pinfo->filled & MPATH_INFO_METRIC) &&
4596 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4597 pinfo->metric)) ||
4598 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4599 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4600 pinfo->exptime)) ||
4601 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4602 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4603 pinfo->flags)) ||
4604 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4605 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4606 pinfo->discovery_timeout)) ||
4607 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4608 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4609 pinfo->discovery_retries)))
4610 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004611
4612 nla_nest_end(msg, pinfoattr);
4613
Johannes Berg053c0952015-01-16 22:09:00 +01004614 genlmsg_end(msg, hdr);
4615 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004616
4617 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004618 genlmsg_cancel(msg, hdr);
4619 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004620}
4621
4622static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004623 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004624{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004625 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004626 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004627 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004628 u8 dst[ETH_ALEN];
4629 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004630 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004631 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004632
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004633 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004634 if (err)
4635 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004636
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004637 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004638 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004639 goto out_err;
4640 }
4641
Johannes Berg97990a02013-04-19 01:02:55 +02004642 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004643 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004644 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004645 }
4646
Johannes Bergbba95fe2008-07-29 13:22:51 +02004647 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004648 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004649 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004650 if (err == -ENOENT)
4651 break;
4652 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004653 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004654
Eric W. Biederman15e47302012-09-07 20:12:54 +00004655 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004656 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004657 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004658 &pinfo) < 0)
4659 goto out;
4660
4661 path_idx++;
4662 }
4663
4664
4665 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004666 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004667 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004668 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004669 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004670 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004671}
4672
4673static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4674{
Johannes Berg4c476992010-10-04 21:36:35 +02004675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004676 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004677 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004678 struct mpath_info pinfo;
4679 struct sk_buff *msg;
4680 u8 *dst = NULL;
4681 u8 next_hop[ETH_ALEN];
4682
4683 memset(&pinfo, 0, sizeof(pinfo));
4684
4685 if (!info->attrs[NL80211_ATTR_MAC])
4686 return -EINVAL;
4687
4688 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4689
Johannes Berg4c476992010-10-04 21:36:35 +02004690 if (!rdev->ops->get_mpath)
4691 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004692
Johannes Berg4c476992010-10-04 21:36:35 +02004693 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4694 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004695
Hila Gonene35e4d22012-06-27 17:19:42 +03004696 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004697 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004698 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004699
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004700 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004701 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004702 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004703
Eric W. Biederman15e47302012-09-07 20:12:54 +00004704 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004705 dev, dst, next_hop, &pinfo) < 0) {
4706 nlmsg_free(msg);
4707 return -ENOBUFS;
4708 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004709
Johannes Berg4c476992010-10-04 21:36:35 +02004710 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004711}
4712
4713static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4714{
Johannes Berg4c476992010-10-04 21:36:35 +02004715 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4716 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004717 u8 *dst = NULL;
4718 u8 *next_hop = NULL;
4719
4720 if (!info->attrs[NL80211_ATTR_MAC])
4721 return -EINVAL;
4722
4723 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4724 return -EINVAL;
4725
4726 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4727 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4728
Johannes Berg4c476992010-10-04 21:36:35 +02004729 if (!rdev->ops->change_mpath)
4730 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004731
Johannes Berg4c476992010-10-04 21:36:35 +02004732 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4733 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004734
Hila Gonene35e4d22012-06-27 17:19:42 +03004735 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004736}
Johannes Berg4c476992010-10-04 21:36:35 +02004737
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004738static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4739{
Johannes Berg4c476992010-10-04 21:36:35 +02004740 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4741 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004742 u8 *dst = NULL;
4743 u8 *next_hop = NULL;
4744
4745 if (!info->attrs[NL80211_ATTR_MAC])
4746 return -EINVAL;
4747
4748 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4749 return -EINVAL;
4750
4751 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4752 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4753
Johannes Berg4c476992010-10-04 21:36:35 +02004754 if (!rdev->ops->add_mpath)
4755 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004756
Johannes Berg4c476992010-10-04 21:36:35 +02004757 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4758 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004759
Hila Gonene35e4d22012-06-27 17:19:42 +03004760 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004761}
4762
4763static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4764{
Johannes Berg4c476992010-10-04 21:36:35 +02004765 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4766 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004767 u8 *dst = NULL;
4768
4769 if (info->attrs[NL80211_ATTR_MAC])
4770 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4771
Johannes Berg4c476992010-10-04 21:36:35 +02004772 if (!rdev->ops->del_mpath)
4773 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004774
Hila Gonene35e4d22012-06-27 17:19:42 +03004775 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004776}
4777
Henning Rogge66be7d22014-09-12 08:58:49 +02004778static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4779{
4780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4781 int err;
4782 struct net_device *dev = info->user_ptr[1];
4783 struct mpath_info pinfo;
4784 struct sk_buff *msg;
4785 u8 *dst = NULL;
4786 u8 mpp[ETH_ALEN];
4787
4788 memset(&pinfo, 0, sizeof(pinfo));
4789
4790 if (!info->attrs[NL80211_ATTR_MAC])
4791 return -EINVAL;
4792
4793 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4794
4795 if (!rdev->ops->get_mpp)
4796 return -EOPNOTSUPP;
4797
4798 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4799 return -EOPNOTSUPP;
4800
4801 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4802 if (err)
4803 return err;
4804
4805 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4806 if (!msg)
4807 return -ENOMEM;
4808
4809 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4810 dev, dst, mpp, &pinfo) < 0) {
4811 nlmsg_free(msg);
4812 return -ENOBUFS;
4813 }
4814
4815 return genlmsg_reply(msg, info);
4816}
4817
4818static int nl80211_dump_mpp(struct sk_buff *skb,
4819 struct netlink_callback *cb)
4820{
4821 struct mpath_info pinfo;
4822 struct cfg80211_registered_device *rdev;
4823 struct wireless_dev *wdev;
4824 u8 dst[ETH_ALEN];
4825 u8 mpp[ETH_ALEN];
4826 int path_idx = cb->args[2];
4827 int err;
4828
4829 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4830 if (err)
4831 return err;
4832
4833 if (!rdev->ops->dump_mpp) {
4834 err = -EOPNOTSUPP;
4835 goto out_err;
4836 }
4837
4838 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4839 err = -EOPNOTSUPP;
4840 goto out_err;
4841 }
4842
4843 while (1) {
4844 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4845 mpp, &pinfo);
4846 if (err == -ENOENT)
4847 break;
4848 if (err)
4849 goto out_err;
4850
4851 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4852 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4853 wdev->netdev, dst, mpp,
4854 &pinfo) < 0)
4855 goto out;
4856
4857 path_idx++;
4858 }
4859
4860 out:
4861 cb->args[2] = path_idx;
4862 err = skb->len;
4863 out_err:
4864 nl80211_finish_wdev_dump(rdev);
4865 return err;
4866}
4867
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004868static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4869{
Johannes Berg4c476992010-10-04 21:36:35 +02004870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4871 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004872 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004873 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004874 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004875
4876 memset(&params, 0, sizeof(params));
4877 /* default to not changing parameters */
4878 params.use_cts_prot = -1;
4879 params.use_short_preamble = -1;
4880 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004881 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004882 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004883 params.p2p_ctwindow = -1;
4884 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004885
4886 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4887 params.use_cts_prot =
4888 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4889 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4890 params.use_short_preamble =
4891 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4892 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4893 params.use_short_slot_time =
4894 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004895 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4896 params.basic_rates =
4897 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4898 params.basic_rates_len =
4899 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4900 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004901 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4902 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004903 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4904 params.ht_opmode =
4905 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004906
Johannes Berg53cabad2012-11-14 15:17:28 +01004907 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4908 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4909 return -EINVAL;
4910 params.p2p_ctwindow =
4911 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4912 if (params.p2p_ctwindow < 0)
4913 return -EINVAL;
4914 if (params.p2p_ctwindow != 0 &&
4915 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4916 return -EINVAL;
4917 }
4918
4919 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4920 u8 tmp;
4921
4922 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4923 return -EINVAL;
4924 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4925 if (tmp > 1)
4926 return -EINVAL;
4927 params.p2p_opp_ps = tmp;
4928 if (params.p2p_opp_ps &&
4929 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4930 return -EINVAL;
4931 }
4932
Johannes Berg4c476992010-10-04 21:36:35 +02004933 if (!rdev->ops->change_bss)
4934 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004935
Johannes Berg074ac8d2010-09-16 14:58:22 +02004936 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004937 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4938 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004939
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004940 wdev_lock(wdev);
4941 err = rdev_change_bss(rdev, dev, &params);
4942 wdev_unlock(wdev);
4943
4944 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004945}
4946
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004947static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004948 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4949 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4950 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4951 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4952 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4953 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004954 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004955};
4956
4957static int parse_reg_rule(struct nlattr *tb[],
4958 struct ieee80211_reg_rule *reg_rule)
4959{
4960 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4961 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4962
4963 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4964 return -EINVAL;
4965 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4966 return -EINVAL;
4967 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4968 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004969 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4970 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004971 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4972 return -EINVAL;
4973
4974 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4975
4976 freq_range->start_freq_khz =
4977 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4978 freq_range->end_freq_khz =
4979 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004980 freq_range->max_bandwidth_khz =
4981 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004982
4983 power_rule->max_eirp =
4984 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4985
4986 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4987 power_rule->max_antenna_gain =
4988 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4989
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004990 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4991 reg_rule->dfs_cac_ms =
4992 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4993
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004994 return 0;
4995}
4996
4997static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4998{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004999 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05005000 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005001 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05005002 u32 owner_nlportid;
5003
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005004
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005005 /*
5006 * You should only get this when cfg80211 hasn't yet initialized
5007 * completely when built-in to the kernel right between the time
5008 * window between nl80211_init() and regulatory_init(), if that is
5009 * even possible.
5010 */
Johannes Berg458f4f92012-12-06 15:47:38 +01005011 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005012 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005013
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005014 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5015 user_reg_hint_type =
5016 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5017 else
5018 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5019
5020 switch (user_reg_hint_type) {
5021 case NL80211_USER_REG_HINT_USER:
5022 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005023 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5024 return -EINVAL;
5025
5026 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5027 return regulatory_hint_user(data, user_reg_hint_type);
5028 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005029 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5030 owner_nlportid = info->snd_portid;
5031 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5032 } else {
5033 owner_nlportid = 0;
5034 is_indoor = true;
5035 }
5036
5037 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005038 default:
5039 return -EINVAL;
5040 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005041}
5042
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005043static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005044 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005045{
Johannes Berg4c476992010-10-04 21:36:35 +02005046 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005047 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005048 struct wireless_dev *wdev = dev->ieee80211_ptr;
5049 struct mesh_config cur_params;
5050 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005051 void *hdr;
5052 struct nlattr *pinfoattr;
5053 struct sk_buff *msg;
5054
Johannes Berg29cbe682010-12-03 09:20:44 +01005055 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5056 return -EOPNOTSUPP;
5057
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005058 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005059 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005060
Johannes Berg29cbe682010-12-03 09:20:44 +01005061 wdev_lock(wdev);
5062 /* If not connected, get default parameters */
5063 if (!wdev->mesh_id_len)
5064 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5065 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005066 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005067 wdev_unlock(wdev);
5068
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005069 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005070 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005071
5072 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005073 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005074 if (!msg)
5075 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005076 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005077 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005078 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005079 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005080 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005081 if (!pinfoattr)
5082 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005083 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5084 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5085 cur_params.dot11MeshRetryTimeout) ||
5086 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5087 cur_params.dot11MeshConfirmTimeout) ||
5088 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5089 cur_params.dot11MeshHoldingTimeout) ||
5090 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5091 cur_params.dot11MeshMaxPeerLinks) ||
5092 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5093 cur_params.dot11MeshMaxRetries) ||
5094 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5095 cur_params.dot11MeshTTL) ||
5096 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5097 cur_params.element_ttl) ||
5098 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5099 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005100 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5101 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005102 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5103 cur_params.dot11MeshHWMPmaxPREQretries) ||
5104 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5105 cur_params.path_refresh_time) ||
5106 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5107 cur_params.min_discovery_timeout) ||
5108 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5109 cur_params.dot11MeshHWMPactivePathTimeout) ||
5110 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5111 cur_params.dot11MeshHWMPpreqMinInterval) ||
5112 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5113 cur_params.dot11MeshHWMPperrMinInterval) ||
5114 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5115 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5116 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5117 cur_params.dot11MeshHWMPRootMode) ||
5118 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5119 cur_params.dot11MeshHWMPRannInterval) ||
5120 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5121 cur_params.dot11MeshGateAnnouncementProtocol) ||
5122 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5123 cur_params.dot11MeshForwarding) ||
5124 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005125 cur_params.rssi_threshold) ||
5126 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005127 cur_params.ht_opmode) ||
5128 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5129 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5130 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005131 cur_params.dot11MeshHWMProotInterval) ||
5132 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005133 cur_params.dot11MeshHWMPconfirmationInterval) ||
5134 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5135 cur_params.power_mode) ||
5136 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005137 cur_params.dot11MeshAwakeWindowDuration) ||
5138 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5139 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005140 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005141 nla_nest_end(msg, pinfoattr);
5142 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005143 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005144
Johannes Berg3b858752009-03-12 09:55:09 +01005145 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005146 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005147 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005148 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005149 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005150}
5151
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005152static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005153 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5154 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5155 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5156 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5157 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5158 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005159 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005160 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005161 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005162 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5163 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5164 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5165 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5166 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005167 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005168 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005169 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005170 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005171 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005172 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005173 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5174 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005175 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5176 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005177 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005178 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5179 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005180 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005181};
5182
Javier Cardonac80d5452010-12-16 17:37:49 -08005183static const struct nla_policy
5184 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005185 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005186 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5187 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005188 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005189 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005190 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005191 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005192 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005193 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005194};
5195
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005196static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005197 struct mesh_config *cfg,
5198 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005199{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005200 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005201 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005202
Marco Porschea54fba2013-01-07 16:04:48 +01005203#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5204do { \
5205 if (tb[attr]) { \
5206 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5207 return -EINVAL; \
5208 cfg->param = fn(tb[attr]); \
5209 mask |= (1 << (attr - 1)); \
5210 } \
5211} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005212
5213
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005214 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005215 return -EINVAL;
5216 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005217 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005218 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005219 return -EINVAL;
5220
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005221 /* This makes sure that there aren't more than 32 mesh config
5222 * parameters (otherwise our bitfield scheme would not work.) */
5223 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5224
5225 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005227 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5228 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005229 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005230 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5231 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005233 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5234 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005235 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005236 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5237 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005239 mask, NL80211_MESHCONF_MAX_RETRIES,
5240 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005241 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005242 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005243 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005244 mask, NL80211_MESHCONF_ELEMENT_TTL,
5245 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005246 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005247 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5248 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005249 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5250 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005251 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5252 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005253 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005254 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5255 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005256 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005257 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5258 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005259 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005260 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5261 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005262 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5263 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005264 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5265 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005266 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005267 1, 65535, mask,
5268 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005269 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005270 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005271 1, 65535, mask,
5272 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005273 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005274 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005275 dot11MeshHWMPnetDiameterTraversalTime,
5276 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005277 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5278 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005279 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5280 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5281 nla_get_u8);
5282 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5283 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005284 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005285 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005286 dot11MeshGateAnnouncementProtocol, 0, 1,
5287 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005288 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005289 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005290 mask, NL80211_MESHCONF_FORWARDING,
5291 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005292 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005293 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005294 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005295 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005296 mask, NL80211_MESHCONF_HT_OPMODE,
5297 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005298 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005299 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005300 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5301 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005302 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005303 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5304 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005305 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005306 dot11MeshHWMPconfirmationInterval,
5307 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005308 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5309 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005310 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5311 NL80211_MESH_POWER_ACTIVE,
5312 NL80211_MESH_POWER_MAX,
5313 mask, NL80211_MESHCONF_POWER_MODE,
5314 nla_get_u32);
5315 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5316 0, 65535, mask,
5317 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005318 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005319 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5320 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005321 if (mask_out)
5322 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005323
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005324 return 0;
5325
5326#undef FILL_IN_MESH_PARAM_IF_SET
5327}
5328
Javier Cardonac80d5452010-12-16 17:37:49 -08005329static int nl80211_parse_mesh_setup(struct genl_info *info,
5330 struct mesh_setup *setup)
5331{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005333 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5334
5335 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5336 return -EINVAL;
5337 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5338 info->attrs[NL80211_ATTR_MESH_SETUP],
5339 nl80211_mesh_setup_params_policy))
5340 return -EINVAL;
5341
Javier Cardonad299a1f2012-03-31 11:31:33 -07005342 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5343 setup->sync_method =
5344 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5345 IEEE80211_SYNC_METHOD_VENDOR :
5346 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5347
Javier Cardonac80d5452010-12-16 17:37:49 -08005348 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5349 setup->path_sel_proto =
5350 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5351 IEEE80211_PATH_PROTOCOL_VENDOR :
5352 IEEE80211_PATH_PROTOCOL_HWMP;
5353
5354 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5355 setup->path_metric =
5356 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5357 IEEE80211_PATH_METRIC_VENDOR :
5358 IEEE80211_PATH_METRIC_AIRTIME;
5359
Javier Cardona581a8b02011-04-07 15:08:27 -07005360
5361 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005362 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005363 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005364 if (!is_valid_ie_attr(ieattr))
5365 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005366 setup->ie = nla_data(ieattr);
5367 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005368 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005369 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5370 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5371 return -EINVAL;
5372 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005373 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5374 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005375 if (setup->is_secure)
5376 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005377
Colleen Twitty6e16d902013-05-08 11:45:59 -07005378 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5379 if (!setup->user_mpm)
5380 return -EINVAL;
5381 setup->auth_id =
5382 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5383 }
5384
Javier Cardonac80d5452010-12-16 17:37:49 -08005385 return 0;
5386}
5387
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005388static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005389 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005390{
5391 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5392 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005393 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005394 struct mesh_config cfg;
5395 u32 mask;
5396 int err;
5397
Johannes Berg29cbe682010-12-03 09:20:44 +01005398 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5399 return -EOPNOTSUPP;
5400
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005401 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005402 return -EOPNOTSUPP;
5403
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005404 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005405 if (err)
5406 return err;
5407
Johannes Berg29cbe682010-12-03 09:20:44 +01005408 wdev_lock(wdev);
5409 if (!wdev->mesh_id_len)
5410 err = -ENOLINK;
5411
5412 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005413 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005414
5415 wdev_unlock(wdev);
5416
5417 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005418}
5419
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005420static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5421 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005422{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005423 struct nlattr *nl_reg_rules;
5424 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005425
Johannes Berg458f4f92012-12-06 15:47:38 +01005426 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5427 (regdom->dfs_region &&
5428 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005429 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005430
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005431 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5432 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005433 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005434
Johannes Berg458f4f92012-12-06 15:47:38 +01005435 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005436 struct nlattr *nl_reg_rule;
5437 const struct ieee80211_reg_rule *reg_rule;
5438 const struct ieee80211_freq_range *freq_range;
5439 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005440 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005441
Johannes Berg458f4f92012-12-06 15:47:38 +01005442 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005443 freq_range = &reg_rule->freq_range;
5444 power_rule = &reg_rule->power_rule;
5445
5446 nl_reg_rule = nla_nest_start(msg, i);
5447 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005448 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005449
Janusz Dziedzic97524822014-01-30 09:52:20 +01005450 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5451 if (!max_bandwidth_khz)
5452 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5453 reg_rule);
5454
David S. Miller9360ffd2012-03-29 04:41:26 -04005455 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5456 reg_rule->flags) ||
5457 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5458 freq_range->start_freq_khz) ||
5459 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5460 freq_range->end_freq_khz) ||
5461 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005462 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005463 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5464 power_rule->max_antenna_gain) ||
5465 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005466 power_rule->max_eirp) ||
5467 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5468 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005469 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005470
5471 nla_nest_end(msg, nl_reg_rule);
5472 }
5473
5474 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005475 return 0;
5476
5477nla_put_failure:
5478 return -EMSGSIZE;
5479}
5480
5481static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5482{
5483 const struct ieee80211_regdomain *regdom = NULL;
5484 struct cfg80211_registered_device *rdev;
5485 struct wiphy *wiphy = NULL;
5486 struct sk_buff *msg;
5487 void *hdr;
5488
5489 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5490 if (!msg)
5491 return -ENOBUFS;
5492
5493 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5494 NL80211_CMD_GET_REG);
5495 if (!hdr)
5496 goto put_failure;
5497
5498 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005499 bool self_managed;
5500
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005501 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5502 if (IS_ERR(rdev)) {
5503 nlmsg_free(msg);
5504 return PTR_ERR(rdev);
5505 }
5506
5507 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005508 self_managed = wiphy->regulatory_flags &
5509 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005510 regdom = get_wiphy_regdom(wiphy);
5511
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005512 /* a self-managed-reg device must have a private regdom */
5513 if (WARN_ON(!regdom && self_managed)) {
5514 nlmsg_free(msg);
5515 return -EINVAL;
5516 }
5517
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005518 if (regdom &&
5519 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5520 goto nla_put_failure;
5521 }
5522
5523 if (!wiphy && reg_last_request_cell_base() &&
5524 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5525 NL80211_USER_REG_HINT_CELL_BASE))
5526 goto nla_put_failure;
5527
5528 rcu_read_lock();
5529
5530 if (!regdom)
5531 regdom = rcu_dereference(cfg80211_regdomain);
5532
5533 if (nl80211_put_regdom(regdom, msg))
5534 goto nla_put_failure_rcu;
5535
5536 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005537
5538 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005539 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005540
Johannes Berg458f4f92012-12-06 15:47:38 +01005541nla_put_failure_rcu:
5542 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005543nla_put_failure:
5544 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005545put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005546 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005547 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005548}
5549
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005550static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5551 u32 seq, int flags, struct wiphy *wiphy,
5552 const struct ieee80211_regdomain *regdom)
5553{
5554 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5555 NL80211_CMD_GET_REG);
5556
5557 if (!hdr)
5558 return -1;
5559
5560 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5561
5562 if (nl80211_put_regdom(regdom, msg))
5563 goto nla_put_failure;
5564
5565 if (!wiphy && reg_last_request_cell_base() &&
5566 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5567 NL80211_USER_REG_HINT_CELL_BASE))
5568 goto nla_put_failure;
5569
5570 if (wiphy &&
5571 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5572 goto nla_put_failure;
5573
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005574 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5575 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5576 goto nla_put_failure;
5577
Johannes Berg053c0952015-01-16 22:09:00 +01005578 genlmsg_end(msg, hdr);
5579 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005580
5581nla_put_failure:
5582 genlmsg_cancel(msg, hdr);
5583 return -EMSGSIZE;
5584}
5585
5586static int nl80211_get_reg_dump(struct sk_buff *skb,
5587 struct netlink_callback *cb)
5588{
5589 const struct ieee80211_regdomain *regdom = NULL;
5590 struct cfg80211_registered_device *rdev;
5591 int err, reg_idx, start = cb->args[2];
5592
5593 rtnl_lock();
5594
5595 if (cfg80211_regdomain && start == 0) {
5596 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5597 NLM_F_MULTI, NULL,
5598 rtnl_dereference(cfg80211_regdomain));
5599 if (err < 0)
5600 goto out_err;
5601 }
5602
5603 /* the global regdom is idx 0 */
5604 reg_idx = 1;
5605 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5606 regdom = get_wiphy_regdom(&rdev->wiphy);
5607 if (!regdom)
5608 continue;
5609
5610 if (++reg_idx <= start)
5611 continue;
5612
5613 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5614 NLM_F_MULTI, &rdev->wiphy, regdom);
5615 if (err < 0) {
5616 reg_idx--;
5617 break;
5618 }
5619 }
5620
5621 cb->args[2] = reg_idx;
5622 err = skb->len;
5623out_err:
5624 rtnl_unlock();
5625 return err;
5626}
5627
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005628static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5629{
5630 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5631 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005632 char *alpha2;
5633 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005634 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005635 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005636 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005637
5638 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5639 return -EINVAL;
5640
5641 if (!info->attrs[NL80211_ATTR_REG_RULES])
5642 return -EINVAL;
5643
5644 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5645
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005646 if (info->attrs[NL80211_ATTR_DFS_REGION])
5647 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5648
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005649 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005650 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005651 num_rules++;
5652 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005653 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005654 }
5655
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005656 if (!reg_is_valid_request(alpha2))
5657 return -EINVAL;
5658
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005659 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005660 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005661
5662 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005663 if (!rd)
5664 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005665
5666 rd->n_reg_rules = num_rules;
5667 rd->alpha2[0] = alpha2[0];
5668 rd->alpha2[1] = alpha2[1];
5669
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005670 /*
5671 * Disable DFS master mode if the DFS region was
5672 * not supported or known on this kernel.
5673 */
5674 if (reg_supported_dfs_region(dfs_region))
5675 rd->dfs_region = dfs_region;
5676
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005677 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005678 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005679 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5680 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5681 reg_rule_policy);
5682 if (r)
5683 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005684 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5685 if (r)
5686 goto bad_reg;
5687
5688 rule_idx++;
5689
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005690 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5691 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005692 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005693 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005694 }
5695
Ilan peerc37722b2015-03-30 15:15:49 +03005696 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005697 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005698 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005699
Johannes Bergd2372b32008-10-24 20:32:20 +02005700 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005701 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005702 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005703}
5704
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005705static int validate_scan_freqs(struct nlattr *freqs)
5706{
5707 struct nlattr *attr1, *attr2;
5708 int n_channels = 0, tmp1, tmp2;
5709
5710 nla_for_each_nested(attr1, freqs, tmp1) {
5711 n_channels++;
5712 /*
5713 * Some hardware has a limited channel list for
5714 * scanning, and it is pretty much nonsensical
5715 * to scan for a channel twice, so disallow that
5716 * and don't require drivers to check that the
5717 * channel list they get isn't longer than what
5718 * they can scan, as long as they can scan all
5719 * the channels they registered at once.
5720 */
5721 nla_for_each_nested(attr2, freqs, tmp2)
5722 if (attr1 != attr2 &&
5723 nla_get_u32(attr1) == nla_get_u32(attr2))
5724 return 0;
5725 }
5726
5727 return n_channels;
5728}
5729
Johannes Bergad2b26a2014-06-12 21:39:05 +02005730static int nl80211_parse_random_mac(struct nlattr **attrs,
5731 u8 *mac_addr, u8 *mac_addr_mask)
5732{
5733 int i;
5734
5735 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005736 eth_zero_addr(mac_addr);
5737 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005738 mac_addr[0] = 0x2;
5739 mac_addr_mask[0] = 0x3;
5740
5741 return 0;
5742 }
5743
5744 /* need both or none */
5745 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5746 return -EINVAL;
5747
5748 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5749 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5750
5751 /* don't allow or configure an mcast address */
5752 if (!is_multicast_ether_addr(mac_addr_mask) ||
5753 is_multicast_ether_addr(mac_addr))
5754 return -EINVAL;
5755
5756 /*
5757 * allow users to pass a MAC address that has bits set outside
5758 * of the mask, but don't bother drivers with having to deal
5759 * with such bits
5760 */
5761 for (i = 0; i < ETH_ALEN; i++)
5762 mac_addr[i] &= mac_addr_mask[i];
5763
5764 return 0;
5765}
5766
Johannes Berg2a519312009-02-10 21:25:55 +01005767static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5768{
Johannes Berg4c476992010-10-04 21:36:35 +02005769 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005770 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005771 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005772 struct nlattr *attr;
5773 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005774 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005775 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005776
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005777 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5778 return -EINVAL;
5779
Johannes Berg79c97e92009-07-07 03:56:12 +02005780 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005781
Johannes Berg4c476992010-10-04 21:36:35 +02005782 if (!rdev->ops->scan)
5783 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005784
Johannes Bergf9d15d12014-01-22 11:14:19 +02005785 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005786 err = -EBUSY;
5787 goto unlock;
5788 }
Johannes Berg2a519312009-02-10 21:25:55 +01005789
5790 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005791 n_channels = validate_scan_freqs(
5792 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005793 if (!n_channels) {
5794 err = -EINVAL;
5795 goto unlock;
5796 }
Johannes Berg2a519312009-02-10 21:25:55 +01005797 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005798 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005799 }
5800
5801 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5802 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5803 n_ssids++;
5804
Johannes Bergf9f47522013-03-19 15:04:07 +01005805 if (n_ssids > wiphy->max_scan_ssids) {
5806 err = -EINVAL;
5807 goto unlock;
5808 }
Johannes Berg2a519312009-02-10 21:25:55 +01005809
Jouni Malinen70692ad2009-02-16 19:39:13 +02005810 if (info->attrs[NL80211_ATTR_IE])
5811 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5812 else
5813 ie_len = 0;
5814
Johannes Bergf9f47522013-03-19 15:04:07 +01005815 if (ie_len > wiphy->max_scan_ie_len) {
5816 err = -EINVAL;
5817 goto unlock;
5818 }
Johannes Berg18a83652009-03-31 12:12:05 +02005819
Johannes Berg2a519312009-02-10 21:25:55 +01005820 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005821 + sizeof(*request->ssids) * n_ssids
5822 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005823 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005824 if (!request) {
5825 err = -ENOMEM;
5826 goto unlock;
5827 }
Johannes Berg2a519312009-02-10 21:25:55 +01005828
Johannes Berg2a519312009-02-10 21:25:55 +01005829 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005830 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005831 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005832 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005833 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005834 request->ie = (void *)(request->ssids + n_ssids);
5835 else
5836 request->ie = (void *)(request->channels + n_channels);
5837 }
Johannes Berg2a519312009-02-10 21:25:55 +01005838
Johannes Berg584991d2009-11-02 13:32:03 +01005839 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005840 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5841 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005842 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005843 struct ieee80211_channel *chan;
5844
5845 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5846
5847 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005848 err = -EINVAL;
5849 goto out_free;
5850 }
Johannes Berg584991d2009-11-02 13:32:03 +01005851
5852 /* ignore disabled channels */
5853 if (chan->flags & IEEE80211_CHAN_DISABLED)
5854 continue;
5855
5856 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005857 i++;
5858 }
5859 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005860 enum ieee80211_band band;
5861
Johannes Berg2a519312009-02-10 21:25:55 +01005862 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005863 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5864 int j;
5865 if (!wiphy->bands[band])
5866 continue;
5867 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005868 struct ieee80211_channel *chan;
5869
5870 chan = &wiphy->bands[band]->channels[j];
5871
5872 if (chan->flags & IEEE80211_CHAN_DISABLED)
5873 continue;
5874
5875 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005876 i++;
5877 }
5878 }
5879 }
5880
Johannes Berg584991d2009-11-02 13:32:03 +01005881 if (!i) {
5882 err = -EINVAL;
5883 goto out_free;
5884 }
5885
5886 request->n_channels = i;
5887
Johannes Berg2a519312009-02-10 21:25:55 +01005888 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005889 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005890 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005891 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005892 err = -EINVAL;
5893 goto out_free;
5894 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005895 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005896 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005897 i++;
5898 }
5899 }
5900
Jouni Malinen70692ad2009-02-16 19:39:13 +02005901 if (info->attrs[NL80211_ATTR_IE]) {
5902 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005903 memcpy((void *)request->ie,
5904 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005905 request->ie_len);
5906 }
5907
Johannes Berg34850ab2011-07-18 18:08:35 +02005908 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005909 if (wiphy->bands[i])
5910 request->rates[i] =
5911 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005912
5913 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5914 nla_for_each_nested(attr,
5915 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5916 tmp) {
5917 enum ieee80211_band band = nla_type(attr);
5918
Dan Carpenter84404622011-07-29 11:52:18 +03005919 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005920 err = -EINVAL;
5921 goto out_free;
5922 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005923
5924 if (!wiphy->bands[band])
5925 continue;
5926
Johannes Berg34850ab2011-07-18 18:08:35 +02005927 err = ieee80211_get_ratemask(wiphy->bands[band],
5928 nla_data(attr),
5929 nla_len(attr),
5930 &request->rates[band]);
5931 if (err)
5932 goto out_free;
5933 }
5934 }
5935
Sam Leffler46856bb2012-10-11 21:03:32 -07005936 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005937 request->flags = nla_get_u32(
5938 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005939 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5940 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005941 err = -EOPNOTSUPP;
5942 goto out_free;
5943 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005944
5945 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5946 if (!(wiphy->features &
5947 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5948 err = -EOPNOTSUPP;
5949 goto out_free;
5950 }
5951
5952 if (wdev->current_bss) {
5953 err = -EOPNOTSUPP;
5954 goto out_free;
5955 }
5956
5957 err = nl80211_parse_random_mac(info->attrs,
5958 request->mac_addr,
5959 request->mac_addr_mask);
5960 if (err)
5961 goto out_free;
5962 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005963 }
Sam Lefflered4737712012-10-11 21:03:31 -07005964
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305965 request->no_cck =
5966 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5967
Johannes Bergfd014282012-06-18 19:17:03 +02005968 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005969 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005970 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005971
Johannes Berg79c97e92009-07-07 03:56:12 +02005972 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005973 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005974
Johannes Berg463d0182009-07-14 00:33:35 +02005975 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005976 nl80211_send_scan_start(rdev, wdev);
5977 if (wdev->netdev)
5978 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005979 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005980 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005981 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005982 kfree(request);
5983 }
Johannes Berg3b858752009-03-12 09:55:09 +01005984
Johannes Bergf9f47522013-03-19 15:04:07 +01005985 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005986 return err;
5987}
5988
Avraham Stern3b06d272015-10-12 09:51:34 +03005989static int
5990nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
5991 struct cfg80211_sched_scan_request *request,
5992 struct nlattr **attrs)
5993{
5994 int tmp, err, i = 0;
5995 struct nlattr *attr;
5996
5997 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
5998 u32 interval;
5999
6000 /*
6001 * If scan plans are not specified,
6002 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6003 * case one scan plan will be set with the specified scan
6004 * interval and infinite number of iterations.
6005 */
6006 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6007 return -EINVAL;
6008
6009 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6010 if (!interval)
6011 return -EINVAL;
6012
6013 request->scan_plans[0].interval =
6014 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6015 if (!request->scan_plans[0].interval)
6016 return -EINVAL;
6017
6018 if (request->scan_plans[0].interval >
6019 wiphy->max_sched_scan_plan_interval)
6020 request->scan_plans[0].interval =
6021 wiphy->max_sched_scan_plan_interval;
6022
6023 return 0;
6024 }
6025
6026 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6027 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6028
6029 if (WARN_ON(i >= n_plans))
6030 return -EINVAL;
6031
6032 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6033 nla_data(attr), nla_len(attr),
6034 nl80211_plan_policy);
6035 if (err)
6036 return err;
6037
6038 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6039 return -EINVAL;
6040
6041 request->scan_plans[i].interval =
6042 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6043 if (!request->scan_plans[i].interval ||
6044 request->scan_plans[i].interval >
6045 wiphy->max_sched_scan_plan_interval)
6046 return -EINVAL;
6047
6048 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6049 request->scan_plans[i].iterations =
6050 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6051 if (!request->scan_plans[i].iterations ||
6052 (request->scan_plans[i].iterations >
6053 wiphy->max_sched_scan_plan_iterations))
6054 return -EINVAL;
6055 } else if (i < n_plans - 1) {
6056 /*
6057 * All scan plans but the last one must specify
6058 * a finite number of iterations
6059 */
6060 return -EINVAL;
6061 }
6062
6063 i++;
6064 }
6065
6066 /*
6067 * The last scan plan must not specify the number of
6068 * iterations, it is supposed to run infinitely
6069 */
6070 if (request->scan_plans[n_plans - 1].iterations)
6071 return -EINVAL;
6072
6073 return 0;
6074}
6075
Luciano Coelho256da022014-11-10 16:13:46 +02006076static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006077nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006078 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006079{
6080 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006081 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006082 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006083 enum ieee80211_band band;
6084 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006085 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006086 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006087
Luciano Coelho256da022014-11-10 16:13:46 +02006088 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6089 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006090
Luciano Coelho256da022014-11-10 16:13:46 +02006091 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006092 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006093 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006094 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006095 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006096 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006097 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006098 }
6099
Luciano Coelho256da022014-11-10 16:13:46 +02006100 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6101 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006102 tmp)
6103 n_ssids++;
6104
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006105 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006106 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006107
Johannes Bergea73cbc2014-01-24 10:53:53 +01006108 /*
6109 * First, count the number of 'real' matchsets. Due to an issue with
6110 * the old implementation, matchsets containing only the RSSI attribute
6111 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6112 * RSSI for all matchsets, rather than their own matchset for reporting
6113 * all APs with a strong RSSI. This is needed to be compatible with
6114 * older userspace that treated a matchset with only the RSSI as the
6115 * global RSSI for all other matchsets - if there are other matchsets.
6116 */
Luciano Coelho256da022014-11-10 16:13:46 +02006117 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006118 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006119 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006120 tmp) {
6121 struct nlattr *rssi;
6122
6123 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6124 nla_data(attr), nla_len(attr),
6125 nl80211_match_policy);
6126 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006127 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006128 /* add other standalone attributes here */
6129 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6130 n_match_sets++;
6131 continue;
6132 }
6133 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6134 if (rssi)
6135 default_match_rssi = nla_get_s32(rssi);
6136 }
6137 }
6138
6139 /* However, if there's no other matchset, add the RSSI one */
6140 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6141 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006142
6143 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006144 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006145
Luciano Coelho256da022014-11-10 16:13:46 +02006146 if (attrs[NL80211_ATTR_IE])
6147 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006148 else
6149 ie_len = 0;
6150
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006151 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006152 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006153
Avraham Stern3b06d272015-10-12 09:51:34 +03006154 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6155 /*
6156 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6157 * each scan plan already specifies its own interval
6158 */
6159 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6160 return ERR_PTR(-EINVAL);
6161
6162 nla_for_each_nested(attr,
6163 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6164 n_plans++;
6165 } else {
6166 /*
6167 * The scan interval attribute is kept for backward
6168 * compatibility. If no scan plans are specified and sched scan
6169 * interval is specified, one scan plan will be set with this
6170 * scan interval and infinite number of iterations.
6171 */
6172 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6173 return ERR_PTR(-EINVAL);
6174
6175 n_plans = 1;
6176 }
6177
6178 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6179 return ERR_PTR(-EINVAL);
6180
Luciano Coelho807f8a82011-05-11 17:09:35 +03006181 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006182 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006183 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006184 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006185 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006186 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006187 if (!request)
6188 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006189
6190 if (n_ssids)
6191 request->ssids = (void *)&request->channels[n_channels];
6192 request->n_ssids = n_ssids;
6193 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006194 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006195 request->ie = (void *)(request->ssids + n_ssids);
6196 else
6197 request->ie = (void *)(request->channels + n_channels);
6198 }
6199
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006200 if (n_match_sets) {
6201 if (request->ie)
6202 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006203 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006204 request->match_sets =
6205 (void *)(request->ssids + n_ssids);
6206 else
6207 request->match_sets =
6208 (void *)(request->channels + n_channels);
6209 }
6210 request->n_match_sets = n_match_sets;
6211
Avraham Stern3b06d272015-10-12 09:51:34 +03006212 if (n_match_sets)
6213 request->scan_plans = (void *)(request->match_sets +
6214 n_match_sets);
6215 else if (request->ie)
6216 request->scan_plans = (void *)(request->ie + ie_len);
6217 else if (n_ssids)
6218 request->scan_plans = (void *)(request->ssids + n_ssids);
6219 else
6220 request->scan_plans = (void *)(request->channels + n_channels);
6221
6222 request->n_scan_plans = n_plans;
6223
Luciano Coelho807f8a82011-05-11 17:09:35 +03006224 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006225 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006226 /* user specified, bail out if channel not found */
6227 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006228 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006229 tmp) {
6230 struct ieee80211_channel *chan;
6231
6232 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6233
6234 if (!chan) {
6235 err = -EINVAL;
6236 goto out_free;
6237 }
6238
6239 /* ignore disabled channels */
6240 if (chan->flags & IEEE80211_CHAN_DISABLED)
6241 continue;
6242
6243 request->channels[i] = chan;
6244 i++;
6245 }
6246 } else {
6247 /* all channels */
6248 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6249 int j;
6250 if (!wiphy->bands[band])
6251 continue;
6252 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6253 struct ieee80211_channel *chan;
6254
6255 chan = &wiphy->bands[band]->channels[j];
6256
6257 if (chan->flags & IEEE80211_CHAN_DISABLED)
6258 continue;
6259
6260 request->channels[i] = chan;
6261 i++;
6262 }
6263 }
6264 }
6265
6266 if (!i) {
6267 err = -EINVAL;
6268 goto out_free;
6269 }
6270
6271 request->n_channels = i;
6272
6273 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006274 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006275 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006276 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006277 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006278 err = -EINVAL;
6279 goto out_free;
6280 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006281 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006282 memcpy(request->ssids[i].ssid, nla_data(attr),
6283 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006284 i++;
6285 }
6286 }
6287
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006288 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006289 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006290 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006291 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006292 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006293 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006294
Johannes Bergae811e22014-01-24 10:17:47 +01006295 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6296 nla_data(attr), nla_len(attr),
6297 nl80211_match_policy);
6298 if (err)
6299 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006300 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006301 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006302 if (WARN_ON(i >= n_match_sets)) {
6303 /* this indicates a programming error,
6304 * the loop above should have verified
6305 * things properly
6306 */
6307 err = -EINVAL;
6308 goto out_free;
6309 }
6310
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006311 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6312 err = -EINVAL;
6313 goto out_free;
6314 }
6315 memcpy(request->match_sets[i].ssid.ssid,
6316 nla_data(ssid), nla_len(ssid));
6317 request->match_sets[i].ssid.ssid_len =
6318 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006319 /* special attribute - old implemenation w/a */
6320 request->match_sets[i].rssi_thold =
6321 default_match_rssi;
6322 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6323 if (rssi)
6324 request->match_sets[i].rssi_thold =
6325 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006326 }
6327 i++;
6328 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006329
6330 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006331 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006332 request->match_sets[0].rssi_thold = default_match_rssi;
6333
6334 request->min_rssi_thold = INT_MAX;
6335 for (i = 0; i < n_match_sets; i++)
6336 request->min_rssi_thold =
6337 min(request->match_sets[i].rssi_thold,
6338 request->min_rssi_thold);
6339 } else {
6340 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006341 }
6342
Johannes Berg9900e482014-02-04 21:01:25 +01006343 if (ie_len) {
6344 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006345 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006346 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006347 request->ie_len);
6348 }
6349
Luciano Coelho256da022014-11-10 16:13:46 +02006350 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006351 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006352 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006353 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6354 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006355 err = -EOPNOTSUPP;
6356 goto out_free;
6357 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006358
6359 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6360 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6361
6362 if (!wdev) /* must be net-detect */
6363 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6364
6365 if (!(wiphy->features & flg)) {
6366 err = -EOPNOTSUPP;
6367 goto out_free;
6368 }
6369
6370 if (wdev && wdev->current_bss) {
6371 err = -EOPNOTSUPP;
6372 goto out_free;
6373 }
6374
6375 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6376 request->mac_addr_mask);
6377 if (err)
6378 goto out_free;
6379 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006380 }
Sam Lefflered4737712012-10-11 21:03:31 -07006381
Luciano Coelho9c748932015-01-16 16:04:09 +02006382 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6383 request->delay =
6384 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6385
Avraham Stern3b06d272015-10-12 09:51:34 +03006386 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6387 if (err)
6388 goto out_free;
6389
Sam Leffler15d60302012-10-11 21:03:34 -07006390 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006391
Luciano Coelho256da022014-11-10 16:13:46 +02006392 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006393
6394out_free:
6395 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006396 return ERR_PTR(err);
6397}
6398
6399static int nl80211_start_sched_scan(struct sk_buff *skb,
6400 struct genl_info *info)
6401{
6402 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6403 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006404 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006405 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006406 int err;
6407
6408 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6409 !rdev->ops->sched_scan_start)
6410 return -EOPNOTSUPP;
6411
6412 if (rdev->sched_scan_req)
6413 return -EINPROGRESS;
6414
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006415 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6416 info->attrs);
6417
6418 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006419 if (err)
6420 goto out_err;
6421
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006422 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006423 if (err)
6424 goto out_free;
6425
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006426 sched_scan_req->dev = dev;
6427 sched_scan_req->wiphy = &rdev->wiphy;
6428
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006429 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6430 sched_scan_req->owner_nlportid = info->snd_portid;
6431
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006432 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006433
6434 nl80211_send_sched_scan(rdev, dev,
6435 NL80211_CMD_START_SCHED_SCAN);
6436 return 0;
6437
6438out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006439 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006440out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006441 return err;
6442}
6443
6444static int nl80211_stop_sched_scan(struct sk_buff *skb,
6445 struct genl_info *info)
6446{
6447 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6448
6449 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6450 !rdev->ops->sched_scan_stop)
6451 return -EOPNOTSUPP;
6452
Johannes Berg5fe231e2013-05-08 21:45:15 +02006453 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006454}
6455
Simon Wunderlich04f39042013-02-08 18:16:19 +01006456static int nl80211_start_radar_detection(struct sk_buff *skb,
6457 struct genl_info *info)
6458{
6459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6460 struct net_device *dev = info->user_ptr[1];
6461 struct wireless_dev *wdev = dev->ieee80211_ptr;
6462 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006463 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006464 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006465 int err;
6466
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006467 dfs_region = reg_get_dfs_region(wdev->wiphy);
6468 if (dfs_region == NL80211_DFS_UNSET)
6469 return -EINVAL;
6470
Simon Wunderlich04f39042013-02-08 18:16:19 +01006471 err = nl80211_parse_chandef(rdev, info, &chandef);
6472 if (err)
6473 return err;
6474
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006475 if (netif_carrier_ok(dev))
6476 return -EBUSY;
6477
Simon Wunderlich04f39042013-02-08 18:16:19 +01006478 if (wdev->cac_started)
6479 return -EBUSY;
6480
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006481 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006482 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006483 if (err < 0)
6484 return err;
6485
6486 if (err == 0)
6487 return -EINVAL;
6488
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006489 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006490 return -EINVAL;
6491
6492 if (!rdev->ops->start_radar_detection)
6493 return -EOPNOTSUPP;
6494
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006495 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6496 if (WARN_ON(!cac_time_ms))
6497 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6498
6499 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6500 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006501 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006502 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006503 wdev->cac_started = true;
6504 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006505 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006506 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006507 return err;
6508}
6509
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006510static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6511{
6512 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6513 struct net_device *dev = info->user_ptr[1];
6514 struct wireless_dev *wdev = dev->ieee80211_ptr;
6515 struct cfg80211_csa_settings params;
6516 /* csa_attrs is defined static to avoid waste of stack size - this
6517 * function is called under RTNL lock, so this should not be a problem.
6518 */
6519 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006520 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006521 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006522 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006523 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006524
6525 if (!rdev->ops->channel_switch ||
6526 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6527 return -EOPNOTSUPP;
6528
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006529 switch (dev->ieee80211_ptr->iftype) {
6530 case NL80211_IFTYPE_AP:
6531 case NL80211_IFTYPE_P2P_GO:
6532 need_new_beacon = true;
6533
6534 /* useless if AP is not running */
6535 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006536 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006537 break;
6538 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006539 if (!wdev->ssid_len)
6540 return -ENOTCONN;
6541 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006542 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006543 if (!wdev->mesh_id_len)
6544 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006545 break;
6546 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006547 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006548 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006549
6550 memset(&params, 0, sizeof(params));
6551
6552 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6553 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6554 return -EINVAL;
6555
6556 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006557 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006558 return -EINVAL;
6559
Luciano Coelho252e07c2014-10-08 09:48:34 +03006560 /* Even though the attribute is u32, the specification says
6561 * u8, so let's make sure we don't overflow.
6562 */
6563 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6564 if (cs_count > 255)
6565 return -EINVAL;
6566
6567 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006568
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006569 if (!need_new_beacon)
6570 goto skip_beacons;
6571
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006572 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6573 if (err)
6574 return err;
6575
6576 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6577 info->attrs[NL80211_ATTR_CSA_IES],
6578 nl80211_policy);
6579 if (err)
6580 return err;
6581
6582 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6583 if (err)
6584 return err;
6585
6586 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6587 return -EINVAL;
6588
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006589 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6590 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006591 return -EINVAL;
6592
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006593 params.n_counter_offsets_beacon = len / sizeof(u16);
6594 if (rdev->wiphy.max_num_csa_counters &&
6595 (params.n_counter_offsets_beacon >
6596 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006597 return -EINVAL;
6598
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006599 params.counter_offsets_beacon =
6600 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6601
6602 /* sanity checks - counters should fit and be the same */
6603 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6604 u16 offset = params.counter_offsets_beacon[i];
6605
6606 if (offset >= params.beacon_csa.tail_len)
6607 return -EINVAL;
6608
6609 if (params.beacon_csa.tail[offset] != params.count)
6610 return -EINVAL;
6611 }
6612
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006613 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006614 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6615 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006616 return -EINVAL;
6617
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006618 params.n_counter_offsets_presp = len / sizeof(u16);
6619 if (rdev->wiphy.max_num_csa_counters &&
6620 (params.n_counter_offsets_beacon >
6621 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006622 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006623
6624 params.counter_offsets_presp =
6625 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6626
6627 /* sanity checks - counters should fit and be the same */
6628 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6629 u16 offset = params.counter_offsets_presp[i];
6630
6631 if (offset >= params.beacon_csa.probe_resp_len)
6632 return -EINVAL;
6633
6634 if (params.beacon_csa.probe_resp[offset] !=
6635 params.count)
6636 return -EINVAL;
6637 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006638 }
6639
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006640skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006641 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6642 if (err)
6643 return err;
6644
Arik Nemtsov923b3522015-07-08 15:41:44 +03006645 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6646 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006647 return -EINVAL;
6648
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006649 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6650 &params.chandef,
6651 wdev->iftype);
6652 if (err < 0)
6653 return err;
6654
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006655 if (err > 0)
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006656 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006657
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006658 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6659 params.block_tx = true;
6660
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006661 wdev_lock(wdev);
6662 err = rdev_channel_switch(rdev, dev, &params);
6663 wdev_unlock(wdev);
6664
6665 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006666}
6667
Johannes Berg9720bb32011-06-21 09:45:33 +02006668static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6669 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006670 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006671 struct wireless_dev *wdev,
6672 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006673{
Johannes Berg48ab9052009-07-10 18:42:31 +02006674 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006675 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006676 void *hdr;
6677 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006678
6679 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006680
Eric W. Biederman15e47302012-09-07 20:12:54 +00006681 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006682 NL80211_CMD_NEW_SCAN_RESULTS);
6683 if (!hdr)
6684 return -1;
6685
Johannes Berg9720bb32011-06-21 09:45:33 +02006686 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6687
Johannes Berg97990a02013-04-19 01:02:55 +02006688 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6689 goto nla_put_failure;
6690 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006691 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6692 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006693 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6694 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006695
6696 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6697 if (!bss)
6698 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006699 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006700 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006701 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006702
6703 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006704 /* indicate whether we have probe response data or not */
6705 if (rcu_access_pointer(res->proberesp_ies) &&
6706 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6707 goto fail_unlock_rcu;
6708
6709 /* this pointer prefers to be pointed to probe response data
6710 * but is always valid
6711 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006712 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006713 if (ies) {
6714 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6715 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006716 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6717 ies->len, ies->data))
6718 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006719 }
Johannes Berg0e227082014-08-12 20:34:30 +02006720
6721 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006722 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006723 if (ies && ies->from_beacon) {
6724 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006725 goto fail_unlock_rcu;
6726 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6727 ies->len, ies->data))
6728 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006729 }
6730 rcu_read_unlock();
6731
David S. Miller9360ffd2012-03-29 04:41:26 -04006732 if (res->beacon_interval &&
6733 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6734 goto nla_put_failure;
6735 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6736 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006737 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006738 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6739 jiffies_to_msecs(jiffies - intbss->ts)))
6740 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006741
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006742 if (intbss->ts_boottime &&
6743 nla_put_u64(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6744 intbss->ts_boottime))
6745 goto nla_put_failure;
6746
Johannes Berg77965c92009-02-18 18:45:06 +01006747 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006748 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006749 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6750 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006751 break;
6752 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006753 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6754 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006755 break;
6756 default:
6757 break;
6758 }
6759
Johannes Berg48ab9052009-07-10 18:42:31 +02006760 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006761 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006762 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006763 if (intbss == wdev->current_bss &&
6764 nla_put_u32(msg, NL80211_BSS_STATUS,
6765 NL80211_BSS_STATUS_ASSOCIATED))
6766 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006767 break;
6768 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006769 if (intbss == wdev->current_bss &&
6770 nla_put_u32(msg, NL80211_BSS_STATUS,
6771 NL80211_BSS_STATUS_IBSS_JOINED))
6772 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006773 break;
6774 default:
6775 break;
6776 }
6777
Johannes Berg2a519312009-02-10 21:25:55 +01006778 nla_nest_end(msg, bss);
6779
Johannes Berg053c0952015-01-16 22:09:00 +01006780 genlmsg_end(msg, hdr);
6781 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006782
Johannes Berg8cef2c92013-02-05 16:54:31 +01006783 fail_unlock_rcu:
6784 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006785 nla_put_failure:
6786 genlmsg_cancel(msg, hdr);
6787 return -EMSGSIZE;
6788}
6789
Johannes Berg97990a02013-04-19 01:02:55 +02006790static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006791{
Johannes Berg48ab9052009-07-10 18:42:31 +02006792 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006793 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006794 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006795 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006796 int err;
6797
Johannes Berg97990a02013-04-19 01:02:55 +02006798 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006799 if (err)
6800 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006801
Johannes Berg48ab9052009-07-10 18:42:31 +02006802 wdev_lock(wdev);
6803 spin_lock_bh(&rdev->bss_lock);
6804 cfg80211_bss_expire(rdev);
6805
Johannes Berg9720bb32011-06-21 09:45:33 +02006806 cb->seq = rdev->bss_generation;
6807
Johannes Berg48ab9052009-07-10 18:42:31 +02006808 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006809 if (++idx <= start)
6810 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006811 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006812 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006813 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006814 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006815 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006816 }
6817 }
6818
Johannes Berg48ab9052009-07-10 18:42:31 +02006819 spin_unlock_bh(&rdev->bss_lock);
6820 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006821
Johannes Berg97990a02013-04-19 01:02:55 +02006822 cb->args[2] = idx;
6823 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006824
Johannes Berg67748892010-10-04 21:14:06 +02006825 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006826}
6827
Eric W. Biederman15e47302012-09-07 20:12:54 +00006828static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006829 int flags, struct net_device *dev,
6830 bool allow_radio_stats,
6831 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006832{
6833 void *hdr;
6834 struct nlattr *infoattr;
6835
Johannes Berg11f78ac2014-11-14 16:43:50 +01006836 /* skip radio stats if userspace didn't request them */
6837 if (!survey->channel && !allow_radio_stats)
6838 return 0;
6839
Eric W. Biederman15e47302012-09-07 20:12:54 +00006840 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006841 NL80211_CMD_NEW_SURVEY_RESULTS);
6842 if (!hdr)
6843 return -ENOMEM;
6844
David S. Miller9360ffd2012-03-29 04:41:26 -04006845 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6846 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006847
6848 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6849 if (!infoattr)
6850 goto nla_put_failure;
6851
Johannes Berg11f78ac2014-11-14 16:43:50 +01006852 if (survey->channel &&
6853 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006854 survey->channel->center_freq))
6855 goto nla_put_failure;
6856
6857 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6858 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6859 goto nla_put_failure;
6860 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6861 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6862 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006863 if ((survey->filled & SURVEY_INFO_TIME) &&
6864 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6865 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006866 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006867 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6868 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6869 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006870 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006871 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6872 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6873 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006874 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006875 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6876 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6877 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006878 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006879 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6880 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6881 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006882 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006883 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6884 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6885 survey->time_scan))
6886 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006887
6888 nla_nest_end(msg, infoattr);
6889
Johannes Berg053c0952015-01-16 22:09:00 +01006890 genlmsg_end(msg, hdr);
6891 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006892
6893 nla_put_failure:
6894 genlmsg_cancel(msg, hdr);
6895 return -EMSGSIZE;
6896}
6897
Johannes Berg11f78ac2014-11-14 16:43:50 +01006898static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006899{
6900 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006901 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006902 struct wireless_dev *wdev;
6903 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006904 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006905 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006906
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006907 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006908 if (res)
6909 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006910
Johannes Berg11f78ac2014-11-14 16:43:50 +01006911 /* prepare_wdev_dump parsed the attributes */
6912 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6913
Johannes Berg97990a02013-04-19 01:02:55 +02006914 if (!wdev->netdev) {
6915 res = -EINVAL;
6916 goto out_err;
6917 }
6918
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006919 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006920 res = -EOPNOTSUPP;
6921 goto out_err;
6922 }
6923
6924 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006925 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006926 if (res == -ENOENT)
6927 break;
6928 if (res)
6929 goto out_err;
6930
Johannes Berg11f78ac2014-11-14 16:43:50 +01006931 /* don't send disabled channels, but do send non-channel data */
6932 if (survey.channel &&
6933 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006934 survey_idx++;
6935 continue;
6936 }
6937
Holger Schurig61fa7132009-11-11 12:25:40 +01006938 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006939 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006940 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006941 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006942 goto out;
6943 survey_idx++;
6944 }
6945
6946 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006947 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006948 res = skb->len;
6949 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006950 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006951 return res;
6952}
6953
Samuel Ortizb23aa672009-07-01 21:26:54 +02006954static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6955{
6956 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6957 NL80211_WPA_VERSION_2));
6958}
6959
Jouni Malinen636a5d32009-03-19 13:39:22 +02006960static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6961{
Johannes Berg4c476992010-10-04 21:36:35 +02006962 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6963 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006964 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006965 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6966 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006967 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006968 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006969 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006970
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006971 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6972 return -EINVAL;
6973
6974 if (!info->attrs[NL80211_ATTR_MAC])
6975 return -EINVAL;
6976
Jouni Malinen17780922009-03-27 20:52:47 +02006977 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6978 return -EINVAL;
6979
Johannes Berg19957bb2009-07-02 17:20:43 +02006980 if (!info->attrs[NL80211_ATTR_SSID])
6981 return -EINVAL;
6982
6983 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6984 return -EINVAL;
6985
Johannes Bergfffd0932009-07-08 14:22:54 +02006986 err = nl80211_parse_key(info, &key);
6987 if (err)
6988 return err;
6989
6990 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006991 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6992 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006993 if (!key.p.key || !key.p.key_len)
6994 return -EINVAL;
6995 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6996 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6997 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6998 key.p.key_len != WLAN_KEY_LEN_WEP104))
6999 return -EINVAL;
7000 if (key.idx > 4)
7001 return -EINVAL;
7002 } else {
7003 key.p.key_len = 0;
7004 key.p.key = NULL;
7005 }
7006
Johannes Bergafea0b72010-08-10 09:46:42 +02007007 if (key.idx >= 0) {
7008 int i;
7009 bool ok = false;
7010 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7011 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7012 ok = true;
7013 break;
7014 }
7015 }
Johannes Berg4c476992010-10-04 21:36:35 +02007016 if (!ok)
7017 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007018 }
7019
Johannes Berg4c476992010-10-04 21:36:35 +02007020 if (!rdev->ops->auth)
7021 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007022
Johannes Berg074ac8d2010-09-16 14:58:22 +02007023 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007024 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7025 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007026
Johannes Berg19957bb2009-07-02 17:20:43 +02007027 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007028 chan = nl80211_get_valid_chan(&rdev->wiphy,
7029 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7030 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007031 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007032
Johannes Berg19957bb2009-07-02 17:20:43 +02007033 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7034 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7035
7036 if (info->attrs[NL80211_ATTR_IE]) {
7037 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7038 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7039 }
7040
7041 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007042 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007043 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007044
Jouni Malinene39e5b52012-09-30 19:29:39 +03007045 if (auth_type == NL80211_AUTHTYPE_SAE &&
7046 !info->attrs[NL80211_ATTR_SAE_DATA])
7047 return -EINVAL;
7048
7049 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7050 if (auth_type != NL80211_AUTHTYPE_SAE)
7051 return -EINVAL;
7052 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7053 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7054 /* need to include at least Auth Transaction and Status Code */
7055 if (sae_data_len < 4)
7056 return -EINVAL;
7057 }
7058
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007059 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7060
Johannes Berg95de8172012-01-20 13:55:25 +01007061 /*
7062 * Since we no longer track auth state, ignore
7063 * requests to only change local state.
7064 */
7065 if (local_state_change)
7066 return 0;
7067
Johannes Berg91bf9b22013-05-15 17:44:01 +02007068 wdev_lock(dev->ieee80211_ptr);
7069 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7070 ssid, ssid_len, ie, ie_len,
7071 key.p.key, key.p.key_len, key.idx,
7072 sae_data, sae_data_len);
7073 wdev_unlock(dev->ieee80211_ptr);
7074 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007075}
7076
Johannes Bergc0692b82010-08-27 14:26:53 +03007077static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7078 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007079 struct cfg80211_crypto_settings *settings,
7080 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007081{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007082 memset(settings, 0, sizeof(*settings));
7083
Samuel Ortizb23aa672009-07-01 21:26:54 +02007084 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7085
Johannes Bergc0692b82010-08-27 14:26:53 +03007086 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7087 u16 proto;
7088 proto = nla_get_u16(
7089 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7090 settings->control_port_ethertype = cpu_to_be16(proto);
7091 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7092 proto != ETH_P_PAE)
7093 return -EINVAL;
7094 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7095 settings->control_port_no_encrypt = true;
7096 } else
7097 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7098
Samuel Ortizb23aa672009-07-01 21:26:54 +02007099 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7100 void *data;
7101 int len, i;
7102
7103 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7104 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7105 settings->n_ciphers_pairwise = len / sizeof(u32);
7106
7107 if (len % sizeof(u32))
7108 return -EINVAL;
7109
Johannes Berg3dc27d22009-07-02 21:36:37 +02007110 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007111 return -EINVAL;
7112
7113 memcpy(settings->ciphers_pairwise, data, len);
7114
7115 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007116 if (!cfg80211_supported_cipher_suite(
7117 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007118 settings->ciphers_pairwise[i]))
7119 return -EINVAL;
7120 }
7121
7122 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7123 settings->cipher_group =
7124 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007125 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7126 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007127 return -EINVAL;
7128 }
7129
7130 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7131 settings->wpa_versions =
7132 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7133 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7134 return -EINVAL;
7135 }
7136
7137 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7138 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007139 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007140
7141 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7142 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7143 settings->n_akm_suites = len / sizeof(u32);
7144
7145 if (len % sizeof(u32))
7146 return -EINVAL;
7147
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007148 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7149 return -EINVAL;
7150
Samuel Ortizb23aa672009-07-01 21:26:54 +02007151 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007152 }
7153
7154 return 0;
7155}
7156
Jouni Malinen636a5d32009-03-19 13:39:22 +02007157static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7158{
Johannes Berg4c476992010-10-04 21:36:35 +02007159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7160 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007161 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007162 struct cfg80211_assoc_request req = {};
7163 const u8 *bssid, *ssid;
7164 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007165
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007166 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7167 return -EINVAL;
7168
7169 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007170 !info->attrs[NL80211_ATTR_SSID] ||
7171 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007172 return -EINVAL;
7173
Johannes Berg4c476992010-10-04 21:36:35 +02007174 if (!rdev->ops->assoc)
7175 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007176
Johannes Berg074ac8d2010-09-16 14:58:22 +02007177 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007178 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7179 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007180
Johannes Berg19957bb2009-07-02 17:20:43 +02007181 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007182
Jouni Malinen664834d2014-01-15 00:01:44 +02007183 chan = nl80211_get_valid_chan(&rdev->wiphy,
7184 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7185 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007186 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007187
Johannes Berg19957bb2009-07-02 17:20:43 +02007188 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7189 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007190
7191 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007192 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7193 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007194 }
7195
Jouni Malinendc6382c2009-05-06 22:09:37 +03007196 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007197 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007198 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007199 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007200 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007201 else if (mfp != NL80211_MFP_NO)
7202 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007203 }
7204
Johannes Berg3e5d7642009-07-07 14:37:26 +02007205 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007206 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007207
Ben Greear7e7c8922011-11-18 11:31:59 -08007208 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007209 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007210
7211 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007212 memcpy(&req.ht_capa_mask,
7213 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7214 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007215
7216 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007217 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007218 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007219 memcpy(&req.ht_capa,
7220 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7221 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007222 }
7223
Johannes Bergee2aca32013-02-21 17:36:01 +01007224 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007225 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007226
7227 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007228 memcpy(&req.vht_capa_mask,
7229 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7230 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007231
7232 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007233 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007234 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007235 memcpy(&req.vht_capa,
7236 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7237 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007238 }
7239
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007240 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7241 if (!(rdev->wiphy.features &
7242 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7243 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7244 return -EINVAL;
7245 req.flags |= ASSOC_REQ_USE_RRM;
7246 }
7247
Johannes Bergf62fab72013-02-21 20:09:09 +01007248 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007249 if (!err) {
7250 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007251 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7252 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007253 wdev_unlock(dev->ieee80211_ptr);
7254 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007255
Jouni Malinen636a5d32009-03-19 13:39:22 +02007256 return err;
7257}
7258
7259static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7260{
Johannes Berg4c476992010-10-04 21:36:35 +02007261 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7262 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007263 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007264 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007265 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007266 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007267
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007268 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7269 return -EINVAL;
7270
7271 if (!info->attrs[NL80211_ATTR_MAC])
7272 return -EINVAL;
7273
7274 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7275 return -EINVAL;
7276
Johannes Berg4c476992010-10-04 21:36:35 +02007277 if (!rdev->ops->deauth)
7278 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007279
Johannes Berg074ac8d2010-09-16 14:58:22 +02007280 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007281 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7282 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007283
Johannes Berg19957bb2009-07-02 17:20:43 +02007284 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007285
Johannes Berg19957bb2009-07-02 17:20:43 +02007286 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7287 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007288 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007289 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007290 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007291
7292 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007293 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7294 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007295 }
7296
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007297 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7298
Johannes Berg91bf9b22013-05-15 17:44:01 +02007299 wdev_lock(dev->ieee80211_ptr);
7300 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7301 local_state_change);
7302 wdev_unlock(dev->ieee80211_ptr);
7303 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007304}
7305
7306static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7307{
Johannes Berg4c476992010-10-04 21:36:35 +02007308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7309 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007310 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007311 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007312 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007313 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007314
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007315 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7316 return -EINVAL;
7317
7318 if (!info->attrs[NL80211_ATTR_MAC])
7319 return -EINVAL;
7320
7321 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7322 return -EINVAL;
7323
Johannes Berg4c476992010-10-04 21:36:35 +02007324 if (!rdev->ops->disassoc)
7325 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007326
Johannes Berg074ac8d2010-09-16 14:58:22 +02007327 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007328 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7329 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007330
Johannes Berg19957bb2009-07-02 17:20:43 +02007331 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007332
Johannes Berg19957bb2009-07-02 17:20:43 +02007333 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7334 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007335 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007336 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007337 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007338
7339 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007340 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7341 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007342 }
7343
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007344 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7345
Johannes Berg91bf9b22013-05-15 17:44:01 +02007346 wdev_lock(dev->ieee80211_ptr);
7347 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7348 local_state_change);
7349 wdev_unlock(dev->ieee80211_ptr);
7350 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007351}
7352
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007353static bool
7354nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7355 int mcast_rate[IEEE80211_NUM_BANDS],
7356 int rateval)
7357{
7358 struct wiphy *wiphy = &rdev->wiphy;
7359 bool found = false;
7360 int band, i;
7361
7362 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7363 struct ieee80211_supported_band *sband;
7364
7365 sband = wiphy->bands[band];
7366 if (!sband)
7367 continue;
7368
7369 for (i = 0; i < sband->n_bitrates; i++) {
7370 if (sband->bitrates[i].bitrate == rateval) {
7371 mcast_rate[band] = i + 1;
7372 found = true;
7373 break;
7374 }
7375 }
7376 }
7377
7378 return found;
7379}
7380
Johannes Berg04a773a2009-04-19 21:24:32 +02007381static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7382{
Johannes Berg4c476992010-10-04 21:36:35 +02007383 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7384 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007385 struct cfg80211_ibss_params ibss;
7386 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007387 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007388 int err;
7389
Johannes Berg8e30bc52009-04-22 17:45:38 +02007390 memset(&ibss, 0, sizeof(ibss));
7391
Johannes Berg04a773a2009-04-19 21:24:32 +02007392 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7393 return -EINVAL;
7394
Johannes Berg683b6d32012-11-08 21:25:48 +01007395 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007396 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7397 return -EINVAL;
7398
Johannes Berg8e30bc52009-04-22 17:45:38 +02007399 ibss.beacon_interval = 100;
7400
7401 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7402 ibss.beacon_interval =
7403 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7404 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7405 return -EINVAL;
7406 }
7407
Johannes Berg4c476992010-10-04 21:36:35 +02007408 if (!rdev->ops->join_ibss)
7409 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007410
Johannes Berg4c476992010-10-04 21:36:35 +02007411 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7412 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007413
Johannes Berg79c97e92009-07-07 03:56:12 +02007414 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007415
Johannes Berg39193492011-09-16 13:45:25 +02007416 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007417 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007418
7419 if (!is_valid_ether_addr(ibss.bssid))
7420 return -EINVAL;
7421 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007422 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7423 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7424
7425 if (info->attrs[NL80211_ATTR_IE]) {
7426 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7427 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7428 }
7429
Johannes Berg683b6d32012-11-08 21:25:48 +01007430 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7431 if (err)
7432 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007433
Ilan Peer174e0cd2014-02-23 09:13:01 +02007434 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7435 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007436 return -EINVAL;
7437
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007438 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007439 case NL80211_CHAN_WIDTH_5:
7440 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007441 case NL80211_CHAN_WIDTH_20_NOHT:
7442 break;
7443 case NL80211_CHAN_WIDTH_20:
7444 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007445 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7446 return -EINVAL;
7447 break;
7448 case NL80211_CHAN_WIDTH_80:
7449 case NL80211_CHAN_WIDTH_80P80:
7450 case NL80211_CHAN_WIDTH_160:
7451 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7452 return -EINVAL;
7453 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7454 NL80211_EXT_FEATURE_VHT_IBSS))
7455 return -EINVAL;
7456 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007457 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007458 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007459 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007460
Johannes Berg04a773a2009-04-19 21:24:32 +02007461 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007462 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007463
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007464 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7465 u8 *rates =
7466 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7467 int n_rates =
7468 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7469 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007470 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007471
Johannes Berg34850ab2011-07-18 18:08:35 +02007472 err = ieee80211_get_ratemask(sband, rates, n_rates,
7473 &ibss.basic_rates);
7474 if (err)
7475 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007476 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007477
Simon Wunderlich803768f2013-06-28 10:39:58 +02007478 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7479 memcpy(&ibss.ht_capa_mask,
7480 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7481 sizeof(ibss.ht_capa_mask));
7482
7483 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7484 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7485 return -EINVAL;
7486 memcpy(&ibss.ht_capa,
7487 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7488 sizeof(ibss.ht_capa));
7489 }
7490
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007491 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7492 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7493 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7494 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007495
Johannes Berg4c476992010-10-04 21:36:35 +02007496 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307497 bool no_ht = false;
7498
Johannes Berg4c476992010-10-04 21:36:35 +02007499 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307500 info->attrs[NL80211_ATTR_KEYS],
7501 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007502 if (IS_ERR(connkeys))
7503 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307504
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007505 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7506 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307507 kfree(connkeys);
7508 return -EINVAL;
7509 }
Johannes Berg4c476992010-10-04 21:36:35 +02007510 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007511
Antonio Quartulli267335d2012-01-31 20:25:47 +01007512 ibss.control_port =
7513 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7514
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007515 ibss.userspace_handles_dfs =
7516 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7517
Johannes Berg4c476992010-10-04 21:36:35 +02007518 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007519 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007520 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007521 return err;
7522}
7523
7524static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7525{
Johannes Berg4c476992010-10-04 21:36:35 +02007526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7527 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007528
Johannes Berg4c476992010-10-04 21:36:35 +02007529 if (!rdev->ops->leave_ibss)
7530 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007531
Johannes Berg4c476992010-10-04 21:36:35 +02007532 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7533 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007534
Johannes Berg4c476992010-10-04 21:36:35 +02007535 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007536}
7537
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007538static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7539{
7540 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7541 struct net_device *dev = info->user_ptr[1];
7542 int mcast_rate[IEEE80211_NUM_BANDS];
7543 u32 nla_rate;
7544 int err;
7545
7546 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007547 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7548 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007549 return -EOPNOTSUPP;
7550
7551 if (!rdev->ops->set_mcast_rate)
7552 return -EOPNOTSUPP;
7553
7554 memset(mcast_rate, 0, sizeof(mcast_rate));
7555
7556 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7557 return -EINVAL;
7558
7559 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7560 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7561 return -EINVAL;
7562
7563 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7564
7565 return err;
7566}
7567
Johannes Bergad7e7182013-11-13 13:37:47 +01007568static struct sk_buff *
7569__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007570 struct wireless_dev *wdev, int approxlen,
7571 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007572 enum nl80211_attrs attr,
7573 const struct nl80211_vendor_cmd_info *info,
7574 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007575{
7576 struct sk_buff *skb;
7577 void *hdr;
7578 struct nlattr *data;
7579
7580 skb = nlmsg_new(approxlen + 100, gfp);
7581 if (!skb)
7582 return NULL;
7583
7584 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7585 if (!hdr) {
7586 kfree_skb(skb);
7587 return NULL;
7588 }
7589
7590 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7591 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007592
7593 if (info) {
7594 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7595 info->vendor_id))
7596 goto nla_put_failure;
7597 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7598 info->subcmd))
7599 goto nla_put_failure;
7600 }
7601
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007602 if (wdev) {
7603 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7604 wdev_id(wdev)))
7605 goto nla_put_failure;
7606 if (wdev->netdev &&
7607 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7608 wdev->netdev->ifindex))
7609 goto nla_put_failure;
7610 }
7611
Johannes Bergad7e7182013-11-13 13:37:47 +01007612 data = nla_nest_start(skb, attr);
7613
7614 ((void **)skb->cb)[0] = rdev;
7615 ((void **)skb->cb)[1] = hdr;
7616 ((void **)skb->cb)[2] = data;
7617
7618 return skb;
7619
7620 nla_put_failure:
7621 kfree_skb(skb);
7622 return NULL;
7623}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007624
Johannes Berge03ad6e2014-01-01 17:22:30 +01007625struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007626 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007627 enum nl80211_commands cmd,
7628 enum nl80211_attrs attr,
7629 int vendor_event_idx,
7630 int approxlen, gfp_t gfp)
7631{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007632 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007633 const struct nl80211_vendor_cmd_info *info;
7634
7635 switch (cmd) {
7636 case NL80211_CMD_TESTMODE:
7637 if (WARN_ON(vendor_event_idx != -1))
7638 return NULL;
7639 info = NULL;
7640 break;
7641 case NL80211_CMD_VENDOR:
7642 if (WARN_ON(vendor_event_idx < 0 ||
7643 vendor_event_idx >= wiphy->n_vendor_events))
7644 return NULL;
7645 info = &wiphy->vendor_events[vendor_event_idx];
7646 break;
7647 default:
7648 WARN_ON(1);
7649 return NULL;
7650 }
7651
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007652 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007653 cmd, attr, info, gfp);
7654}
7655EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7656
7657void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7658{
7659 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7660 void *hdr = ((void **)skb->cb)[1];
7661 struct nlattr *data = ((void **)skb->cb)[2];
7662 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7663
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007664 /* clear CB data for netlink core to own from now on */
7665 memset(skb->cb, 0, sizeof(skb->cb));
7666
Johannes Berge03ad6e2014-01-01 17:22:30 +01007667 nla_nest_end(skb, data);
7668 genlmsg_end(skb, hdr);
7669
7670 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7671 mcgrp = NL80211_MCGRP_VENDOR;
7672
7673 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7674 mcgrp, gfp);
7675}
7676EXPORT_SYMBOL(__cfg80211_send_event_skb);
7677
Johannes Bergaff89a92009-07-01 21:26:51 +02007678#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007679static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7680{
Johannes Berg4c476992010-10-04 21:36:35 +02007681 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007682 struct wireless_dev *wdev =
7683 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007684 int err;
7685
David Spinadelfc73f112013-07-31 18:04:15 +03007686 if (!rdev->ops->testmode_cmd)
7687 return -EOPNOTSUPP;
7688
7689 if (IS_ERR(wdev)) {
7690 err = PTR_ERR(wdev);
7691 if (err != -EINVAL)
7692 return err;
7693 wdev = NULL;
7694 } else if (wdev->wiphy != &rdev->wiphy) {
7695 return -EINVAL;
7696 }
7697
Johannes Bergaff89a92009-07-01 21:26:51 +02007698 if (!info->attrs[NL80211_ATTR_TESTDATA])
7699 return -EINVAL;
7700
Johannes Bergad7e7182013-11-13 13:37:47 +01007701 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007702 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007703 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7704 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007705 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007706
Johannes Bergaff89a92009-07-01 21:26:51 +02007707 return err;
7708}
7709
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007710static int nl80211_testmode_dump(struct sk_buff *skb,
7711 struct netlink_callback *cb)
7712{
Johannes Berg00918d32011-12-13 17:22:05 +01007713 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007714 int err;
7715 long phy_idx;
7716 void *data = NULL;
7717 int data_len = 0;
7718
Johannes Berg5fe231e2013-05-08 21:45:15 +02007719 rtnl_lock();
7720
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007721 if (cb->args[0]) {
7722 /*
7723 * 0 is a valid index, but not valid for args[0],
7724 * so we need to offset by 1.
7725 */
7726 phy_idx = cb->args[0] - 1;
7727 } else {
7728 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7729 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7730 nl80211_policy);
7731 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007732 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007733
Johannes Berg2bd7e352012-06-15 14:23:16 +02007734 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7735 nl80211_fam.attrbuf);
7736 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007737 err = PTR_ERR(rdev);
7738 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007739 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007740 phy_idx = rdev->wiphy_idx;
7741 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007742
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007743 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7744 cb->args[1] =
7745 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7746 }
7747
7748 if (cb->args[1]) {
7749 data = nla_data((void *)cb->args[1]);
7750 data_len = nla_len((void *)cb->args[1]);
7751 }
7752
Johannes Berg00918d32011-12-13 17:22:05 +01007753 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7754 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007755 err = -ENOENT;
7756 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007757 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007758
Johannes Berg00918d32011-12-13 17:22:05 +01007759 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007760 err = -EOPNOTSUPP;
7761 goto out_err;
7762 }
7763
7764 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007765 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007766 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7767 NL80211_CMD_TESTMODE);
7768 struct nlattr *tmdata;
7769
Dan Carpentercb35fba2013-08-14 14:50:01 +03007770 if (!hdr)
7771 break;
7772
David S. Miller9360ffd2012-03-29 04:41:26 -04007773 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007774 genlmsg_cancel(skb, hdr);
7775 break;
7776 }
7777
7778 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7779 if (!tmdata) {
7780 genlmsg_cancel(skb, hdr);
7781 break;
7782 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007783 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007784 nla_nest_end(skb, tmdata);
7785
7786 if (err == -ENOBUFS || err == -ENOENT) {
7787 genlmsg_cancel(skb, hdr);
7788 break;
7789 } else if (err) {
7790 genlmsg_cancel(skb, hdr);
7791 goto out_err;
7792 }
7793
7794 genlmsg_end(skb, hdr);
7795 }
7796
7797 err = skb->len;
7798 /* see above */
7799 cb->args[0] = phy_idx + 1;
7800 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007801 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007802 return err;
7803}
Johannes Bergaff89a92009-07-01 21:26:51 +02007804#endif
7805
Samuel Ortizb23aa672009-07-01 21:26:54 +02007806static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7807{
Johannes Berg4c476992010-10-04 21:36:35 +02007808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7809 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007810 struct cfg80211_connect_params connect;
7811 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007812 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007813 int err;
7814
7815 memset(&connect, 0, sizeof(connect));
7816
7817 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7818 return -EINVAL;
7819
7820 if (!info->attrs[NL80211_ATTR_SSID] ||
7821 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7822 return -EINVAL;
7823
7824 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7825 connect.auth_type =
7826 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007827 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7828 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007829 return -EINVAL;
7830 } else
7831 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7832
7833 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7834
Johannes Bergc0692b82010-08-27 14:26:53 +03007835 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007836 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007837 if (err)
7838 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007839
Johannes Berg074ac8d2010-09-16 14:58:22 +02007840 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007841 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7842 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007843
Johannes Berg79c97e92009-07-07 03:56:12 +02007844 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007845
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307846 connect.bg_scan_period = -1;
7847 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7848 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7849 connect.bg_scan_period =
7850 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7851 }
7852
Samuel Ortizb23aa672009-07-01 21:26:54 +02007853 if (info->attrs[NL80211_ATTR_MAC])
7854 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007855 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7856 connect.bssid_hint =
7857 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007858 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7859 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7860
7861 if (info->attrs[NL80211_ATTR_IE]) {
7862 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7863 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7864 }
7865
Jouni Malinencee00a92013-01-15 17:15:57 +02007866 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7867 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7868 if (connect.mfp != NL80211_MFP_REQUIRED &&
7869 connect.mfp != NL80211_MFP_NO)
7870 return -EINVAL;
7871 } else {
7872 connect.mfp = NL80211_MFP_NO;
7873 }
7874
Samuel Ortizb23aa672009-07-01 21:26:54 +02007875 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007876 connect.channel = nl80211_get_valid_chan(
7877 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7878 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007879 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007880 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007881 connect.channel_hint = nl80211_get_valid_chan(
7882 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7883 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007884 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007885 }
7886
Johannes Bergfffd0932009-07-08 14:22:54 +02007887 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7888 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307889 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007890 if (IS_ERR(connkeys))
7891 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007892 }
7893
Ben Greear7e7c8922011-11-18 11:31:59 -08007894 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7895 connect.flags |= ASSOC_REQ_DISABLE_HT;
7896
7897 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7898 memcpy(&connect.ht_capa_mask,
7899 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7900 sizeof(connect.ht_capa_mask));
7901
7902 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007903 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007904 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007905 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007906 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007907 memcpy(&connect.ht_capa,
7908 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7909 sizeof(connect.ht_capa));
7910 }
7911
Johannes Bergee2aca32013-02-21 17:36:01 +01007912 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7913 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7914
7915 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7916 memcpy(&connect.vht_capa_mask,
7917 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7918 sizeof(connect.vht_capa_mask));
7919
7920 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7921 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007922 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007923 return -EINVAL;
7924 }
7925 memcpy(&connect.vht_capa,
7926 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7927 sizeof(connect.vht_capa));
7928 }
7929
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007930 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7931 if (!(rdev->wiphy.features &
7932 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7933 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7934 return -EINVAL;
7935 connect.flags |= ASSOC_REQ_USE_RRM;
7936 }
7937
Johannes Berg83739b02013-05-15 17:44:01 +02007938 wdev_lock(dev->ieee80211_ptr);
7939 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7940 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007941 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007942 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007943 return err;
7944}
7945
7946static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7947{
Johannes Berg4c476992010-10-04 21:36:35 +02007948 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7949 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007950 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007951 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007952
7953 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7954 reason = WLAN_REASON_DEAUTH_LEAVING;
7955 else
7956 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7957
7958 if (reason == 0)
7959 return -EINVAL;
7960
Johannes Berg074ac8d2010-09-16 14:58:22 +02007961 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007962 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7963 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007964
Johannes Berg83739b02013-05-15 17:44:01 +02007965 wdev_lock(dev->ieee80211_ptr);
7966 ret = cfg80211_disconnect(rdev, dev, reason, true);
7967 wdev_unlock(dev->ieee80211_ptr);
7968 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007969}
7970
Johannes Berg463d0182009-07-14 00:33:35 +02007971static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7972{
Johannes Berg4c476992010-10-04 21:36:35 +02007973 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007974 struct net *net;
7975 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007976
Vadim Kochan4b681c82015-01-12 16:34:05 +02007977 if (info->attrs[NL80211_ATTR_PID]) {
7978 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7979
7980 net = get_net_ns_by_pid(pid);
7981 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7982 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7983
7984 net = get_net_ns_by_fd(fd);
7985 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007986 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007987 }
Johannes Berg463d0182009-07-14 00:33:35 +02007988
Johannes Berg4c476992010-10-04 21:36:35 +02007989 if (IS_ERR(net))
7990 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007991
7992 err = 0;
7993
7994 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007995 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7996 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007997
Johannes Berg463d0182009-07-14 00:33:35 +02007998 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007999 return err;
8000}
8001
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008002static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8003{
Johannes Berg4c476992010-10-04 21:36:35 +02008004 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008005 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8006 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008007 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008008 struct cfg80211_pmksa pmksa;
8009
8010 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8011
8012 if (!info->attrs[NL80211_ATTR_MAC])
8013 return -EINVAL;
8014
8015 if (!info->attrs[NL80211_ATTR_PMKID])
8016 return -EINVAL;
8017
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008018 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8019 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
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 Ortiz67fbb162009-11-24 23:59:15 +01008024
8025 switch (info->genlhdr->cmd) {
8026 case NL80211_CMD_SET_PMKSA:
8027 rdev_ops = rdev->ops->set_pmksa;
8028 break;
8029 case NL80211_CMD_DEL_PMKSA:
8030 rdev_ops = rdev->ops->del_pmksa;
8031 break;
8032 default:
8033 WARN_ON(1);
8034 break;
8035 }
8036
Johannes Berg4c476992010-10-04 21:36:35 +02008037 if (!rdev_ops)
8038 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008039
Johannes Berg4c476992010-10-04 21:36:35 +02008040 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008041}
8042
8043static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8044{
Johannes Berg4c476992010-10-04 21:36:35 +02008045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8046 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008047
Johannes Berg074ac8d2010-09-16 14:58:22 +02008048 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008049 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8050 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008051
Johannes Berg4c476992010-10-04 21:36:35 +02008052 if (!rdev->ops->flush_pmksa)
8053 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008054
Hila Gonene35e4d22012-06-27 17:19:42 +03008055 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008056}
8057
Arik Nemtsov109086c2011-09-28 14:12:50 +03008058static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8059{
8060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8061 struct net_device *dev = info->user_ptr[1];
8062 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308063 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008064 u16 status_code;
8065 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008066 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008067
8068 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8069 !rdev->ops->tdls_mgmt)
8070 return -EOPNOTSUPP;
8071
8072 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8073 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8074 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8075 !info->attrs[NL80211_ATTR_IE] ||
8076 !info->attrs[NL80211_ATTR_MAC])
8077 return -EINVAL;
8078
8079 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8080 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8081 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8082 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008083 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308084 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8085 peer_capability =
8086 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008087
Hila Gonene35e4d22012-06-27 17:19:42 +03008088 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308089 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008090 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008091 nla_data(info->attrs[NL80211_ATTR_IE]),
8092 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008093}
8094
8095static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8096{
8097 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8098 struct net_device *dev = info->user_ptr[1];
8099 enum nl80211_tdls_operation operation;
8100 u8 *peer;
8101
8102 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8103 !rdev->ops->tdls_oper)
8104 return -EOPNOTSUPP;
8105
8106 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8107 !info->attrs[NL80211_ATTR_MAC])
8108 return -EINVAL;
8109
8110 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8111 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8112
Hila Gonene35e4d22012-06-27 17:19:42 +03008113 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008114}
8115
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008116static int nl80211_remain_on_channel(struct sk_buff *skb,
8117 struct genl_info *info)
8118{
Johannes Berg4c476992010-10-04 21:36:35 +02008119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008120 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008121 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008122 struct sk_buff *msg;
8123 void *hdr;
8124 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008125 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008126 int err;
8127
8128 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8129 !info->attrs[NL80211_ATTR_DURATION])
8130 return -EINVAL;
8131
8132 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8133
Johannes Berg7c4ef712011-11-18 15:33:48 +01008134 if (!rdev->ops->remain_on_channel ||
8135 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008136 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008137
Johannes Bergebf348f2012-06-01 12:50:54 +02008138 /*
8139 * We should be on that channel for at least a minimum amount of
8140 * time (10ms) but no longer than the driver supports.
8141 */
8142 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8143 duration > rdev->wiphy.max_remain_on_channel_duration)
8144 return -EINVAL;
8145
Johannes Berg683b6d32012-11-08 21:25:48 +01008146 err = nl80211_parse_chandef(rdev, info, &chandef);
8147 if (err)
8148 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008149
8150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008151 if (!msg)
8152 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008153
Eric W. Biederman15e47302012-09-07 20:12:54 +00008154 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008155 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008156 if (!hdr) {
8157 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008158 goto free_msg;
8159 }
8160
Johannes Berg683b6d32012-11-08 21:25:48 +01008161 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8162 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008163
8164 if (err)
8165 goto free_msg;
8166
David S. Miller9360ffd2012-03-29 04:41:26 -04008167 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8168 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008169
8170 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008171
8172 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008173
8174 nla_put_failure:
8175 err = -ENOBUFS;
8176 free_msg:
8177 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008178 return err;
8179}
8180
8181static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8182 struct genl_info *info)
8183{
Johannes Berg4c476992010-10-04 21:36:35 +02008184 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008185 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008186 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008187
8188 if (!info->attrs[NL80211_ATTR_COOKIE])
8189 return -EINVAL;
8190
Johannes Berg4c476992010-10-04 21:36:35 +02008191 if (!rdev->ops->cancel_remain_on_channel)
8192 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008193
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008194 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8195
Hila Gonene35e4d22012-06-27 17:19:42 +03008196 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008197}
8198
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008199static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8200 u8 *rates, u8 rates_len)
8201{
8202 u8 i;
8203 u32 mask = 0;
8204
8205 for (i = 0; i < rates_len; i++) {
8206 int rate = (rates[i] & 0x7f) * 5;
8207 int ridx;
8208 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8209 struct ieee80211_rate *srate =
8210 &sband->bitrates[ridx];
8211 if (rate == srate->bitrate) {
8212 mask |= 1 << ridx;
8213 break;
8214 }
8215 }
8216 if (ridx == sband->n_bitrates)
8217 return 0; /* rate not found */
8218 }
8219
8220 return mask;
8221}
8222
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008223static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8224 u8 *rates, u8 rates_len,
8225 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8226{
8227 u8 i;
8228
8229 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8230
8231 for (i = 0; i < rates_len; i++) {
8232 int ridx, rbit;
8233
8234 ridx = rates[i] / 8;
8235 rbit = BIT(rates[i] % 8);
8236
8237 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008238 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008239 return false;
8240
8241 /* check availability */
8242 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8243 mcs[ridx] |= rbit;
8244 else
8245 return false;
8246 }
8247
8248 return true;
8249}
8250
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008251static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8252{
8253 u16 mcs_mask = 0;
8254
8255 switch (vht_mcs_map) {
8256 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8257 break;
8258 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8259 mcs_mask = 0x00FF;
8260 break;
8261 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8262 mcs_mask = 0x01FF;
8263 break;
8264 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8265 mcs_mask = 0x03FF;
8266 break;
8267 default:
8268 break;
8269 }
8270
8271 return mcs_mask;
8272}
8273
8274static void vht_build_mcs_mask(u16 vht_mcs_map,
8275 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8276{
8277 u8 nss;
8278
8279 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8280 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8281 vht_mcs_map >>= 2;
8282 }
8283}
8284
8285static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8286 struct nl80211_txrate_vht *txrate,
8287 u16 mcs[NL80211_VHT_NSS_MAX])
8288{
8289 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8290 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8291 u8 i;
8292
8293 if (!sband->vht_cap.vht_supported)
8294 return false;
8295
8296 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8297
8298 /* Build vht_mcs_mask from VHT capabilities */
8299 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8300
8301 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8302 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8303 mcs[i] = txrate->mcs[i];
8304 else
8305 return false;
8306 }
8307
8308 return true;
8309}
8310
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008311static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008312 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8313 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008314 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8315 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008316 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008317 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008318};
8319
8320static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8321 struct genl_info *info)
8322{
8323 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008324 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008325 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008326 int rem, i;
8327 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008328 struct nlattr *tx_rates;
8329 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008330 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008331
Johannes Berg4c476992010-10-04 21:36:35 +02008332 if (!rdev->ops->set_bitrate_mask)
8333 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008334
8335 memset(&mask, 0, sizeof(mask));
8336 /* Default to all rates enabled */
8337 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8338 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008339
8340 if (!sband)
8341 continue;
8342
8343 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008344 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008345 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008346 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008347
8348 if (!sband->vht_cap.vht_supported)
8349 continue;
8350
8351 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8352 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008353 }
8354
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008355 /* if no rates are given set it back to the defaults */
8356 if (!info->attrs[NL80211_ATTR_TX_RATES])
8357 goto out;
8358
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008359 /*
8360 * The nested attribute uses enum nl80211_band as the index. This maps
8361 * directly to the enum ieee80211_band values used in cfg80211.
8362 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008363 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008364 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008365 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008366 int err;
8367
Johannes Berg4c476992010-10-04 21:36:35 +02008368 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8369 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008370 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008371 if (sband == NULL)
8372 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008373 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8374 nla_len(tx_rates), nl80211_txattr_policy);
8375 if (err)
8376 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008377 if (tb[NL80211_TXRATE_LEGACY]) {
8378 mask.control[band].legacy = rateset_to_mask(
8379 sband,
8380 nla_data(tb[NL80211_TXRATE_LEGACY]),
8381 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308382 if ((mask.control[band].legacy == 0) &&
8383 nla_len(tb[NL80211_TXRATE_LEGACY]))
8384 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008385 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008386 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008387 if (!ht_rateset_to_mask(
8388 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008389 nla_data(tb[NL80211_TXRATE_HT]),
8390 nla_len(tb[NL80211_TXRATE_HT]),
8391 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008392 return -EINVAL;
8393 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008394 if (tb[NL80211_TXRATE_VHT]) {
8395 if (!vht_set_mcs_mask(
8396 sband,
8397 nla_data(tb[NL80211_TXRATE_VHT]),
8398 mask.control[band].vht_mcs))
8399 return -EINVAL;
8400 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008401 if (tb[NL80211_TXRATE_GI]) {
8402 mask.control[band].gi =
8403 nla_get_u8(tb[NL80211_TXRATE_GI]);
8404 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8405 return -EINVAL;
8406 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008407
8408 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008409 /* don't allow empty legacy rates if HT or VHT
8410 * are not even supported.
8411 */
8412 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8413 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008414 return -EINVAL;
8415
8416 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008417 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008418 goto out;
8419
8420 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8421 if (mask.control[band].vht_mcs[i])
8422 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008423
8424 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008425 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008426 }
8427 }
8428
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008429out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008430 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008431}
8432
Johannes Berg2e161f72010-08-12 15:38:38 +02008433static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008434{
Johannes Berg4c476992010-10-04 21:36:35 +02008435 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008436 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008437 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008438
8439 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8440 return -EINVAL;
8441
Johannes Berg2e161f72010-08-12 15:38:38 +02008442 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8443 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008444
Johannes Berg71bbc992012-06-15 15:30:18 +02008445 switch (wdev->iftype) {
8446 case NL80211_IFTYPE_STATION:
8447 case NL80211_IFTYPE_ADHOC:
8448 case NL80211_IFTYPE_P2P_CLIENT:
8449 case NL80211_IFTYPE_AP:
8450 case NL80211_IFTYPE_AP_VLAN:
8451 case NL80211_IFTYPE_MESH_POINT:
8452 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008453 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008454 break;
8455 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008456 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008457 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008458
8459 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008460 if (!rdev->ops->mgmt_tx)
8461 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008462
Eric W. Biederman15e47302012-09-07 20:12:54 +00008463 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008464 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8465 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008466}
8467
Johannes Berg2e161f72010-08-12 15:38:38 +02008468static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008469{
Johannes Berg4c476992010-10-04 21:36:35 +02008470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008471 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008472 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008473 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008474 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008475 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008476 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008477 struct cfg80211_mgmt_tx_params params = {
8478 .dont_wait_for_ack =
8479 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8480 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008481
Johannes Berg683b6d32012-11-08 21:25:48 +01008482 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008483 return -EINVAL;
8484
Johannes Berg4c476992010-10-04 21:36:35 +02008485 if (!rdev->ops->mgmt_tx)
8486 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008487
Johannes Berg71bbc992012-06-15 15:30:18 +02008488 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008489 case NL80211_IFTYPE_P2P_DEVICE:
8490 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8491 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008492 case NL80211_IFTYPE_STATION:
8493 case NL80211_IFTYPE_ADHOC:
8494 case NL80211_IFTYPE_P2P_CLIENT:
8495 case NL80211_IFTYPE_AP:
8496 case NL80211_IFTYPE_AP_VLAN:
8497 case NL80211_IFTYPE_MESH_POINT:
8498 case NL80211_IFTYPE_P2P_GO:
8499 break;
8500 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008501 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008502 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008503
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008504 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008505 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008506 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008507 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008508
8509 /*
8510 * We should wait on the channel for at least a minimum amount
8511 * of time (10ms) but no longer than the driver supports.
8512 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008513 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8514 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008515 return -EINVAL;
8516
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008517 }
8518
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008519 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008520
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008521 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008522 return -EINVAL;
8523
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008524 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308525
Antonio Quartulliea141b752013-06-11 14:20:03 +02008526 /* get the channel if any has been specified, otherwise pass NULL to
8527 * the driver. The latter will use the current one
8528 */
8529 chandef.chan = NULL;
8530 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8531 err = nl80211_parse_chandef(rdev, info, &chandef);
8532 if (err)
8533 return err;
8534 }
8535
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008536 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008537 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008538
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008539 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8540 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8541
8542 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8543 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8544 int i;
8545
8546 if (len % sizeof(u16))
8547 return -EINVAL;
8548
8549 params.n_csa_offsets = len / sizeof(u16);
8550 params.csa_offsets =
8551 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8552
8553 /* check that all the offsets fit the frame */
8554 for (i = 0; i < params.n_csa_offsets; i++) {
8555 if (params.csa_offsets[i] >= params.len)
8556 return -EINVAL;
8557 }
8558 }
8559
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008560 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008561 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8562 if (!msg)
8563 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008564
Eric W. Biederman15e47302012-09-07 20:12:54 +00008565 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008566 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008567 if (!hdr) {
8568 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008569 goto free_msg;
8570 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008571 }
Johannes Berge247bd902011-11-04 11:18:21 +01008572
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008573 params.chan = chandef.chan;
8574 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008575 if (err)
8576 goto free_msg;
8577
Johannes Berge247bd902011-11-04 11:18:21 +01008578 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008579 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8580 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008581
Johannes Berge247bd902011-11-04 11:18:21 +01008582 genlmsg_end(msg, hdr);
8583 return genlmsg_reply(msg, info);
8584 }
8585
8586 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008587
8588 nla_put_failure:
8589 err = -ENOBUFS;
8590 free_msg:
8591 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008592 return err;
8593}
8594
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008595static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8596{
8597 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008598 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008599 u64 cookie;
8600
8601 if (!info->attrs[NL80211_ATTR_COOKIE])
8602 return -EINVAL;
8603
8604 if (!rdev->ops->mgmt_tx_cancel_wait)
8605 return -EOPNOTSUPP;
8606
Johannes Berg71bbc992012-06-15 15:30:18 +02008607 switch (wdev->iftype) {
8608 case NL80211_IFTYPE_STATION:
8609 case NL80211_IFTYPE_ADHOC:
8610 case NL80211_IFTYPE_P2P_CLIENT:
8611 case NL80211_IFTYPE_AP:
8612 case NL80211_IFTYPE_AP_VLAN:
8613 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008614 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008615 break;
8616 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008617 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008618 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008619
8620 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8621
Hila Gonene35e4d22012-06-27 17:19:42 +03008622 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008623}
8624
Kalle Valoffb9eb32010-02-17 17:58:10 +02008625static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8626{
Johannes Berg4c476992010-10-04 21:36:35 +02008627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008628 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008629 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008630 u8 ps_state;
8631 bool state;
8632 int err;
8633
Johannes Berg4c476992010-10-04 21:36:35 +02008634 if (!info->attrs[NL80211_ATTR_PS_STATE])
8635 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008636
8637 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8638
Johannes Berg4c476992010-10-04 21:36:35 +02008639 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8640 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008641
8642 wdev = dev->ieee80211_ptr;
8643
Johannes Berg4c476992010-10-04 21:36:35 +02008644 if (!rdev->ops->set_power_mgmt)
8645 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008646
8647 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8648
8649 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008650 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008651
Hila Gonene35e4d22012-06-27 17:19:42 +03008652 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008653 if (!err)
8654 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008655 return err;
8656}
8657
8658static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8659{
Johannes Berg4c476992010-10-04 21:36:35 +02008660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008661 enum nl80211_ps_state ps_state;
8662 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008663 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008664 struct sk_buff *msg;
8665 void *hdr;
8666 int err;
8667
Kalle Valoffb9eb32010-02-17 17:58:10 +02008668 wdev = dev->ieee80211_ptr;
8669
Johannes Berg4c476992010-10-04 21:36:35 +02008670 if (!rdev->ops->set_power_mgmt)
8671 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008672
8673 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008674 if (!msg)
8675 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008676
Eric W. Biederman15e47302012-09-07 20:12:54 +00008677 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008678 NL80211_CMD_GET_POWER_SAVE);
8679 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008680 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008681 goto free_msg;
8682 }
8683
8684 if (wdev->ps)
8685 ps_state = NL80211_PS_ENABLED;
8686 else
8687 ps_state = NL80211_PS_DISABLED;
8688
David S. Miller9360ffd2012-03-29 04:41:26 -04008689 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8690 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008691
8692 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008693 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008694
Johannes Berg4c476992010-10-04 21:36:35 +02008695 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008696 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008697 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008698 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008699 return err;
8700}
8701
Johannes Berg94e860f2014-01-20 23:58:15 +01008702static const struct nla_policy
8703nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008704 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8705 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8706 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008707 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8708 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8709 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008710};
8711
Thomas Pedersen84f10702012-07-12 16:17:33 -07008712static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008713 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008714{
8715 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008716 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008717 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008718
Johannes Bergd9d8b012012-11-26 12:51:52 +01008719 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008720 return -EINVAL;
8721
Thomas Pedersen84f10702012-07-12 16:17:33 -07008722 if (!rdev->ops->set_cqm_txe_config)
8723 return -EOPNOTSUPP;
8724
8725 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8726 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8727 return -EOPNOTSUPP;
8728
Hila Gonene35e4d22012-06-27 17:19:42 +03008729 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008730}
8731
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008732static int nl80211_set_cqm_rssi(struct genl_info *info,
8733 s32 threshold, u32 hysteresis)
8734{
Johannes Berg4c476992010-10-04 21:36:35 +02008735 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008736 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008737 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008738
8739 if (threshold > 0)
8740 return -EINVAL;
8741
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008742 /* disabling - hysteresis should also be zero then */
8743 if (threshold == 0)
8744 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008745
Johannes Berg4c476992010-10-04 21:36:35 +02008746 if (!rdev->ops->set_cqm_rssi_config)
8747 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008748
Johannes Berg074ac8d2010-09-16 14:58:22 +02008749 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008750 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8751 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008752
Hila Gonene35e4d22012-06-27 17:19:42 +03008753 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008754}
8755
8756static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8757{
8758 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8759 struct nlattr *cqm;
8760 int err;
8761
8762 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008763 if (!cqm)
8764 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008765
8766 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8767 nl80211_attr_cqm_policy);
8768 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008769 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008770
8771 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8772 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008773 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8774 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008775
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008776 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8777 }
8778
8779 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8780 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8781 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8782 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8783 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8784 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8785
8786 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8787 }
8788
8789 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008790}
8791
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008792static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8793{
8794 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8795 struct net_device *dev = info->user_ptr[1];
8796 struct ocb_setup setup = {};
8797 int err;
8798
8799 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8800 if (err)
8801 return err;
8802
8803 return cfg80211_join_ocb(rdev, dev, &setup);
8804}
8805
8806static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8807{
8808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8809 struct net_device *dev = info->user_ptr[1];
8810
8811 return cfg80211_leave_ocb(rdev, dev);
8812}
8813
Johannes Berg29cbe682010-12-03 09:20:44 +01008814static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8815{
8816 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8817 struct net_device *dev = info->user_ptr[1];
8818 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008819 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008820 int err;
8821
8822 /* start with default */
8823 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008824 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008825
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008826 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008827 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008828 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008829 if (err)
8830 return err;
8831 }
8832
8833 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8834 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8835 return -EINVAL;
8836
Javier Cardonac80d5452010-12-16 17:37:49 -08008837 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8838 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8839
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008840 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8841 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8842 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8843 return -EINVAL;
8844
Marco Porsch9bdbf042013-01-07 16:04:51 +01008845 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8846 setup.beacon_interval =
8847 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8848 if (setup.beacon_interval < 10 ||
8849 setup.beacon_interval > 10000)
8850 return -EINVAL;
8851 }
8852
8853 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8854 setup.dtim_period =
8855 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8856 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8857 return -EINVAL;
8858 }
8859
Javier Cardonac80d5452010-12-16 17:37:49 -08008860 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8861 /* parse additional setup parameters if given */
8862 err = nl80211_parse_mesh_setup(info, &setup);
8863 if (err)
8864 return err;
8865 }
8866
Thomas Pedersend37bb182013-03-04 13:06:13 -08008867 if (setup.user_mpm)
8868 cfg.auto_open_plinks = false;
8869
Johannes Bergcc1d2802012-05-16 23:50:20 +02008870 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008871 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8872 if (err)
8873 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008874 } else {
8875 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008876 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008877 }
8878
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008879 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8880 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8881 int n_rates =
8882 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8883 struct ieee80211_supported_band *sband;
8884
8885 if (!setup.chandef.chan)
8886 return -EINVAL;
8887
8888 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8889
8890 err = ieee80211_get_ratemask(sband, rates, n_rates,
8891 &setup.basic_rates);
8892 if (err)
8893 return err;
8894 }
8895
Javier Cardonac80d5452010-12-16 17:37:49 -08008896 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008897}
8898
8899static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8900{
8901 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8902 struct net_device *dev = info->user_ptr[1];
8903
8904 return cfg80211_leave_mesh(rdev, dev);
8905}
8906
Johannes Bergdfb89c52012-06-27 09:23:48 +02008907#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008908static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8909 struct cfg80211_registered_device *rdev)
8910{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008911 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008912 struct nlattr *nl_pats, *nl_pat;
8913 int i, pat_len;
8914
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008915 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008916 return 0;
8917
8918 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8919 if (!nl_pats)
8920 return -ENOBUFS;
8921
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008922 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008923 nl_pat = nla_nest_start(msg, i + 1);
8924 if (!nl_pat)
8925 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008926 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008927 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008928 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008929 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8930 wowlan->patterns[i].pattern) ||
8931 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008932 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008933 return -ENOBUFS;
8934 nla_nest_end(msg, nl_pat);
8935 }
8936 nla_nest_end(msg, nl_pats);
8937
8938 return 0;
8939}
8940
Johannes Berg2a0e0472013-01-23 22:57:40 +01008941static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8942 struct cfg80211_wowlan_tcp *tcp)
8943{
8944 struct nlattr *nl_tcp;
8945
8946 if (!tcp)
8947 return 0;
8948
8949 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8950 if (!nl_tcp)
8951 return -ENOBUFS;
8952
Jiri Benc930345e2015-03-29 16:59:25 +02008953 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8954 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01008955 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8956 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8957 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8958 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8959 tcp->payload_len, tcp->payload) ||
8960 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8961 tcp->data_interval) ||
8962 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8963 tcp->wake_len, tcp->wake_data) ||
8964 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8965 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8966 return -ENOBUFS;
8967
8968 if (tcp->payload_seq.len &&
8969 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8970 sizeof(tcp->payload_seq), &tcp->payload_seq))
8971 return -ENOBUFS;
8972
8973 if (tcp->payload_tok.len &&
8974 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8975 sizeof(tcp->payload_tok) + tcp->tokens_size,
8976 &tcp->payload_tok))
8977 return -ENOBUFS;
8978
Johannes Berge248ad32013-05-16 10:24:28 +02008979 nla_nest_end(msg, nl_tcp);
8980
Johannes Berg2a0e0472013-01-23 22:57:40 +01008981 return 0;
8982}
8983
Luciano Coelho75453cc2015-01-09 14:06:37 +02008984static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8985 struct cfg80211_sched_scan_request *req)
8986{
Avraham Stern3b06d272015-10-12 09:51:34 +03008987 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02008988 int i;
8989
8990 if (!req)
8991 return 0;
8992
8993 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
8994 if (!nd)
8995 return -ENOBUFS;
8996
Avraham Stern3b06d272015-10-12 09:51:34 +03008997 if (req->n_scan_plans == 1 &&
8998 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
8999 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009000 return -ENOBUFS;
9001
Luciano Coelho21fea562015-03-17 16:36:01 +02009002 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9003 return -ENOBUFS;
9004
Luciano Coelho75453cc2015-01-09 14:06:37 +02009005 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9006 if (!freqs)
9007 return -ENOBUFS;
9008
9009 for (i = 0; i < req->n_channels; i++)
9010 nla_put_u32(msg, i, req->channels[i]->center_freq);
9011
9012 nla_nest_end(msg, freqs);
9013
9014 if (req->n_match_sets) {
9015 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9016 for (i = 0; i < req->n_match_sets; i++) {
9017 match = nla_nest_start(msg, i);
9018 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9019 req->match_sets[i].ssid.ssid_len,
9020 req->match_sets[i].ssid.ssid);
9021 nla_nest_end(msg, match);
9022 }
9023 nla_nest_end(msg, matches);
9024 }
9025
Avraham Stern3b06d272015-10-12 09:51:34 +03009026 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9027 if (!scan_plans)
9028 return -ENOBUFS;
9029
9030 for (i = 0; i < req->n_scan_plans; i++) {
9031 scan_plan = nla_nest_start(msg, i + 1);
9032 if (!scan_plan ||
9033 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9034 req->scan_plans[i].interval) ||
9035 (req->scan_plans[i].iterations &&
9036 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9037 req->scan_plans[i].iterations)))
9038 return -ENOBUFS;
9039 nla_nest_end(msg, scan_plan);
9040 }
9041 nla_nest_end(msg, scan_plans);
9042
Luciano Coelho75453cc2015-01-09 14:06:37 +02009043 nla_nest_end(msg, nd);
9044
9045 return 0;
9046}
9047
Johannes Bergff1b6e62011-05-04 15:37:28 +02009048static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9049{
9050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9051 struct sk_buff *msg;
9052 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009053 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009054
Johannes Berg964dc9e2013-06-03 17:25:34 +02009055 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009056 return -EOPNOTSUPP;
9057
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009058 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009059 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009060 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9061 rdev->wiphy.wowlan_config->tcp->payload_len +
9062 rdev->wiphy.wowlan_config->tcp->wake_len +
9063 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009064 }
9065
9066 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009067 if (!msg)
9068 return -ENOMEM;
9069
Eric W. Biederman15e47302012-09-07 20:12:54 +00009070 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009071 NL80211_CMD_GET_WOWLAN);
9072 if (!hdr)
9073 goto nla_put_failure;
9074
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009075 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009076 struct nlattr *nl_wowlan;
9077
9078 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9079 if (!nl_wowlan)
9080 goto nla_put_failure;
9081
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009082 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009083 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009084 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009085 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009086 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009087 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009088 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009089 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009090 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009091 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009092 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009093 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009094 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009095 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9096 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009097
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009098 if (nl80211_send_wowlan_patterns(msg, rdev))
9099 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009100
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009101 if (nl80211_send_wowlan_tcp(msg,
9102 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009103 goto nla_put_failure;
9104
Luciano Coelho75453cc2015-01-09 14:06:37 +02009105 if (nl80211_send_wowlan_nd(
9106 msg,
9107 rdev->wiphy.wowlan_config->nd_config))
9108 goto nla_put_failure;
9109
Johannes Bergff1b6e62011-05-04 15:37:28 +02009110 nla_nest_end(msg, nl_wowlan);
9111 }
9112
9113 genlmsg_end(msg, hdr);
9114 return genlmsg_reply(msg, info);
9115
9116nla_put_failure:
9117 nlmsg_free(msg);
9118 return -ENOBUFS;
9119}
9120
Johannes Berg2a0e0472013-01-23 22:57:40 +01009121static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9122 struct nlattr *attr,
9123 struct cfg80211_wowlan *trig)
9124{
9125 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9126 struct cfg80211_wowlan_tcp *cfg;
9127 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9128 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9129 u32 size;
9130 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9131 int err, port;
9132
Johannes Berg964dc9e2013-06-03 17:25:34 +02009133 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009134 return -EINVAL;
9135
9136 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9137 nla_data(attr), nla_len(attr),
9138 nl80211_wowlan_tcp_policy);
9139 if (err)
9140 return err;
9141
9142 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9143 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9144 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9145 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9146 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9147 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9148 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9149 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9150 return -EINVAL;
9151
9152 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009153 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009154 return -EINVAL;
9155
9156 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009157 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009158 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009159 return -EINVAL;
9160
9161 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009162 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009163 return -EINVAL;
9164
9165 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9166 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9167 return -EINVAL;
9168
9169 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9170 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9171
9172 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9173 tokens_size = tokln - sizeof(*tok);
9174
9175 if (!tok->len || tokens_size % tok->len)
9176 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009177 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009178 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009179 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009180 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009181 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009182 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009183 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009184 return -EINVAL;
9185 if (tok->offset + tok->len > data_size)
9186 return -EINVAL;
9187 }
9188
9189 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9190 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009191 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009192 return -EINVAL;
9193 if (seq->len == 0 || seq->len > 4)
9194 return -EINVAL;
9195 if (seq->len + seq->offset > data_size)
9196 return -EINVAL;
9197 }
9198
9199 size = sizeof(*cfg);
9200 size += data_size;
9201 size += wake_size + wake_mask_size;
9202 size += tokens_size;
9203
9204 cfg = kzalloc(size, GFP_KERNEL);
9205 if (!cfg)
9206 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009207 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9208 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009209 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9210 ETH_ALEN);
9211 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9212 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9213 else
9214 port = 0;
9215#ifdef CONFIG_INET
9216 /* allocate a socket and port for it and use it */
9217 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9218 IPPROTO_TCP, &cfg->sock, 1);
9219 if (err) {
9220 kfree(cfg);
9221 return err;
9222 }
9223 if (inet_csk_get_port(cfg->sock->sk, port)) {
9224 sock_release(cfg->sock);
9225 kfree(cfg);
9226 return -EADDRINUSE;
9227 }
9228 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9229#else
9230 if (!port) {
9231 kfree(cfg);
9232 return -EINVAL;
9233 }
9234 cfg->src_port = port;
9235#endif
9236
9237 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9238 cfg->payload_len = data_size;
9239 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9240 memcpy((void *)cfg->payload,
9241 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9242 data_size);
9243 if (seq)
9244 cfg->payload_seq = *seq;
9245 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9246 cfg->wake_len = wake_size;
9247 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9248 memcpy((void *)cfg->wake_data,
9249 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9250 wake_size);
9251 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9252 data_size + wake_size;
9253 memcpy((void *)cfg->wake_mask,
9254 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9255 wake_mask_size);
9256 if (tok) {
9257 cfg->tokens_size = tokens_size;
9258 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9259 }
9260
9261 trig->tcp = cfg;
9262
9263 return 0;
9264}
9265
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009266static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9267 const struct wiphy_wowlan_support *wowlan,
9268 struct nlattr *attr,
9269 struct cfg80211_wowlan *trig)
9270{
9271 struct nlattr **tb;
9272 int err;
9273
9274 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9275 if (!tb)
9276 return -ENOMEM;
9277
9278 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9279 err = -EOPNOTSUPP;
9280 goto out;
9281 }
9282
9283 err = nla_parse(tb, NL80211_ATTR_MAX,
9284 nla_data(attr), nla_len(attr),
9285 nl80211_policy);
9286 if (err)
9287 goto out;
9288
Johannes Bergad2b26a2014-06-12 21:39:05 +02009289 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009290 err = PTR_ERR_OR_ZERO(trig->nd_config);
9291 if (err)
9292 trig->nd_config = NULL;
9293
9294out:
9295 kfree(tb);
9296 return err;
9297}
9298
Johannes Bergff1b6e62011-05-04 15:37:28 +02009299static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9300{
9301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9302 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009303 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009304 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009305 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009306 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009307 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009308 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009309
Johannes Berg964dc9e2013-06-03 17:25:34 +02009310 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009311 return -EOPNOTSUPP;
9312
Johannes Bergae33bd82012-07-12 16:25:02 +02009313 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9314 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009315 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009316 goto set_wakeup;
9317 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009318
9319 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9320 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9321 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9322 nl80211_wowlan_policy);
9323 if (err)
9324 return err;
9325
9326 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9327 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9328 return -EINVAL;
9329 new_triggers.any = true;
9330 }
9331
9332 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9333 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9334 return -EINVAL;
9335 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009336 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009337 }
9338
9339 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9340 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9341 return -EINVAL;
9342 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009343 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009344 }
9345
Johannes Berg77dbbb12011-07-13 10:48:55 +02009346 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9347 return -EINVAL;
9348
9349 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9350 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9351 return -EINVAL;
9352 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009353 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009354 }
9355
9356 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9357 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9358 return -EINVAL;
9359 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009360 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009361 }
9362
9363 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9364 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9365 return -EINVAL;
9366 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009367 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009368 }
9369
9370 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9371 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9372 return -EINVAL;
9373 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009374 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009375 }
9376
Johannes Bergff1b6e62011-05-04 15:37:28 +02009377 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9378 struct nlattr *pat;
9379 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009380 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009381 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009382
Johannes Berg98fc4382015-03-01 09:10:13 +02009383 regular = true;
9384
Johannes Bergff1b6e62011-05-04 15:37:28 +02009385 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9386 rem)
9387 n_patterns++;
9388 if (n_patterns > wowlan->n_patterns)
9389 return -EINVAL;
9390
9391 new_triggers.patterns = kcalloc(n_patterns,
9392 sizeof(new_triggers.patterns[0]),
9393 GFP_KERNEL);
9394 if (!new_triggers.patterns)
9395 return -ENOMEM;
9396
9397 new_triggers.n_patterns = n_patterns;
9398 i = 0;
9399
9400 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9401 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009402 u8 *mask_pat;
9403
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009404 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9405 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009406 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009407 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9408 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009409 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009410 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009411 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009412 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009413 goto error;
9414 if (pat_len > wowlan->pattern_max_len ||
9415 pat_len < wowlan->pattern_min_len)
9416 goto error;
9417
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009418 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009419 pkt_offset = 0;
9420 else
9421 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009422 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009423 if (pkt_offset > wowlan->max_pkt_offset)
9424 goto error;
9425 new_triggers.patterns[i].pkt_offset = pkt_offset;
9426
Johannes Berg922bd802014-05-19 17:59:50 +02009427 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9428 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009429 err = -ENOMEM;
9430 goto error;
9431 }
Johannes Berg922bd802014-05-19 17:59:50 +02009432 new_triggers.patterns[i].mask = mask_pat;
9433 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009434 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009435 mask_pat += mask_len;
9436 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009437 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009438 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009439 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009440 pat_len);
9441 i++;
9442 }
9443 }
9444
Johannes Berg2a0e0472013-01-23 22:57:40 +01009445 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009446 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009447 err = nl80211_parse_wowlan_tcp(
9448 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9449 &new_triggers);
9450 if (err)
9451 goto error;
9452 }
9453
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009454 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009455 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009456 err = nl80211_parse_wowlan_nd(
9457 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9458 &new_triggers);
9459 if (err)
9460 goto error;
9461 }
9462
Johannes Berg98fc4382015-03-01 09:10:13 +02009463 /* The 'any' trigger means the device continues operating more or less
9464 * as in its normal operation mode and wakes up the host on most of the
9465 * normal interrupts (like packet RX, ...)
9466 * It therefore makes little sense to combine with the more constrained
9467 * wakeup trigger modes.
9468 */
9469 if (new_triggers.any && regular) {
9470 err = -EINVAL;
9471 goto error;
9472 }
9473
Johannes Bergae33bd82012-07-12 16:25:02 +02009474 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9475 if (!ntrig) {
9476 err = -ENOMEM;
9477 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009478 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009479 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009480 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009481
Johannes Bergae33bd82012-07-12 16:25:02 +02009482 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009483 if (rdev->ops->set_wakeup &&
9484 prev_enabled != !!rdev->wiphy.wowlan_config)
9485 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009486
Johannes Bergff1b6e62011-05-04 15:37:28 +02009487 return 0;
9488 error:
9489 for (i = 0; i < new_triggers.n_patterns; i++)
9490 kfree(new_triggers.patterns[i].mask);
9491 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009492 if (new_triggers.tcp && new_triggers.tcp->sock)
9493 sock_release(new_triggers.tcp->sock);
9494 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009495 return err;
9496}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009497#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009498
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009499static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9500 struct cfg80211_registered_device *rdev)
9501{
9502 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9503 int i, j, pat_len;
9504 struct cfg80211_coalesce_rules *rule;
9505
9506 if (!rdev->coalesce->n_rules)
9507 return 0;
9508
9509 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9510 if (!nl_rules)
9511 return -ENOBUFS;
9512
9513 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9514 nl_rule = nla_nest_start(msg, i + 1);
9515 if (!nl_rule)
9516 return -ENOBUFS;
9517
9518 rule = &rdev->coalesce->rules[i];
9519 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9520 rule->delay))
9521 return -ENOBUFS;
9522
9523 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9524 rule->condition))
9525 return -ENOBUFS;
9526
9527 nl_pats = nla_nest_start(msg,
9528 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9529 if (!nl_pats)
9530 return -ENOBUFS;
9531
9532 for (j = 0; j < rule->n_patterns; j++) {
9533 nl_pat = nla_nest_start(msg, j + 1);
9534 if (!nl_pat)
9535 return -ENOBUFS;
9536 pat_len = rule->patterns[j].pattern_len;
9537 if (nla_put(msg, NL80211_PKTPAT_MASK,
9538 DIV_ROUND_UP(pat_len, 8),
9539 rule->patterns[j].mask) ||
9540 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9541 rule->patterns[j].pattern) ||
9542 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9543 rule->patterns[j].pkt_offset))
9544 return -ENOBUFS;
9545 nla_nest_end(msg, nl_pat);
9546 }
9547 nla_nest_end(msg, nl_pats);
9548 nla_nest_end(msg, nl_rule);
9549 }
9550 nla_nest_end(msg, nl_rules);
9551
9552 return 0;
9553}
9554
9555static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9556{
9557 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9558 struct sk_buff *msg;
9559 void *hdr;
9560
9561 if (!rdev->wiphy.coalesce)
9562 return -EOPNOTSUPP;
9563
9564 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9565 if (!msg)
9566 return -ENOMEM;
9567
9568 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9569 NL80211_CMD_GET_COALESCE);
9570 if (!hdr)
9571 goto nla_put_failure;
9572
9573 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9574 goto nla_put_failure;
9575
9576 genlmsg_end(msg, hdr);
9577 return genlmsg_reply(msg, info);
9578
9579nla_put_failure:
9580 nlmsg_free(msg);
9581 return -ENOBUFS;
9582}
9583
9584void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9585{
9586 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9587 int i, j;
9588 struct cfg80211_coalesce_rules *rule;
9589
9590 if (!coalesce)
9591 return;
9592
9593 for (i = 0; i < coalesce->n_rules; i++) {
9594 rule = &coalesce->rules[i];
9595 for (j = 0; j < rule->n_patterns; j++)
9596 kfree(rule->patterns[j].mask);
9597 kfree(rule->patterns);
9598 }
9599 kfree(coalesce->rules);
9600 kfree(coalesce);
9601 rdev->coalesce = NULL;
9602}
9603
9604static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9605 struct nlattr *rule,
9606 struct cfg80211_coalesce_rules *new_rule)
9607{
9608 int err, i;
9609 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9610 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9611 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9612 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9613
9614 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9615 nla_len(rule), nl80211_coalesce_policy);
9616 if (err)
9617 return err;
9618
9619 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9620 new_rule->delay =
9621 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9622 if (new_rule->delay > coalesce->max_delay)
9623 return -EINVAL;
9624
9625 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9626 new_rule->condition =
9627 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9628 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9629 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9630 return -EINVAL;
9631
9632 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9633 return -EINVAL;
9634
9635 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9636 rem)
9637 n_patterns++;
9638 if (n_patterns > coalesce->n_patterns)
9639 return -EINVAL;
9640
9641 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9642 GFP_KERNEL);
9643 if (!new_rule->patterns)
9644 return -ENOMEM;
9645
9646 new_rule->n_patterns = n_patterns;
9647 i = 0;
9648
9649 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9650 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009651 u8 *mask_pat;
9652
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009653 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9654 nla_len(pat), NULL);
9655 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9656 !pat_tb[NL80211_PKTPAT_PATTERN])
9657 return -EINVAL;
9658 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9659 mask_len = DIV_ROUND_UP(pat_len, 8);
9660 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9661 return -EINVAL;
9662 if (pat_len > coalesce->pattern_max_len ||
9663 pat_len < coalesce->pattern_min_len)
9664 return -EINVAL;
9665
9666 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9667 pkt_offset = 0;
9668 else
9669 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9670 if (pkt_offset > coalesce->max_pkt_offset)
9671 return -EINVAL;
9672 new_rule->patterns[i].pkt_offset = pkt_offset;
9673
Johannes Berg922bd802014-05-19 17:59:50 +02009674 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9675 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009676 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009677
9678 new_rule->patterns[i].mask = mask_pat;
9679 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9680 mask_len);
9681
9682 mask_pat += mask_len;
9683 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009684 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009685 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9686 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009687 i++;
9688 }
9689
9690 return 0;
9691}
9692
9693static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9694{
9695 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9696 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9697 struct cfg80211_coalesce new_coalesce = {};
9698 struct cfg80211_coalesce *n_coalesce;
9699 int err, rem_rule, n_rules = 0, i, j;
9700 struct nlattr *rule;
9701 struct cfg80211_coalesce_rules *tmp_rule;
9702
9703 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9704 return -EOPNOTSUPP;
9705
9706 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9707 cfg80211_rdev_free_coalesce(rdev);
9708 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9709 return 0;
9710 }
9711
9712 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9713 rem_rule)
9714 n_rules++;
9715 if (n_rules > coalesce->n_rules)
9716 return -EINVAL;
9717
9718 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9719 GFP_KERNEL);
9720 if (!new_coalesce.rules)
9721 return -ENOMEM;
9722
9723 new_coalesce.n_rules = n_rules;
9724 i = 0;
9725
9726 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9727 rem_rule) {
9728 err = nl80211_parse_coalesce_rule(rdev, rule,
9729 &new_coalesce.rules[i]);
9730 if (err)
9731 goto error;
9732
9733 i++;
9734 }
9735
9736 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9737 if (err)
9738 goto error;
9739
9740 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9741 if (!n_coalesce) {
9742 err = -ENOMEM;
9743 goto error;
9744 }
9745 cfg80211_rdev_free_coalesce(rdev);
9746 rdev->coalesce = n_coalesce;
9747
9748 return 0;
9749error:
9750 for (i = 0; i < new_coalesce.n_rules; i++) {
9751 tmp_rule = &new_coalesce.rules[i];
9752 for (j = 0; j < tmp_rule->n_patterns; j++)
9753 kfree(tmp_rule->patterns[j].mask);
9754 kfree(tmp_rule->patterns);
9755 }
9756 kfree(new_coalesce.rules);
9757
9758 return err;
9759}
9760
Johannes Berge5497d72011-07-05 16:35:40 +02009761static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9762{
9763 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9764 struct net_device *dev = info->user_ptr[1];
9765 struct wireless_dev *wdev = dev->ieee80211_ptr;
9766 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9767 struct cfg80211_gtk_rekey_data rekey_data;
9768 int err;
9769
9770 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9771 return -EINVAL;
9772
9773 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9774 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9775 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9776 nl80211_rekey_policy);
9777 if (err)
9778 return err;
9779
9780 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9781 return -ERANGE;
9782 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9783 return -ERANGE;
9784 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9785 return -ERANGE;
9786
Johannes Berg78f686c2014-09-10 22:28:06 +03009787 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9788 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9789 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009790
9791 wdev_lock(wdev);
9792 if (!wdev->current_bss) {
9793 err = -ENOTCONN;
9794 goto out;
9795 }
9796
9797 if (!rdev->ops->set_rekey_data) {
9798 err = -EOPNOTSUPP;
9799 goto out;
9800 }
9801
Hila Gonene35e4d22012-06-27 17:19:42 +03009802 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009803 out:
9804 wdev_unlock(wdev);
9805 return err;
9806}
9807
Johannes Berg28946da2011-11-04 11:18:12 +01009808static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9809 struct genl_info *info)
9810{
9811 struct net_device *dev = info->user_ptr[1];
9812 struct wireless_dev *wdev = dev->ieee80211_ptr;
9813
9814 if (wdev->iftype != NL80211_IFTYPE_AP &&
9815 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9816 return -EINVAL;
9817
Eric W. Biederman15e47302012-09-07 20:12:54 +00009818 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009819 return -EBUSY;
9820
Eric W. Biederman15e47302012-09-07 20:12:54 +00009821 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009822 return 0;
9823}
9824
Johannes Berg7f6cf312011-11-04 11:18:15 +01009825static int nl80211_probe_client(struct sk_buff *skb,
9826 struct genl_info *info)
9827{
9828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9829 struct net_device *dev = info->user_ptr[1];
9830 struct wireless_dev *wdev = dev->ieee80211_ptr;
9831 struct sk_buff *msg;
9832 void *hdr;
9833 const u8 *addr;
9834 u64 cookie;
9835 int err;
9836
9837 if (wdev->iftype != NL80211_IFTYPE_AP &&
9838 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9839 return -EOPNOTSUPP;
9840
9841 if (!info->attrs[NL80211_ATTR_MAC])
9842 return -EINVAL;
9843
9844 if (!rdev->ops->probe_client)
9845 return -EOPNOTSUPP;
9846
9847 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9848 if (!msg)
9849 return -ENOMEM;
9850
Eric W. Biederman15e47302012-09-07 20:12:54 +00009851 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009852 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009853 if (!hdr) {
9854 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009855 goto free_msg;
9856 }
9857
9858 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9859
Hila Gonene35e4d22012-06-27 17:19:42 +03009860 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009861 if (err)
9862 goto free_msg;
9863
David S. Miller9360ffd2012-03-29 04:41:26 -04009864 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9865 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009866
9867 genlmsg_end(msg, hdr);
9868
9869 return genlmsg_reply(msg, info);
9870
9871 nla_put_failure:
9872 err = -ENOBUFS;
9873 free_msg:
9874 nlmsg_free(msg);
9875 return err;
9876}
9877
Johannes Berg5e760232011-11-04 11:18:17 +01009878static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9879{
9880 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009881 struct cfg80211_beacon_registration *reg, *nreg;
9882 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009883
9884 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9885 return -EOPNOTSUPP;
9886
Ben Greear37c73b52012-10-26 14:49:25 -07009887 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9888 if (!nreg)
9889 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009890
Ben Greear37c73b52012-10-26 14:49:25 -07009891 /* First, check if already registered. */
9892 spin_lock_bh(&rdev->beacon_registrations_lock);
9893 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9894 if (reg->nlportid == info->snd_portid) {
9895 rv = -EALREADY;
9896 goto out_err;
9897 }
9898 }
9899 /* Add it to the list */
9900 nreg->nlportid = info->snd_portid;
9901 list_add(&nreg->list, &rdev->beacon_registrations);
9902
9903 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009904
9905 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009906out_err:
9907 spin_unlock_bh(&rdev->beacon_registrations_lock);
9908 kfree(nreg);
9909 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009910}
9911
Johannes Berg98104fde2012-06-16 00:19:54 +02009912static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9913{
9914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9915 struct wireless_dev *wdev = info->user_ptr[1];
9916 int err;
9917
9918 if (!rdev->ops->start_p2p_device)
9919 return -EOPNOTSUPP;
9920
9921 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9922 return -EOPNOTSUPP;
9923
9924 if (wdev->p2p_started)
9925 return 0;
9926
Luciano Coelhob6a55012014-02-27 11:07:21 +02009927 if (rfkill_blocked(rdev->rfkill))
9928 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009929
Johannes Bergeeb126e2012-10-23 15:16:50 +02009930 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009931 if (err)
9932 return err;
9933
9934 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009935 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009936
9937 return 0;
9938}
9939
9940static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9941{
9942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9943 struct wireless_dev *wdev = info->user_ptr[1];
9944
9945 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9946 return -EOPNOTSUPP;
9947
9948 if (!rdev->ops->stop_p2p_device)
9949 return -EOPNOTSUPP;
9950
Johannes Bergf9f47522013-03-19 15:04:07 +01009951 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009952
9953 return 0;
9954}
9955
Johannes Berg3713b4e2013-02-14 16:19:38 +01009956static int nl80211_get_protocol_features(struct sk_buff *skb,
9957 struct genl_info *info)
9958{
9959 void *hdr;
9960 struct sk_buff *msg;
9961
9962 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9963 if (!msg)
9964 return -ENOMEM;
9965
9966 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9967 NL80211_CMD_GET_PROTOCOL_FEATURES);
9968 if (!hdr)
9969 goto nla_put_failure;
9970
9971 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9972 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9973 goto nla_put_failure;
9974
9975 genlmsg_end(msg, hdr);
9976 return genlmsg_reply(msg, info);
9977
9978 nla_put_failure:
9979 kfree_skb(msg);
9980 return -ENOBUFS;
9981}
9982
Jouni Malinen355199e2013-02-27 17:14:27 +02009983static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9984{
9985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9986 struct cfg80211_update_ft_ies_params ft_params;
9987 struct net_device *dev = info->user_ptr[1];
9988
9989 if (!rdev->ops->update_ft_ies)
9990 return -EOPNOTSUPP;
9991
9992 if (!info->attrs[NL80211_ATTR_MDID] ||
9993 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9994 return -EINVAL;
9995
9996 memset(&ft_params, 0, sizeof(ft_params));
9997 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9998 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9999 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10000
10001 return rdev_update_ft_ies(rdev, dev, &ft_params);
10002}
10003
Arend van Spriel5de17982013-04-18 15:49:00 +020010004static int nl80211_crit_protocol_start(struct sk_buff *skb,
10005 struct genl_info *info)
10006{
10007 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10008 struct wireless_dev *wdev = info->user_ptr[1];
10009 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10010 u16 duration;
10011 int ret;
10012
10013 if (!rdev->ops->crit_proto_start)
10014 return -EOPNOTSUPP;
10015
10016 if (WARN_ON(!rdev->ops->crit_proto_stop))
10017 return -EINVAL;
10018
10019 if (rdev->crit_proto_nlportid)
10020 return -EBUSY;
10021
10022 /* determine protocol if provided */
10023 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10024 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10025
10026 if (proto >= NUM_NL80211_CRIT_PROTO)
10027 return -EINVAL;
10028
10029 /* timeout must be provided */
10030 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10031 return -EINVAL;
10032
10033 duration =
10034 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10035
10036 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10037 return -ERANGE;
10038
10039 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10040 if (!ret)
10041 rdev->crit_proto_nlportid = info->snd_portid;
10042
10043 return ret;
10044}
10045
10046static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10047 struct genl_info *info)
10048{
10049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10050 struct wireless_dev *wdev = info->user_ptr[1];
10051
10052 if (!rdev->ops->crit_proto_stop)
10053 return -EOPNOTSUPP;
10054
10055 if (rdev->crit_proto_nlportid) {
10056 rdev->crit_proto_nlportid = 0;
10057 rdev_crit_proto_stop(rdev, wdev);
10058 }
10059 return 0;
10060}
10061
Johannes Bergad7e7182013-11-13 13:37:47 +010010062static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10063{
10064 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10065 struct wireless_dev *wdev =
10066 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10067 int i, err;
10068 u32 vid, subcmd;
10069
10070 if (!rdev->wiphy.vendor_commands)
10071 return -EOPNOTSUPP;
10072
10073 if (IS_ERR(wdev)) {
10074 err = PTR_ERR(wdev);
10075 if (err != -EINVAL)
10076 return err;
10077 wdev = NULL;
10078 } else if (wdev->wiphy != &rdev->wiphy) {
10079 return -EINVAL;
10080 }
10081
10082 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10083 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10084 return -EINVAL;
10085
10086 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10087 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10088 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10089 const struct wiphy_vendor_command *vcmd;
10090 void *data = NULL;
10091 int len = 0;
10092
10093 vcmd = &rdev->wiphy.vendor_commands[i];
10094
10095 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10096 continue;
10097
10098 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10099 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10100 if (!wdev)
10101 return -EINVAL;
10102 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10103 !wdev->netdev)
10104 return -EINVAL;
10105
10106 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10107 if (wdev->netdev &&
10108 !netif_running(wdev->netdev))
10109 return -ENETDOWN;
10110 if (!wdev->netdev && !wdev->p2p_started)
10111 return -ENETDOWN;
10112 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010113
10114 if (!vcmd->doit)
10115 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010116 } else {
10117 wdev = NULL;
10118 }
10119
10120 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10121 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10122 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10123 }
10124
10125 rdev->cur_cmd_info = info;
10126 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10127 data, len);
10128 rdev->cur_cmd_info = NULL;
10129 return err;
10130 }
10131
10132 return -EOPNOTSUPP;
10133}
10134
Johannes Berg7bdbe402015-08-15 22:39:49 +030010135static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10136 struct netlink_callback *cb,
10137 struct cfg80211_registered_device **rdev,
10138 struct wireless_dev **wdev)
10139{
10140 u32 vid, subcmd;
10141 unsigned int i;
10142 int vcmd_idx = -1;
10143 int err;
10144 void *data = NULL;
10145 unsigned int data_len = 0;
10146
10147 rtnl_lock();
10148
10149 if (cb->args[0]) {
10150 /* subtract the 1 again here */
10151 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10152 struct wireless_dev *tmp;
10153
10154 if (!wiphy) {
10155 err = -ENODEV;
10156 goto out_unlock;
10157 }
10158 *rdev = wiphy_to_rdev(wiphy);
10159 *wdev = NULL;
10160
10161 if (cb->args[1]) {
10162 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
10163 if (tmp->identifier == cb->args[1] - 1) {
10164 *wdev = tmp;
10165 break;
10166 }
10167 }
10168 }
10169
10170 /* keep rtnl locked in successful case */
10171 return 0;
10172 }
10173
10174 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10175 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10176 nl80211_policy);
10177 if (err)
10178 goto out_unlock;
10179
10180 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10181 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10182 err = -EINVAL;
10183 goto out_unlock;
10184 }
10185
10186 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10187 nl80211_fam.attrbuf);
10188 if (IS_ERR(*wdev))
10189 *wdev = NULL;
10190
10191 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10192 nl80211_fam.attrbuf);
10193 if (IS_ERR(*rdev)) {
10194 err = PTR_ERR(*rdev);
10195 goto out_unlock;
10196 }
10197
10198 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10199 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10200
10201 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10202 const struct wiphy_vendor_command *vcmd;
10203
10204 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10205
10206 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10207 continue;
10208
10209 if (!vcmd->dumpit) {
10210 err = -EOPNOTSUPP;
10211 goto out_unlock;
10212 }
10213
10214 vcmd_idx = i;
10215 break;
10216 }
10217
10218 if (vcmd_idx < 0) {
10219 err = -EOPNOTSUPP;
10220 goto out_unlock;
10221 }
10222
10223 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10224 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10225 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10226 }
10227
10228 /* 0 is the first index - add 1 to parse only once */
10229 cb->args[0] = (*rdev)->wiphy_idx + 1;
10230 /* add 1 to know if it was NULL */
10231 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10232 cb->args[2] = vcmd_idx;
10233 cb->args[3] = (unsigned long)data;
10234 cb->args[4] = data_len;
10235
10236 /* keep rtnl locked in successful case */
10237 return 0;
10238 out_unlock:
10239 rtnl_unlock();
10240 return err;
10241}
10242
10243static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10244 struct netlink_callback *cb)
10245{
10246 struct cfg80211_registered_device *rdev;
10247 struct wireless_dev *wdev;
10248 unsigned int vcmd_idx;
10249 const struct wiphy_vendor_command *vcmd;
10250 void *data;
10251 int data_len;
10252 int err;
10253 struct nlattr *vendor_data;
10254
10255 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10256 if (err)
10257 return err;
10258
10259 vcmd_idx = cb->args[2];
10260 data = (void *)cb->args[3];
10261 data_len = cb->args[4];
10262 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10263
10264 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10265 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10266 if (!wdev)
10267 return -EINVAL;
10268 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10269 !wdev->netdev)
10270 return -EINVAL;
10271
10272 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10273 if (wdev->netdev &&
10274 !netif_running(wdev->netdev))
10275 return -ENETDOWN;
10276 if (!wdev->netdev && !wdev->p2p_started)
10277 return -ENETDOWN;
10278 }
10279 }
10280
10281 while (1) {
10282 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10283 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10284 NL80211_CMD_VENDOR);
10285 if (!hdr)
10286 break;
10287
10288 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10289 (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV,
10290 wdev_id(wdev)))) {
10291 genlmsg_cancel(skb, hdr);
10292 break;
10293 }
10294
10295 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10296 if (!vendor_data) {
10297 genlmsg_cancel(skb, hdr);
10298 break;
10299 }
10300
10301 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10302 (unsigned long *)&cb->args[5]);
10303 nla_nest_end(skb, vendor_data);
10304
10305 if (err == -ENOBUFS || err == -ENOENT) {
10306 genlmsg_cancel(skb, hdr);
10307 break;
10308 } else if (err) {
10309 genlmsg_cancel(skb, hdr);
10310 goto out;
10311 }
10312
10313 genlmsg_end(skb, hdr);
10314 }
10315
10316 err = skb->len;
10317 out:
10318 rtnl_unlock();
10319 return err;
10320}
10321
Johannes Bergad7e7182013-11-13 13:37:47 +010010322struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10323 enum nl80211_commands cmd,
10324 enum nl80211_attrs attr,
10325 int approxlen)
10326{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010327 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010328
10329 if (WARN_ON(!rdev->cur_cmd_info))
10330 return NULL;
10331
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010332 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010333 rdev->cur_cmd_info->snd_portid,
10334 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010335 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010336}
10337EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10338
10339int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10340{
10341 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10342 void *hdr = ((void **)skb->cb)[1];
10343 struct nlattr *data = ((void **)skb->cb)[2];
10344
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010345 /* clear CB data for netlink core to own from now on */
10346 memset(skb->cb, 0, sizeof(skb->cb));
10347
Johannes Bergad7e7182013-11-13 13:37:47 +010010348 if (WARN_ON(!rdev->cur_cmd_info)) {
10349 kfree_skb(skb);
10350 return -EINVAL;
10351 }
10352
10353 nla_nest_end(skb, data);
10354 genlmsg_end(skb, hdr);
10355 return genlmsg_reply(skb, rdev->cur_cmd_info);
10356}
10357EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10358
10359
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010360static int nl80211_set_qos_map(struct sk_buff *skb,
10361 struct genl_info *info)
10362{
10363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10364 struct cfg80211_qos_map *qos_map = NULL;
10365 struct net_device *dev = info->user_ptr[1];
10366 u8 *pos, len, num_des, des_len, des;
10367 int ret;
10368
10369 if (!rdev->ops->set_qos_map)
10370 return -EOPNOTSUPP;
10371
10372 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10373 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10374 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10375
10376 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10377 len > IEEE80211_QOS_MAP_LEN_MAX)
10378 return -EINVAL;
10379
10380 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10381 if (!qos_map)
10382 return -ENOMEM;
10383
10384 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10385 if (num_des) {
10386 des_len = num_des *
10387 sizeof(struct cfg80211_dscp_exception);
10388 memcpy(qos_map->dscp_exception, pos, des_len);
10389 qos_map->num_des = num_des;
10390 for (des = 0; des < num_des; des++) {
10391 if (qos_map->dscp_exception[des].up > 7) {
10392 kfree(qos_map);
10393 return -EINVAL;
10394 }
10395 }
10396 pos += des_len;
10397 }
10398 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10399 }
10400
10401 wdev_lock(dev->ieee80211_ptr);
10402 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10403 if (!ret)
10404 ret = rdev_set_qos_map(rdev, dev, qos_map);
10405 wdev_unlock(dev->ieee80211_ptr);
10406
10407 kfree(qos_map);
10408 return ret;
10409}
10410
Johannes Berg960d01a2014-09-09 22:55:35 +030010411static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10412{
10413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10414 struct net_device *dev = info->user_ptr[1];
10415 struct wireless_dev *wdev = dev->ieee80211_ptr;
10416 const u8 *peer;
10417 u8 tsid, up;
10418 u16 admitted_time = 0;
10419 int err;
10420
Johannes Berg723e73a2014-10-22 09:25:06 +020010421 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010422 return -EOPNOTSUPP;
10423
10424 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10425 !info->attrs[NL80211_ATTR_USER_PRIO])
10426 return -EINVAL;
10427
10428 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10429 if (tsid >= IEEE80211_NUM_TIDS)
10430 return -EINVAL;
10431
10432 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10433 if (up >= IEEE80211_NUM_UPS)
10434 return -EINVAL;
10435
10436 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010437 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010438 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010439 * need more attributes for that (e.g. BA session requirement);
10440 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010441 */
10442 return -EINVAL;
10443 }
10444
10445 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10446
10447 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10448 admitted_time =
10449 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10450 if (!admitted_time)
10451 return -EINVAL;
10452 }
10453
10454 wdev_lock(wdev);
10455 switch (wdev->iftype) {
10456 case NL80211_IFTYPE_STATION:
10457 case NL80211_IFTYPE_P2P_CLIENT:
10458 if (wdev->current_bss)
10459 break;
10460 err = -ENOTCONN;
10461 goto out;
10462 default:
10463 err = -EOPNOTSUPP;
10464 goto out;
10465 }
10466
10467 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10468
10469 out:
10470 wdev_unlock(wdev);
10471 return err;
10472}
10473
10474static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10475{
10476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10477 struct net_device *dev = info->user_ptr[1];
10478 struct wireless_dev *wdev = dev->ieee80211_ptr;
10479 const u8 *peer;
10480 u8 tsid;
10481 int err;
10482
10483 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10484 return -EINVAL;
10485
10486 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10487 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10488
10489 wdev_lock(wdev);
10490 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10491 wdev_unlock(wdev);
10492
10493 return err;
10494}
10495
Arik Nemtsov1057d352014-11-19 12:54:26 +020010496static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10497 struct genl_info *info)
10498{
10499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10500 struct net_device *dev = info->user_ptr[1];
10501 struct wireless_dev *wdev = dev->ieee80211_ptr;
10502 struct cfg80211_chan_def chandef = {};
10503 const u8 *addr;
10504 u8 oper_class;
10505 int err;
10506
10507 if (!rdev->ops->tdls_channel_switch ||
10508 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10509 return -EOPNOTSUPP;
10510
10511 switch (dev->ieee80211_ptr->iftype) {
10512 case NL80211_IFTYPE_STATION:
10513 case NL80211_IFTYPE_P2P_CLIENT:
10514 break;
10515 default:
10516 return -EOPNOTSUPP;
10517 }
10518
10519 if (!info->attrs[NL80211_ATTR_MAC] ||
10520 !info->attrs[NL80211_ATTR_OPER_CLASS])
10521 return -EINVAL;
10522
10523 err = nl80211_parse_chandef(rdev, info, &chandef);
10524 if (err)
10525 return err;
10526
10527 /*
10528 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10529 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10530 * specification is not defined for them.
10531 */
10532 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10533 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10534 chandef.width != NL80211_CHAN_WIDTH_20)
10535 return -EINVAL;
10536
10537 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010538 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10539 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010540 return -EINVAL;
10541
10542 /* don't allow switching to DFS channels */
10543 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10544 return -EINVAL;
10545
10546 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10547 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10548
10549 wdev_lock(wdev);
10550 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10551 wdev_unlock(wdev);
10552
10553 return err;
10554}
10555
10556static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10557 struct genl_info *info)
10558{
10559 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10560 struct net_device *dev = info->user_ptr[1];
10561 struct wireless_dev *wdev = dev->ieee80211_ptr;
10562 const u8 *addr;
10563
10564 if (!rdev->ops->tdls_channel_switch ||
10565 !rdev->ops->tdls_cancel_channel_switch ||
10566 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10567 return -EOPNOTSUPP;
10568
10569 switch (dev->ieee80211_ptr->iftype) {
10570 case NL80211_IFTYPE_STATION:
10571 case NL80211_IFTYPE_P2P_CLIENT:
10572 break;
10573 default:
10574 return -EOPNOTSUPP;
10575 }
10576
10577 if (!info->attrs[NL80211_ATTR_MAC])
10578 return -EINVAL;
10579
10580 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10581
10582 wdev_lock(wdev);
10583 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10584 wdev_unlock(wdev);
10585
10586 return 0;
10587}
10588
Johannes Berg4c476992010-10-04 21:36:35 +020010589#define NL80211_FLAG_NEED_WIPHY 0x01
10590#define NL80211_FLAG_NEED_NETDEV 0x02
10591#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010592#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10593#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10594 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010595#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010596/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010597#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10598 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010599#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010600
Johannes Bergf84f7712013-11-14 17:14:45 +010010601static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010602 struct genl_info *info)
10603{
10604 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010605 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010606 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010607 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10608
10609 if (rtnl)
10610 rtnl_lock();
10611
10612 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010613 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010614 if (IS_ERR(rdev)) {
10615 if (rtnl)
10616 rtnl_unlock();
10617 return PTR_ERR(rdev);
10618 }
10619 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010620 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10621 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010622 ASSERT_RTNL();
10623
Johannes Berg89a54e42012-06-15 14:33:17 +020010624 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10625 info->attrs);
10626 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010627 if (rtnl)
10628 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010629 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010630 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010631
Johannes Berg89a54e42012-06-15 14:33:17 +020010632 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010633 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010634
Johannes Berg1bf614e2012-06-15 15:23:36 +020010635 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10636 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010637 if (rtnl)
10638 rtnl_unlock();
10639 return -EINVAL;
10640 }
10641
10642 info->user_ptr[1] = dev;
10643 } else {
10644 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010645 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010646
Johannes Berg1bf614e2012-06-15 15:23:36 +020010647 if (dev) {
10648 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10649 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010650 if (rtnl)
10651 rtnl_unlock();
10652 return -ENETDOWN;
10653 }
10654
10655 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010656 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10657 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010658 if (rtnl)
10659 rtnl_unlock();
10660 return -ENETDOWN;
10661 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010662 }
10663
Johannes Berg4c476992010-10-04 21:36:35 +020010664 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010665 }
10666
10667 return 0;
10668}
10669
Johannes Bergf84f7712013-11-14 17:14:45 +010010670static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010671 struct genl_info *info)
10672{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010673 if (info->user_ptr[1]) {
10674 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10675 struct wireless_dev *wdev = info->user_ptr[1];
10676
10677 if (wdev->netdev)
10678 dev_put(wdev->netdev);
10679 } else {
10680 dev_put(info->user_ptr[1]);
10681 }
10682 }
Johannes Berg5393b912014-09-10 15:00:16 +030010683
Johannes Berg4c476992010-10-04 21:36:35 +020010684 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10685 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010686
10687 /* If needed, clear the netlink message payload from the SKB
10688 * as it might contain key data that shouldn't stick around on
10689 * the heap after the SKB is freed. The netlink message header
10690 * is still needed for further processing, so leave it intact.
10691 */
10692 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10693 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10694
10695 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10696 }
Johannes Berg4c476992010-10-04 21:36:35 +020010697}
10698
Johannes Berg4534de82013-11-14 17:14:46 +010010699static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010700 {
10701 .cmd = NL80211_CMD_GET_WIPHY,
10702 .doit = nl80211_get_wiphy,
10703 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010704 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010705 .policy = nl80211_policy,
10706 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010707 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10708 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010709 },
10710 {
10711 .cmd = NL80211_CMD_SET_WIPHY,
10712 .doit = nl80211_set_wiphy,
10713 .policy = nl80211_policy,
10714 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010715 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010716 },
10717 {
10718 .cmd = NL80211_CMD_GET_INTERFACE,
10719 .doit = nl80211_get_interface,
10720 .dumpit = nl80211_dump_interface,
10721 .policy = nl80211_policy,
10722 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010723 .internal_flags = NL80211_FLAG_NEED_WDEV |
10724 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010725 },
10726 {
10727 .cmd = NL80211_CMD_SET_INTERFACE,
10728 .doit = nl80211_set_interface,
10729 .policy = nl80211_policy,
10730 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010731 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10732 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010733 },
10734 {
10735 .cmd = NL80211_CMD_NEW_INTERFACE,
10736 .doit = nl80211_new_interface,
10737 .policy = nl80211_policy,
10738 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010739 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10740 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010741 },
10742 {
10743 .cmd = NL80211_CMD_DEL_INTERFACE,
10744 .doit = nl80211_del_interface,
10745 .policy = nl80211_policy,
10746 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010747 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010748 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010749 },
Johannes Berg41ade002007-12-19 02:03:29 +010010750 {
10751 .cmd = NL80211_CMD_GET_KEY,
10752 .doit = nl80211_get_key,
10753 .policy = nl80211_policy,
10754 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010755 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010756 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010757 },
10758 {
10759 .cmd = NL80211_CMD_SET_KEY,
10760 .doit = nl80211_set_key,
10761 .policy = nl80211_policy,
10762 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010763 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010764 NL80211_FLAG_NEED_RTNL |
10765 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010766 },
10767 {
10768 .cmd = NL80211_CMD_NEW_KEY,
10769 .doit = nl80211_new_key,
10770 .policy = nl80211_policy,
10771 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010773 NL80211_FLAG_NEED_RTNL |
10774 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010775 },
10776 {
10777 .cmd = NL80211_CMD_DEL_KEY,
10778 .doit = nl80211_del_key,
10779 .policy = nl80211_policy,
10780 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010781 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010782 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010783 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010784 {
10785 .cmd = NL80211_CMD_SET_BEACON,
10786 .policy = nl80211_policy,
10787 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010788 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010789 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010790 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010791 },
10792 {
Johannes Berg88600202012-02-13 15:17:18 +010010793 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010794 .policy = nl80211_policy,
10795 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010796 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010797 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010798 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010799 },
10800 {
Johannes Berg88600202012-02-13 15:17:18 +010010801 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010802 .policy = nl80211_policy,
10803 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010804 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010805 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010806 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010807 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010808 {
10809 .cmd = NL80211_CMD_GET_STATION,
10810 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010811 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010812 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010813 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10814 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010815 },
10816 {
10817 .cmd = NL80211_CMD_SET_STATION,
10818 .doit = nl80211_set_station,
10819 .policy = nl80211_policy,
10820 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010821 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010822 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010823 },
10824 {
10825 .cmd = NL80211_CMD_NEW_STATION,
10826 .doit = nl80211_new_station,
10827 .policy = nl80211_policy,
10828 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010829 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010830 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010831 },
10832 {
10833 .cmd = NL80211_CMD_DEL_STATION,
10834 .doit = nl80211_del_station,
10835 .policy = nl80211_policy,
10836 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010837 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010838 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010839 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010840 {
10841 .cmd = NL80211_CMD_GET_MPATH,
10842 .doit = nl80211_get_mpath,
10843 .dumpit = nl80211_dump_mpath,
10844 .policy = nl80211_policy,
10845 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010846 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010847 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010848 },
10849 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010850 .cmd = NL80211_CMD_GET_MPP,
10851 .doit = nl80211_get_mpp,
10852 .dumpit = nl80211_dump_mpp,
10853 .policy = nl80211_policy,
10854 .flags = GENL_ADMIN_PERM,
10855 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10856 NL80211_FLAG_NEED_RTNL,
10857 },
10858 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010859 .cmd = NL80211_CMD_SET_MPATH,
10860 .doit = nl80211_set_mpath,
10861 .policy = nl80211_policy,
10862 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010863 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010864 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010865 },
10866 {
10867 .cmd = NL80211_CMD_NEW_MPATH,
10868 .doit = nl80211_new_mpath,
10869 .policy = nl80211_policy,
10870 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010871 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010872 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010873 },
10874 {
10875 .cmd = NL80211_CMD_DEL_MPATH,
10876 .doit = nl80211_del_mpath,
10877 .policy = nl80211_policy,
10878 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010879 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010880 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010881 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010882 {
10883 .cmd = NL80211_CMD_SET_BSS,
10884 .doit = nl80211_set_bss,
10885 .policy = nl80211_policy,
10886 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010887 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010888 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010889 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010890 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010891 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010892 .doit = nl80211_get_reg_do,
10893 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010894 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010895 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010896 /* can be retrieved by unprivileged users */
10897 },
10898 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010899 .cmd = NL80211_CMD_SET_REG,
10900 .doit = nl80211_set_reg,
10901 .policy = nl80211_policy,
10902 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010903 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010904 },
10905 {
10906 .cmd = NL80211_CMD_REQ_SET_REG,
10907 .doit = nl80211_req_set_reg,
10908 .policy = nl80211_policy,
10909 .flags = GENL_ADMIN_PERM,
10910 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010911 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010912 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10913 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010914 .policy = nl80211_policy,
10915 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010916 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010917 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010918 },
10919 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010920 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10921 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010922 .policy = nl80211_policy,
10923 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010924 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010925 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010926 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010927 {
Johannes Berg2a519312009-02-10 21:25:55 +010010928 .cmd = NL80211_CMD_TRIGGER_SCAN,
10929 .doit = nl80211_trigger_scan,
10930 .policy = nl80211_policy,
10931 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010932 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010933 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010934 },
10935 {
10936 .cmd = NL80211_CMD_GET_SCAN,
10937 .policy = nl80211_policy,
10938 .dumpit = nl80211_dump_scan,
10939 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010940 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010941 .cmd = NL80211_CMD_START_SCHED_SCAN,
10942 .doit = nl80211_start_sched_scan,
10943 .policy = nl80211_policy,
10944 .flags = GENL_ADMIN_PERM,
10945 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10946 NL80211_FLAG_NEED_RTNL,
10947 },
10948 {
10949 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10950 .doit = nl80211_stop_sched_scan,
10951 .policy = nl80211_policy,
10952 .flags = GENL_ADMIN_PERM,
10953 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10954 NL80211_FLAG_NEED_RTNL,
10955 },
10956 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010957 .cmd = NL80211_CMD_AUTHENTICATE,
10958 .doit = nl80211_authenticate,
10959 .policy = nl80211_policy,
10960 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010961 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010962 NL80211_FLAG_NEED_RTNL |
10963 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010964 },
10965 {
10966 .cmd = NL80211_CMD_ASSOCIATE,
10967 .doit = nl80211_associate,
10968 .policy = nl80211_policy,
10969 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010970 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010971 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010972 },
10973 {
10974 .cmd = NL80211_CMD_DEAUTHENTICATE,
10975 .doit = nl80211_deauthenticate,
10976 .policy = nl80211_policy,
10977 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010978 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010979 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010980 },
10981 {
10982 .cmd = NL80211_CMD_DISASSOCIATE,
10983 .doit = nl80211_disassociate,
10984 .policy = nl80211_policy,
10985 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010986 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010987 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010988 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010989 {
10990 .cmd = NL80211_CMD_JOIN_IBSS,
10991 .doit = nl80211_join_ibss,
10992 .policy = nl80211_policy,
10993 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010994 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010995 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010996 },
10997 {
10998 .cmd = NL80211_CMD_LEAVE_IBSS,
10999 .doit = nl80211_leave_ibss,
11000 .policy = nl80211_policy,
11001 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011002 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011003 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011004 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011005#ifdef CONFIG_NL80211_TESTMODE
11006 {
11007 .cmd = NL80211_CMD_TESTMODE,
11008 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011009 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011010 .policy = nl80211_policy,
11011 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011012 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11013 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011014 },
11015#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011016 {
11017 .cmd = NL80211_CMD_CONNECT,
11018 .doit = nl80211_connect,
11019 .policy = nl80211_policy,
11020 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011021 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011022 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011023 },
11024 {
11025 .cmd = NL80211_CMD_DISCONNECT,
11026 .doit = nl80211_disconnect,
11027 .policy = nl80211_policy,
11028 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011029 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011030 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011031 },
Johannes Berg463d0182009-07-14 00:33:35 +020011032 {
11033 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11034 .doit = nl80211_wiphy_netns,
11035 .policy = nl80211_policy,
11036 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011037 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11038 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011039 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011040 {
11041 .cmd = NL80211_CMD_GET_SURVEY,
11042 .policy = nl80211_policy,
11043 .dumpit = nl80211_dump_survey,
11044 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011045 {
11046 .cmd = NL80211_CMD_SET_PMKSA,
11047 .doit = nl80211_setdel_pmksa,
11048 .policy = nl80211_policy,
11049 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011050 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011051 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011052 },
11053 {
11054 .cmd = NL80211_CMD_DEL_PMKSA,
11055 .doit = nl80211_setdel_pmksa,
11056 .policy = nl80211_policy,
11057 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011058 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011059 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011060 },
11061 {
11062 .cmd = NL80211_CMD_FLUSH_PMKSA,
11063 .doit = nl80211_flush_pmksa,
11064 .policy = nl80211_policy,
11065 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011066 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011067 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011068 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011069 {
11070 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11071 .doit = nl80211_remain_on_channel,
11072 .policy = nl80211_policy,
11073 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011074 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011075 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011076 },
11077 {
11078 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11079 .doit = nl80211_cancel_remain_on_channel,
11080 .policy = nl80211_policy,
11081 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011082 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011083 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011084 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011085 {
11086 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11087 .doit = nl80211_set_tx_bitrate_mask,
11088 .policy = nl80211_policy,
11089 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011090 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11091 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011092 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011093 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011094 .cmd = NL80211_CMD_REGISTER_FRAME,
11095 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011096 .policy = nl80211_policy,
11097 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011098 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011099 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011100 },
11101 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011102 .cmd = NL80211_CMD_FRAME,
11103 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011104 .policy = nl80211_policy,
11105 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011106 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011107 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011108 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011109 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011110 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11111 .doit = nl80211_tx_mgmt_cancel_wait,
11112 .policy = nl80211_policy,
11113 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011114 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011115 NL80211_FLAG_NEED_RTNL,
11116 },
11117 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011118 .cmd = NL80211_CMD_SET_POWER_SAVE,
11119 .doit = nl80211_set_power_save,
11120 .policy = nl80211_policy,
11121 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011122 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11123 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011124 },
11125 {
11126 .cmd = NL80211_CMD_GET_POWER_SAVE,
11127 .doit = nl80211_get_power_save,
11128 .policy = nl80211_policy,
11129 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011130 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11131 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011132 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011133 {
11134 .cmd = NL80211_CMD_SET_CQM,
11135 .doit = nl80211_set_cqm,
11136 .policy = nl80211_policy,
11137 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011138 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11139 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011140 },
Johannes Bergf444de02010-05-05 15:25:02 +020011141 {
11142 .cmd = NL80211_CMD_SET_CHANNEL,
11143 .doit = nl80211_set_channel,
11144 .policy = nl80211_policy,
11145 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011146 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11147 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011148 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011149 {
11150 .cmd = NL80211_CMD_SET_WDS_PEER,
11151 .doit = nl80211_set_wds_peer,
11152 .policy = nl80211_policy,
11153 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011154 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11155 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011156 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011157 {
11158 .cmd = NL80211_CMD_JOIN_MESH,
11159 .doit = nl80211_join_mesh,
11160 .policy = nl80211_policy,
11161 .flags = GENL_ADMIN_PERM,
11162 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11163 NL80211_FLAG_NEED_RTNL,
11164 },
11165 {
11166 .cmd = NL80211_CMD_LEAVE_MESH,
11167 .doit = nl80211_leave_mesh,
11168 .policy = nl80211_policy,
11169 .flags = GENL_ADMIN_PERM,
11170 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11171 NL80211_FLAG_NEED_RTNL,
11172 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011173 {
11174 .cmd = NL80211_CMD_JOIN_OCB,
11175 .doit = nl80211_join_ocb,
11176 .policy = nl80211_policy,
11177 .flags = GENL_ADMIN_PERM,
11178 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11179 NL80211_FLAG_NEED_RTNL,
11180 },
11181 {
11182 .cmd = NL80211_CMD_LEAVE_OCB,
11183 .doit = nl80211_leave_ocb,
11184 .policy = nl80211_policy,
11185 .flags = GENL_ADMIN_PERM,
11186 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11187 NL80211_FLAG_NEED_RTNL,
11188 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011189#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011190 {
11191 .cmd = NL80211_CMD_GET_WOWLAN,
11192 .doit = nl80211_get_wowlan,
11193 .policy = nl80211_policy,
11194 /* can be retrieved by unprivileged users */
11195 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11196 NL80211_FLAG_NEED_RTNL,
11197 },
11198 {
11199 .cmd = NL80211_CMD_SET_WOWLAN,
11200 .doit = nl80211_set_wowlan,
11201 .policy = nl80211_policy,
11202 .flags = GENL_ADMIN_PERM,
11203 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11204 NL80211_FLAG_NEED_RTNL,
11205 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011206#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011207 {
11208 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11209 .doit = nl80211_set_rekey_data,
11210 .policy = nl80211_policy,
11211 .flags = GENL_ADMIN_PERM,
11212 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011213 NL80211_FLAG_NEED_RTNL |
11214 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011215 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011216 {
11217 .cmd = NL80211_CMD_TDLS_MGMT,
11218 .doit = nl80211_tdls_mgmt,
11219 .policy = nl80211_policy,
11220 .flags = GENL_ADMIN_PERM,
11221 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11222 NL80211_FLAG_NEED_RTNL,
11223 },
11224 {
11225 .cmd = NL80211_CMD_TDLS_OPER,
11226 .doit = nl80211_tdls_oper,
11227 .policy = nl80211_policy,
11228 .flags = GENL_ADMIN_PERM,
11229 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11230 NL80211_FLAG_NEED_RTNL,
11231 },
Johannes Berg28946da2011-11-04 11:18:12 +010011232 {
11233 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11234 .doit = nl80211_register_unexpected_frame,
11235 .policy = nl80211_policy,
11236 .flags = GENL_ADMIN_PERM,
11237 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11238 NL80211_FLAG_NEED_RTNL,
11239 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011240 {
11241 .cmd = NL80211_CMD_PROBE_CLIENT,
11242 .doit = nl80211_probe_client,
11243 .policy = nl80211_policy,
11244 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011245 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011246 NL80211_FLAG_NEED_RTNL,
11247 },
Johannes Berg5e760232011-11-04 11:18:17 +010011248 {
11249 .cmd = NL80211_CMD_REGISTER_BEACONS,
11250 .doit = nl80211_register_beacons,
11251 .policy = nl80211_policy,
11252 .flags = GENL_ADMIN_PERM,
11253 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11254 NL80211_FLAG_NEED_RTNL,
11255 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011256 {
11257 .cmd = NL80211_CMD_SET_NOACK_MAP,
11258 .doit = nl80211_set_noack_map,
11259 .policy = nl80211_policy,
11260 .flags = GENL_ADMIN_PERM,
11261 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11262 NL80211_FLAG_NEED_RTNL,
11263 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011264 {
11265 .cmd = NL80211_CMD_START_P2P_DEVICE,
11266 .doit = nl80211_start_p2p_device,
11267 .policy = nl80211_policy,
11268 .flags = GENL_ADMIN_PERM,
11269 .internal_flags = NL80211_FLAG_NEED_WDEV |
11270 NL80211_FLAG_NEED_RTNL,
11271 },
11272 {
11273 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11274 .doit = nl80211_stop_p2p_device,
11275 .policy = nl80211_policy,
11276 .flags = GENL_ADMIN_PERM,
11277 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11278 NL80211_FLAG_NEED_RTNL,
11279 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011280 {
11281 .cmd = NL80211_CMD_SET_MCAST_RATE,
11282 .doit = nl80211_set_mcast_rate,
11283 .policy = nl80211_policy,
11284 .flags = GENL_ADMIN_PERM,
11285 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11286 NL80211_FLAG_NEED_RTNL,
11287 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011288 {
11289 .cmd = NL80211_CMD_SET_MAC_ACL,
11290 .doit = nl80211_set_mac_acl,
11291 .policy = nl80211_policy,
11292 .flags = GENL_ADMIN_PERM,
11293 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11294 NL80211_FLAG_NEED_RTNL,
11295 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011296 {
11297 .cmd = NL80211_CMD_RADAR_DETECT,
11298 .doit = nl80211_start_radar_detection,
11299 .policy = nl80211_policy,
11300 .flags = GENL_ADMIN_PERM,
11301 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11302 NL80211_FLAG_NEED_RTNL,
11303 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011304 {
11305 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11306 .doit = nl80211_get_protocol_features,
11307 .policy = nl80211_policy,
11308 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011309 {
11310 .cmd = NL80211_CMD_UPDATE_FT_IES,
11311 .doit = nl80211_update_ft_ies,
11312 .policy = nl80211_policy,
11313 .flags = GENL_ADMIN_PERM,
11314 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11315 NL80211_FLAG_NEED_RTNL,
11316 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011317 {
11318 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11319 .doit = nl80211_crit_protocol_start,
11320 .policy = nl80211_policy,
11321 .flags = GENL_ADMIN_PERM,
11322 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11323 NL80211_FLAG_NEED_RTNL,
11324 },
11325 {
11326 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11327 .doit = nl80211_crit_protocol_stop,
11328 .policy = nl80211_policy,
11329 .flags = GENL_ADMIN_PERM,
11330 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11331 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011332 },
11333 {
11334 .cmd = NL80211_CMD_GET_COALESCE,
11335 .doit = nl80211_get_coalesce,
11336 .policy = nl80211_policy,
11337 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11338 NL80211_FLAG_NEED_RTNL,
11339 },
11340 {
11341 .cmd = NL80211_CMD_SET_COALESCE,
11342 .doit = nl80211_set_coalesce,
11343 .policy = nl80211_policy,
11344 .flags = GENL_ADMIN_PERM,
11345 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11346 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011347 },
11348 {
11349 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11350 .doit = nl80211_channel_switch,
11351 .policy = nl80211_policy,
11352 .flags = GENL_ADMIN_PERM,
11353 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11354 NL80211_FLAG_NEED_RTNL,
11355 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011356 {
11357 .cmd = NL80211_CMD_VENDOR,
11358 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011359 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011360 .policy = nl80211_policy,
11361 .flags = GENL_ADMIN_PERM,
11362 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11363 NL80211_FLAG_NEED_RTNL,
11364 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011365 {
11366 .cmd = NL80211_CMD_SET_QOS_MAP,
11367 .doit = nl80211_set_qos_map,
11368 .policy = nl80211_policy,
11369 .flags = GENL_ADMIN_PERM,
11370 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11371 NL80211_FLAG_NEED_RTNL,
11372 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011373 {
11374 .cmd = NL80211_CMD_ADD_TX_TS,
11375 .doit = nl80211_add_tx_ts,
11376 .policy = nl80211_policy,
11377 .flags = GENL_ADMIN_PERM,
11378 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11379 NL80211_FLAG_NEED_RTNL,
11380 },
11381 {
11382 .cmd = NL80211_CMD_DEL_TX_TS,
11383 .doit = nl80211_del_tx_ts,
11384 .policy = nl80211_policy,
11385 .flags = GENL_ADMIN_PERM,
11386 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11387 NL80211_FLAG_NEED_RTNL,
11388 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011389 {
11390 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11391 .doit = nl80211_tdls_channel_switch,
11392 .policy = nl80211_policy,
11393 .flags = GENL_ADMIN_PERM,
11394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11395 NL80211_FLAG_NEED_RTNL,
11396 },
11397 {
11398 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11399 .doit = nl80211_tdls_cancel_channel_switch,
11400 .policy = nl80211_policy,
11401 .flags = GENL_ADMIN_PERM,
11402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11403 NL80211_FLAG_NEED_RTNL,
11404 },
Johannes Berg55682962007-09-20 13:09:35 -040011405};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011406
Johannes Berg55682962007-09-20 13:09:35 -040011407/* notification functions */
11408
Johannes Berg3bb20552014-05-26 13:52:25 +020011409void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11410 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011411{
11412 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011413 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011414
Johannes Berg3bb20552014-05-26 13:52:25 +020011415 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11416 cmd != NL80211_CMD_DEL_WIPHY);
11417
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011418 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011419 if (!msg)
11420 return;
11421
Johannes Berg3bb20552014-05-26 13:52:25 +020011422 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011423 nlmsg_free(msg);
11424 return;
11425 }
11426
Johannes Berg68eb5502013-11-19 15:19:38 +010011427 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011428 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011429}
11430
Johannes Berg362a4152009-05-24 16:43:15 +020011431static int nl80211_add_scan_req(struct sk_buff *msg,
11432 struct cfg80211_registered_device *rdev)
11433{
11434 struct cfg80211_scan_request *req = rdev->scan_req;
11435 struct nlattr *nest;
11436 int i;
11437
11438 if (WARN_ON(!req))
11439 return 0;
11440
11441 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11442 if (!nest)
11443 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011444 for (i = 0; i < req->n_ssids; i++) {
11445 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11446 goto nla_put_failure;
11447 }
Johannes Berg362a4152009-05-24 16:43:15 +020011448 nla_nest_end(msg, nest);
11449
11450 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11451 if (!nest)
11452 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011453 for (i = 0; i < req->n_channels; i++) {
11454 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11455 goto nla_put_failure;
11456 }
Johannes Berg362a4152009-05-24 16:43:15 +020011457 nla_nest_end(msg, nest);
11458
David S. Miller9360ffd2012-03-29 04:41:26 -040011459 if (req->ie &&
11460 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11461 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011462
Johannes Bergae917c92013-10-25 11:05:22 +020011463 if (req->flags &&
11464 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11465 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011466
Johannes Berg362a4152009-05-24 16:43:15 +020011467 return 0;
11468 nla_put_failure:
11469 return -ENOBUFS;
11470}
11471
Johannes Berga538e2d2009-06-16 19:56:42 +020011472static int nl80211_send_scan_msg(struct sk_buff *msg,
11473 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011474 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011475 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011476 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011477{
11478 void *hdr;
11479
Eric W. Biederman15e47302012-09-07 20:12:54 +000011480 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011481 if (!hdr)
11482 return -1;
11483
David S. Miller9360ffd2012-03-29 04:41:26 -040011484 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011485 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11486 wdev->netdev->ifindex)) ||
11487 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011488 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011489
Johannes Berg362a4152009-05-24 16:43:15 +020011490 /* ignore errors and send incomplete event anyway */
11491 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011492
Johannes Berg053c0952015-01-16 22:09:00 +010011493 genlmsg_end(msg, hdr);
11494 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011495
11496 nla_put_failure:
11497 genlmsg_cancel(msg, hdr);
11498 return -EMSGSIZE;
11499}
11500
Luciano Coelho807f8a82011-05-11 17:09:35 +030011501static int
11502nl80211_send_sched_scan_msg(struct sk_buff *msg,
11503 struct cfg80211_registered_device *rdev,
11504 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011505 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011506{
11507 void *hdr;
11508
Eric W. Biederman15e47302012-09-07 20:12:54 +000011509 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011510 if (!hdr)
11511 return -1;
11512
David S. Miller9360ffd2012-03-29 04:41:26 -040011513 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11514 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11515 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011516
Johannes Berg053c0952015-01-16 22:09:00 +010011517 genlmsg_end(msg, hdr);
11518 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011519
11520 nla_put_failure:
11521 genlmsg_cancel(msg, hdr);
11522 return -EMSGSIZE;
11523}
11524
Johannes Berga538e2d2009-06-16 19:56:42 +020011525void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011526 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011527{
11528 struct sk_buff *msg;
11529
Thomas Graf58050fc2012-06-28 03:57:45 +000011530 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011531 if (!msg)
11532 return;
11533
Johannes Bergfd014282012-06-18 19:17:03 +020011534 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011535 NL80211_CMD_TRIGGER_SCAN) < 0) {
11536 nlmsg_free(msg);
11537 return;
11538 }
11539
Johannes Berg68eb5502013-11-19 15:19:38 +010011540 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011541 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011542}
11543
Johannes Bergf9d15d12014-01-22 11:14:19 +020011544struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11545 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011546{
11547 struct sk_buff *msg;
11548
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011549 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011550 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011551 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011552
Johannes Bergfd014282012-06-18 19:17:03 +020011553 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011554 aborted ? NL80211_CMD_SCAN_ABORTED :
11555 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011556 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011557 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011558 }
11559
Johannes Bergf9d15d12014-01-22 11:14:19 +020011560 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011561}
11562
Johannes Bergf9d15d12014-01-22 11:14:19 +020011563void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11564 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011565{
Johannes Berg2a519312009-02-10 21:25:55 +010011566 if (!msg)
11567 return;
11568
Johannes Berg68eb5502013-11-19 15:19:38 +010011569 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011570 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011571}
11572
Luciano Coelho807f8a82011-05-11 17:09:35 +030011573void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11574 struct net_device *netdev)
11575{
11576 struct sk_buff *msg;
11577
11578 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11579 if (!msg)
11580 return;
11581
11582 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11583 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11584 nlmsg_free(msg);
11585 return;
11586 }
11587
Johannes Berg68eb5502013-11-19 15:19:38 +010011588 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011589 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011590}
11591
11592void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11593 struct net_device *netdev, u32 cmd)
11594{
11595 struct sk_buff *msg;
11596
Thomas Graf58050fc2012-06-28 03:57:45 +000011597 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011598 if (!msg)
11599 return;
11600
11601 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11602 nlmsg_free(msg);
11603 return;
11604 }
11605
Johannes Berg68eb5502013-11-19 15:19:38 +010011606 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011607 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011608}
11609
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011610static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11611 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011612{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011613 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011614 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11615 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011616
David S. Miller9360ffd2012-03-29 04:41:26 -040011617 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11618 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11619 NL80211_REGDOM_TYPE_WORLD))
11620 goto nla_put_failure;
11621 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11622 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11623 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11624 goto nla_put_failure;
11625 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11626 request->intersect) {
11627 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11628 NL80211_REGDOM_TYPE_INTERSECTION))
11629 goto nla_put_failure;
11630 } else {
11631 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11632 NL80211_REGDOM_TYPE_COUNTRY) ||
11633 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11634 request->alpha2))
11635 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011636 }
11637
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011638 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11639 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11640
11641 if (wiphy &&
11642 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11643 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011644
11645 if (wiphy &&
11646 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11647 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11648 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011649 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011650
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011651 return true;
11652
11653nla_put_failure:
11654 return false;
11655}
11656
11657/*
11658 * This can happen on global regulatory changes or device specific settings
11659 * based on custom regulatory domains.
11660 */
11661void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11662 struct regulatory_request *request)
11663{
11664 struct sk_buff *msg;
11665 void *hdr;
11666
11667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11668 if (!msg)
11669 return;
11670
11671 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11672 if (!hdr) {
11673 nlmsg_free(msg);
11674 return;
11675 }
11676
11677 if (nl80211_reg_change_event_fill(msg, request) == false)
11678 goto nla_put_failure;
11679
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011680 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011681
Johannes Bergbc43b282009-07-25 10:54:13 +020011682 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011683 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011684 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011685 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011686
11687 return;
11688
11689nla_put_failure:
11690 genlmsg_cancel(msg, hdr);
11691 nlmsg_free(msg);
11692}
11693
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011694static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11695 struct net_device *netdev,
11696 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011697 enum nl80211_commands cmd, gfp_t gfp,
11698 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011699{
11700 struct sk_buff *msg;
11701 void *hdr;
11702
Johannes Berge6d6e342009-07-01 21:26:47 +020011703 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011704 if (!msg)
11705 return;
11706
11707 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11708 if (!hdr) {
11709 nlmsg_free(msg);
11710 return;
11711 }
11712
David S. Miller9360ffd2012-03-29 04:41:26 -040011713 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11714 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11715 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11716 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011717
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011718 if (uapsd_queues >= 0) {
11719 struct nlattr *nla_wmm =
11720 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11721 if (!nla_wmm)
11722 goto nla_put_failure;
11723
11724 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11725 uapsd_queues))
11726 goto nla_put_failure;
11727
11728 nla_nest_end(msg, nla_wmm);
11729 }
11730
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011731 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011732
Johannes Berg68eb5502013-11-19 15:19:38 +010011733 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011734 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011735 return;
11736
11737 nla_put_failure:
11738 genlmsg_cancel(msg, hdr);
11739 nlmsg_free(msg);
11740}
11741
11742void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011743 struct net_device *netdev, const u8 *buf,
11744 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011745{
11746 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011747 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011748}
11749
11750void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11751 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011752 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011753{
Johannes Berge6d6e342009-07-01 21:26:47 +020011754 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011755 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011756}
11757
Jouni Malinen53b46b82009-03-27 20:53:56 +020011758void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011759 struct net_device *netdev, const u8 *buf,
11760 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011761{
11762 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011763 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011764}
11765
Jouni Malinen53b46b82009-03-27 20:53:56 +020011766void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11767 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011768 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011769{
11770 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011771 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011772}
11773
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011774void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11775 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011776{
Johannes Berg947add32013-02-22 22:05:20 +010011777 struct wireless_dev *wdev = dev->ieee80211_ptr;
11778 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011779 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011780 const struct ieee80211_mgmt *mgmt = (void *)buf;
11781 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011782
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011783 if (WARN_ON(len < 2))
11784 return;
11785
11786 if (ieee80211_is_deauth(mgmt->frame_control))
11787 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11788 else
11789 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11790
11791 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011792 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011793}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011794EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011795
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011796static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11797 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011798 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011799{
11800 struct sk_buff *msg;
11801 void *hdr;
11802
Johannes Berge6d6e342009-07-01 21:26:47 +020011803 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011804 if (!msg)
11805 return;
11806
11807 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11808 if (!hdr) {
11809 nlmsg_free(msg);
11810 return;
11811 }
11812
David S. Miller9360ffd2012-03-29 04:41:26 -040011813 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11814 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11815 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11816 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11817 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011818
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011819 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011820
Johannes Berg68eb5502013-11-19 15:19:38 +010011821 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011822 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011823 return;
11824
11825 nla_put_failure:
11826 genlmsg_cancel(msg, hdr);
11827 nlmsg_free(msg);
11828}
11829
11830void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011831 struct net_device *netdev, const u8 *addr,
11832 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011833{
11834 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011835 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011836}
11837
11838void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011839 struct net_device *netdev, const u8 *addr,
11840 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011841{
Johannes Berge6d6e342009-07-01 21:26:47 +020011842 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11843 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011844}
11845
Samuel Ortizb23aa672009-07-01 21:26:54 +020011846void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11847 struct net_device *netdev, const u8 *bssid,
11848 const u8 *req_ie, size_t req_ie_len,
11849 const u8 *resp_ie, size_t resp_ie_len,
11850 u16 status, gfp_t gfp)
11851{
11852 struct sk_buff *msg;
11853 void *hdr;
11854
Thomas Graf58050fc2012-06-28 03:57:45 +000011855 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011856 if (!msg)
11857 return;
11858
11859 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11860 if (!hdr) {
11861 nlmsg_free(msg);
11862 return;
11863 }
11864
David S. Miller9360ffd2012-03-29 04:41:26 -040011865 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11866 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11867 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11868 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11869 (req_ie &&
11870 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11871 (resp_ie &&
11872 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11873 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011874
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011875 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011876
Johannes Berg68eb5502013-11-19 15:19:38 +010011877 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011878 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011879 return;
11880
11881 nla_put_failure:
11882 genlmsg_cancel(msg, hdr);
11883 nlmsg_free(msg);
11884
11885}
11886
11887void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11888 struct net_device *netdev, const u8 *bssid,
11889 const u8 *req_ie, size_t req_ie_len,
11890 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11891{
11892 struct sk_buff *msg;
11893 void *hdr;
11894
Thomas Graf58050fc2012-06-28 03:57:45 +000011895 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011896 if (!msg)
11897 return;
11898
11899 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11900 if (!hdr) {
11901 nlmsg_free(msg);
11902 return;
11903 }
11904
David S. Miller9360ffd2012-03-29 04:41:26 -040011905 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11906 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11907 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11908 (req_ie &&
11909 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11910 (resp_ie &&
11911 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11912 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011913
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011914 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011915
Johannes Berg68eb5502013-11-19 15:19:38 +010011916 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011917 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011918 return;
11919
11920 nla_put_failure:
11921 genlmsg_cancel(msg, hdr);
11922 nlmsg_free(msg);
11923
11924}
11925
11926void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11927 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011928 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011929{
11930 struct sk_buff *msg;
11931 void *hdr;
11932
Thomas Graf58050fc2012-06-28 03:57:45 +000011933 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011934 if (!msg)
11935 return;
11936
11937 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11938 if (!hdr) {
11939 nlmsg_free(msg);
11940 return;
11941 }
11942
David S. Miller9360ffd2012-03-29 04:41:26 -040011943 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11944 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11945 (from_ap && reason &&
11946 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11947 (from_ap &&
11948 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11949 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11950 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011951
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011952 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011953
Johannes Berg68eb5502013-11-19 15:19:38 +010011954 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011955 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011956 return;
11957
11958 nla_put_failure:
11959 genlmsg_cancel(msg, hdr);
11960 nlmsg_free(msg);
11961
11962}
11963
Johannes Berg04a773a2009-04-19 21:24:32 +020011964void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11965 struct net_device *netdev, const u8 *bssid,
11966 gfp_t gfp)
11967{
11968 struct sk_buff *msg;
11969 void *hdr;
11970
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011971 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011972 if (!msg)
11973 return;
11974
11975 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11976 if (!hdr) {
11977 nlmsg_free(msg);
11978 return;
11979 }
11980
David S. Miller9360ffd2012-03-29 04:41:26 -040011981 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11982 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11983 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11984 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011985
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011986 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011987
Johannes Berg68eb5502013-11-19 15:19:38 +010011988 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011989 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011990 return;
11991
11992 nla_put_failure:
11993 genlmsg_cancel(msg, hdr);
11994 nlmsg_free(msg);
11995}
11996
Johannes Berg947add32013-02-22 22:05:20 +010011997void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11998 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011999{
Johannes Berg947add32013-02-22 22:05:20 +010012000 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012001 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012002 struct sk_buff *msg;
12003 void *hdr;
12004
Johannes Berg947add32013-02-22 22:05:20 +010012005 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12006 return;
12007
12008 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12009
Javier Cardonac93b5e72011-04-07 15:08:34 -070012010 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12011 if (!msg)
12012 return;
12013
12014 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12015 if (!hdr) {
12016 nlmsg_free(msg);
12017 return;
12018 }
12019
David S. Miller9360ffd2012-03-29 04:41:26 -040012020 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012021 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12022 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012023 (ie_len && ie &&
12024 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12025 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012026
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012027 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012028
Johannes Berg68eb5502013-11-19 15:19:38 +010012029 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012030 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012031 return;
12032
12033 nla_put_failure:
12034 genlmsg_cancel(msg, hdr);
12035 nlmsg_free(msg);
12036}
Johannes Berg947add32013-02-22 22:05:20 +010012037EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012038
Jouni Malinena3b8b052009-03-27 21:59:49 +020012039void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12040 struct net_device *netdev, const u8 *addr,
12041 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012042 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012043{
12044 struct sk_buff *msg;
12045 void *hdr;
12046
Johannes Berge6d6e342009-07-01 21:26:47 +020012047 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012048 if (!msg)
12049 return;
12050
12051 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12052 if (!hdr) {
12053 nlmsg_free(msg);
12054 return;
12055 }
12056
David S. Miller9360ffd2012-03-29 04:41:26 -040012057 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12058 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12059 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12060 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12061 (key_id != -1 &&
12062 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12063 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12064 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012065
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012066 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012067
Johannes Berg68eb5502013-11-19 15:19:38 +010012068 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012069 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012070 return;
12071
12072 nla_put_failure:
12073 genlmsg_cancel(msg, hdr);
12074 nlmsg_free(msg);
12075}
12076
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012077void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12078 struct ieee80211_channel *channel_before,
12079 struct ieee80211_channel *channel_after)
12080{
12081 struct sk_buff *msg;
12082 void *hdr;
12083 struct nlattr *nl_freq;
12084
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012085 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012086 if (!msg)
12087 return;
12088
12089 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12090 if (!hdr) {
12091 nlmsg_free(msg);
12092 return;
12093 }
12094
12095 /*
12096 * Since we are applying the beacon hint to a wiphy we know its
12097 * wiphy_idx is valid
12098 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012099 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12100 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012101
12102 /* Before */
12103 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12104 if (!nl_freq)
12105 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012106 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012107 goto nla_put_failure;
12108 nla_nest_end(msg, nl_freq);
12109
12110 /* After */
12111 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12112 if (!nl_freq)
12113 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012114 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012115 goto nla_put_failure;
12116 nla_nest_end(msg, nl_freq);
12117
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012118 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012119
Johannes Berg463d0182009-07-14 00:33:35 +020012120 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012121 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012122 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012123 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012124
12125 return;
12126
12127nla_put_failure:
12128 genlmsg_cancel(msg, hdr);
12129 nlmsg_free(msg);
12130}
12131
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012132static void nl80211_send_remain_on_chan_event(
12133 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012134 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012135 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012136 unsigned int duration, gfp_t gfp)
12137{
12138 struct sk_buff *msg;
12139 void *hdr;
12140
12141 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12142 if (!msg)
12143 return;
12144
12145 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12146 if (!hdr) {
12147 nlmsg_free(msg);
12148 return;
12149 }
12150
David S. Miller9360ffd2012-03-29 04:41:26 -040012151 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012152 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12153 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020012154 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012155 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012156 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12157 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012158 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
12159 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012160
David S. Miller9360ffd2012-03-29 04:41:26 -040012161 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12162 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12163 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012164
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012165 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012166
Johannes Berg68eb5502013-11-19 15:19:38 +010012167 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012168 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012169 return;
12170
12171 nla_put_failure:
12172 genlmsg_cancel(msg, hdr);
12173 nlmsg_free(msg);
12174}
12175
Johannes Berg947add32013-02-22 22:05:20 +010012176void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12177 struct ieee80211_channel *chan,
12178 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012179{
Johannes Berg947add32013-02-22 22:05:20 +010012180 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012181 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012182
12183 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012184 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012185 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012186 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012187}
Johannes Berg947add32013-02-22 22:05:20 +010012188EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012189
Johannes Berg947add32013-02-22 22:05:20 +010012190void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12191 struct ieee80211_channel *chan,
12192 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012193{
Johannes Berg947add32013-02-22 22:05:20 +010012194 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012195 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012196
12197 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012198 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012199 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012200}
Johannes Berg947add32013-02-22 22:05:20 +010012201EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012202
Johannes Berg947add32013-02-22 22:05:20 +010012203void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12204 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012205{
Johannes Berg947add32013-02-22 22:05:20 +010012206 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012207 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012208 struct sk_buff *msg;
12209
Johannes Berg947add32013-02-22 22:05:20 +010012210 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12211
Thomas Graf58050fc2012-06-28 03:57:45 +000012212 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012213 if (!msg)
12214 return;
12215
Johannes Bergcf5ead82014-11-14 17:14:00 +010012216 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012217 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012218 nlmsg_free(msg);
12219 return;
12220 }
12221
Johannes Berg68eb5502013-11-19 15:19:38 +010012222 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012223 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012224}
Johannes Berg947add32013-02-22 22:05:20 +010012225EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012226
Johannes Bergcf5ead82014-11-14 17:14:00 +010012227void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12228 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012229{
Johannes Berg947add32013-02-22 22:05:20 +010012230 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012231 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012232 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012233 struct station_info empty_sinfo = {};
12234
12235 if (!sinfo)
12236 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012237
Johannes Berg947add32013-02-22 22:05:20 +010012238 trace_cfg80211_del_sta(dev, mac_addr);
12239
Thomas Graf58050fc2012-06-28 03:57:45 +000012240 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012241 if (!msg)
12242 return;
12243
Johannes Bergcf5ead82014-11-14 17:14:00 +010012244 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012245 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012246 nlmsg_free(msg);
12247 return;
12248 }
12249
Johannes Berg68eb5502013-11-19 15:19:38 +010012250 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012251 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012252}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012253EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012254
Johannes Berg947add32013-02-22 22:05:20 +010012255void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12256 enum nl80211_connect_failed_reason reason,
12257 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012258{
Johannes Berg947add32013-02-22 22:05:20 +010012259 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012260 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012261 struct sk_buff *msg;
12262 void *hdr;
12263
12264 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12265 if (!msg)
12266 return;
12267
12268 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12269 if (!hdr) {
12270 nlmsg_free(msg);
12271 return;
12272 }
12273
12274 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12275 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12276 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12277 goto nla_put_failure;
12278
12279 genlmsg_end(msg, hdr);
12280
Johannes Berg68eb5502013-11-19 15:19:38 +010012281 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012282 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012283 return;
12284
12285 nla_put_failure:
12286 genlmsg_cancel(msg, hdr);
12287 nlmsg_free(msg);
12288}
Johannes Berg947add32013-02-22 22:05:20 +010012289EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012290
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012291static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12292 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012293{
12294 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012295 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012296 struct sk_buff *msg;
12297 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012298 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012299
Eric W. Biederman15e47302012-09-07 20:12:54 +000012300 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012301 return false;
12302
12303 msg = nlmsg_new(100, gfp);
12304 if (!msg)
12305 return true;
12306
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012307 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012308 if (!hdr) {
12309 nlmsg_free(msg);
12310 return true;
12311 }
12312
David S. Miller9360ffd2012-03-29 04:41:26 -040012313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12314 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12315 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12316 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012317
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012318 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012319 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012320 return true;
12321
12322 nla_put_failure:
12323 genlmsg_cancel(msg, hdr);
12324 nlmsg_free(msg);
12325 return true;
12326}
12327
Johannes Berg947add32013-02-22 22:05:20 +010012328bool cfg80211_rx_spurious_frame(struct net_device *dev,
12329 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012330{
Johannes Berg947add32013-02-22 22:05:20 +010012331 struct wireless_dev *wdev = dev->ieee80211_ptr;
12332 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012333
Johannes Berg947add32013-02-22 22:05:20 +010012334 trace_cfg80211_rx_spurious_frame(dev, addr);
12335
12336 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12337 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12338 trace_cfg80211_return_bool(false);
12339 return false;
12340 }
12341 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12342 addr, gfp);
12343 trace_cfg80211_return_bool(ret);
12344 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012345}
Johannes Berg947add32013-02-22 22:05:20 +010012346EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12347
12348bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12349 const u8 *addr, gfp_t gfp)
12350{
12351 struct wireless_dev *wdev = dev->ieee80211_ptr;
12352 bool ret;
12353
12354 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12355
12356 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12357 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12358 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12359 trace_cfg80211_return_bool(false);
12360 return false;
12361 }
12362 ret = __nl80211_unexpected_frame(dev,
12363 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12364 addr, gfp);
12365 trace_cfg80211_return_bool(ret);
12366 return ret;
12367}
12368EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012369
Johannes Berg2e161f72010-08-12 15:38:38 +020012370int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012371 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012372 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012373 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012374{
Johannes Berg71bbc992012-06-15 15:30:18 +020012375 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012376 struct sk_buff *msg;
12377 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012378
12379 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12380 if (!msg)
12381 return -ENOMEM;
12382
Johannes Berg2e161f72010-08-12 15:38:38 +020012383 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012384 if (!hdr) {
12385 nlmsg_free(msg);
12386 return -ENOMEM;
12387 }
12388
David S. Miller9360ffd2012-03-29 04:41:26 -040012389 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012390 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12391 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012392 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012393 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12394 (sig_dbm &&
12395 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012396 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12397 (flags &&
12398 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012399 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012400
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012401 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012402
Eric W. Biederman15e47302012-09-07 20:12:54 +000012403 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012404
12405 nla_put_failure:
12406 genlmsg_cancel(msg, hdr);
12407 nlmsg_free(msg);
12408 return -ENOBUFS;
12409}
12410
Johannes Berg947add32013-02-22 22:05:20 +010012411void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12412 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012413{
Johannes Berg947add32013-02-22 22:05:20 +010012414 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012415 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012416 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012417 struct sk_buff *msg;
12418 void *hdr;
12419
Johannes Berg947add32013-02-22 22:05:20 +010012420 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12421
Jouni Malinen026331c2010-02-15 12:53:10 +020012422 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12423 if (!msg)
12424 return;
12425
Johannes Berg2e161f72010-08-12 15:38:38 +020012426 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012427 if (!hdr) {
12428 nlmsg_free(msg);
12429 return;
12430 }
12431
David S. Miller9360ffd2012-03-29 04:41:26 -040012432 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012433 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12434 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012435 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012436 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12437 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12438 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12439 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012440
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012441 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012442
Johannes Berg68eb5502013-11-19 15:19:38 +010012443 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012444 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012445 return;
12446
12447 nla_put_failure:
12448 genlmsg_cancel(msg, hdr);
12449 nlmsg_free(msg);
12450}
Johannes Berg947add32013-02-22 22:05:20 +010012451EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012452
Johannes Berg5b97f492014-11-26 12:37:43 +010012453static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12454 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012455{
Johannes Berg947add32013-02-22 22:05:20 +010012456 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012457 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12458 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12459 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012460
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012461 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012462 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012463
Johannes Berg5b97f492014-11-26 12:37:43 +010012464 cb = (void **)msg->cb;
12465
12466 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12467 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012468 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012469 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012470 }
12471
David S. Miller9360ffd2012-03-29 04:41:26 -040012472 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012473 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012474 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012475
Johannes Berg5b97f492014-11-26 12:37:43 +010012476 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012477 goto nla_put_failure;
12478
Johannes Berg5b97f492014-11-26 12:37:43 +010012479 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12480 if (!cb[1])
12481 goto nla_put_failure;
12482
12483 cb[2] = rdev;
12484
12485 return msg;
12486 nla_put_failure:
12487 nlmsg_free(msg);
12488 return NULL;
12489}
12490
12491static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12492{
12493 void **cb = (void **)msg->cb;
12494 struct cfg80211_registered_device *rdev = cb[2];
12495
12496 nla_nest_end(msg, cb[1]);
12497 genlmsg_end(msg, cb[0]);
12498
12499 memset(msg->cb, 0, sizeof(msg->cb));
12500
12501 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12502 NL80211_MCGRP_MLME, gfp);
12503}
12504
12505void cfg80211_cqm_rssi_notify(struct net_device *dev,
12506 enum nl80211_cqm_rssi_threshold_event rssi_event,
12507 gfp_t gfp)
12508{
12509 struct sk_buff *msg;
12510
12511 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12512
Johannes Berg98f03342014-11-26 12:42:02 +010012513 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12514 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12515 return;
12516
Johannes Berg5b97f492014-11-26 12:37:43 +010012517 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12518 if (!msg)
12519 return;
12520
David S. Miller9360ffd2012-03-29 04:41:26 -040012521 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12522 rssi_event))
12523 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012524
Johannes Berg5b97f492014-11-26 12:37:43 +010012525 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012526
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012527 return;
12528
12529 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012530 nlmsg_free(msg);
12531}
Johannes Berg947add32013-02-22 22:05:20 +010012532EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012533
Johannes Berg5b97f492014-11-26 12:37:43 +010012534void cfg80211_cqm_txe_notify(struct net_device *dev,
12535 const u8 *peer, u32 num_packets,
12536 u32 rate, u32 intvl, gfp_t gfp)
12537{
12538 struct sk_buff *msg;
12539
12540 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12541 if (!msg)
12542 return;
12543
12544 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12545 goto nla_put_failure;
12546
12547 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12548 goto nla_put_failure;
12549
12550 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12551 goto nla_put_failure;
12552
12553 cfg80211_send_cqm(msg, gfp);
12554 return;
12555
12556 nla_put_failure:
12557 nlmsg_free(msg);
12558}
12559EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12560
12561void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12562 const u8 *peer, u32 num_packets, gfp_t gfp)
12563{
12564 struct sk_buff *msg;
12565
12566 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12567
12568 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12569 if (!msg)
12570 return;
12571
12572 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12573 goto nla_put_failure;
12574
12575 cfg80211_send_cqm(msg, gfp);
12576 return;
12577
12578 nla_put_failure:
12579 nlmsg_free(msg);
12580}
12581EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12582
Johannes Berg98f03342014-11-26 12:42:02 +010012583void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12584{
12585 struct sk_buff *msg;
12586
12587 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12588 if (!msg)
12589 return;
12590
12591 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12592 goto nla_put_failure;
12593
12594 cfg80211_send_cqm(msg, gfp);
12595 return;
12596
12597 nla_put_failure:
12598 nlmsg_free(msg);
12599}
12600EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12601
Johannes Berg947add32013-02-22 22:05:20 +010012602static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12603 struct net_device *netdev, const u8 *bssid,
12604 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012605{
12606 struct sk_buff *msg;
12607 struct nlattr *rekey_attr;
12608 void *hdr;
12609
Thomas Graf58050fc2012-06-28 03:57:45 +000012610 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012611 if (!msg)
12612 return;
12613
12614 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12615 if (!hdr) {
12616 nlmsg_free(msg);
12617 return;
12618 }
12619
David S. Miller9360ffd2012-03-29 04:41:26 -040012620 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12621 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12622 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12623 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012624
12625 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12626 if (!rekey_attr)
12627 goto nla_put_failure;
12628
David S. Miller9360ffd2012-03-29 04:41:26 -040012629 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12630 NL80211_REPLAY_CTR_LEN, replay_ctr))
12631 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012632
12633 nla_nest_end(msg, rekey_attr);
12634
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012635 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012636
Johannes Berg68eb5502013-11-19 15:19:38 +010012637 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012638 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012639 return;
12640
12641 nla_put_failure:
12642 genlmsg_cancel(msg, hdr);
12643 nlmsg_free(msg);
12644}
12645
Johannes Berg947add32013-02-22 22:05:20 +010012646void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12647 const u8 *replay_ctr, gfp_t gfp)
12648{
12649 struct wireless_dev *wdev = dev->ieee80211_ptr;
12650 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012651 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012652
12653 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12654 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12655}
12656EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12657
12658static void
12659nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12660 struct net_device *netdev, int index,
12661 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012662{
12663 struct sk_buff *msg;
12664 struct nlattr *attr;
12665 void *hdr;
12666
Thomas Graf58050fc2012-06-28 03:57:45 +000012667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012668 if (!msg)
12669 return;
12670
12671 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12672 if (!hdr) {
12673 nlmsg_free(msg);
12674 return;
12675 }
12676
David S. Miller9360ffd2012-03-29 04:41:26 -040012677 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12678 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12679 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012680
12681 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12682 if (!attr)
12683 goto nla_put_failure;
12684
David S. Miller9360ffd2012-03-29 04:41:26 -040012685 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12686 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12687 (preauth &&
12688 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12689 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012690
12691 nla_nest_end(msg, attr);
12692
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012693 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012694
Johannes Berg68eb5502013-11-19 15:19:38 +010012695 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012696 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012697 return;
12698
12699 nla_put_failure:
12700 genlmsg_cancel(msg, hdr);
12701 nlmsg_free(msg);
12702}
12703
Johannes Berg947add32013-02-22 22:05:20 +010012704void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12705 const u8 *bssid, bool preauth, gfp_t gfp)
12706{
12707 struct wireless_dev *wdev = dev->ieee80211_ptr;
12708 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012709 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012710
12711 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12712 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12713}
12714EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12715
12716static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12717 struct net_device *netdev,
12718 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012719 gfp_t gfp,
12720 enum nl80211_commands notif,
12721 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012722{
12723 struct sk_buff *msg;
12724 void *hdr;
12725
Thomas Graf58050fc2012-06-28 03:57:45 +000012726 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012727 if (!msg)
12728 return;
12729
Luciano Coelhof8d75522014-11-07 14:31:35 +020012730 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012731 if (!hdr) {
12732 nlmsg_free(msg);
12733 return;
12734 }
12735
Johannes Berg683b6d32012-11-08 21:25:48 +010012736 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12737 goto nla_put_failure;
12738
12739 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012740 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012741
Luciano Coelhof8d75522014-11-07 14:31:35 +020012742 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12743 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12744 goto nla_put_failure;
12745
Thomas Pedersen53145262012-04-06 13:35:47 -070012746 genlmsg_end(msg, hdr);
12747
Johannes Berg68eb5502013-11-19 15:19:38 +010012748 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012749 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012750 return;
12751
12752 nla_put_failure:
12753 genlmsg_cancel(msg, hdr);
12754 nlmsg_free(msg);
12755}
12756
Johannes Berg947add32013-02-22 22:05:20 +010012757void cfg80211_ch_switch_notify(struct net_device *dev,
12758 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012759{
Johannes Berg947add32013-02-22 22:05:20 +010012760 struct wireless_dev *wdev = dev->ieee80211_ptr;
12761 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012762 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012763
Simon Wunderliche487eae2013-11-21 18:19:51 +010012764 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012765
Simon Wunderliche487eae2013-11-21 18:19:51 +010012766 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012767
Michal Kazior9e0e2962014-01-29 14:22:27 +010012768 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012769 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012770 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12771 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012772}
12773EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12774
Luciano Coelhof8d75522014-11-07 14:31:35 +020012775void cfg80211_ch_switch_started_notify(struct net_device *dev,
12776 struct cfg80211_chan_def *chandef,
12777 u8 count)
12778{
12779 struct wireless_dev *wdev = dev->ieee80211_ptr;
12780 struct wiphy *wiphy = wdev->wiphy;
12781 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12782
12783 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12784
12785 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12786 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12787}
12788EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12789
Thomas Pedersen84f10702012-07-12 16:17:33 -070012790void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012791nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012792 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012793 enum nl80211_radar_event event,
12794 struct net_device *netdev, gfp_t gfp)
12795{
12796 struct sk_buff *msg;
12797 void *hdr;
12798
12799 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12800 if (!msg)
12801 return;
12802
12803 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12804 if (!hdr) {
12805 nlmsg_free(msg);
12806 return;
12807 }
12808
12809 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12810 goto nla_put_failure;
12811
12812 /* NOP and radar events don't need a netdev parameter */
12813 if (netdev) {
12814 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12815
12816 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12817 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12818 goto nla_put_failure;
12819 }
12820
12821 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12822 goto nla_put_failure;
12823
12824 if (nl80211_send_chandef(msg, chandef))
12825 goto nla_put_failure;
12826
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012827 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012828
Johannes Berg68eb5502013-11-19 15:19:38 +010012829 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012830 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012831 return;
12832
12833 nla_put_failure:
12834 genlmsg_cancel(msg, hdr);
12835 nlmsg_free(msg);
12836}
12837
Johannes Berg7f6cf312011-11-04 11:18:15 +010012838void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12839 u64 cookie, bool acked, gfp_t gfp)
12840{
12841 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012842 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012843 struct sk_buff *msg;
12844 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012845
Beni Lev4ee3e062012-08-27 12:49:39 +030012846 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12847
Thomas Graf58050fc2012-06-28 03:57:45 +000012848 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012849
Johannes Berg7f6cf312011-11-04 11:18:15 +010012850 if (!msg)
12851 return;
12852
12853 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12854 if (!hdr) {
12855 nlmsg_free(msg);
12856 return;
12857 }
12858
David S. Miller9360ffd2012-03-29 04:41:26 -040012859 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12860 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12861 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12862 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12863 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12864 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012865
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012866 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012867
Johannes Berg68eb5502013-11-19 15:19:38 +010012868 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012869 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012870 return;
12871
12872 nla_put_failure:
12873 genlmsg_cancel(msg, hdr);
12874 nlmsg_free(msg);
12875}
12876EXPORT_SYMBOL(cfg80211_probe_status);
12877
Johannes Berg5e760232011-11-04 11:18:17 +010012878void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12879 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012880 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012881{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012882 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012883 struct sk_buff *msg;
12884 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012885 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012886
Beni Lev4ee3e062012-08-27 12:49:39 +030012887 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12888
Ben Greear37c73b52012-10-26 14:49:25 -070012889 spin_lock_bh(&rdev->beacon_registrations_lock);
12890 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12891 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12892 if (!msg) {
12893 spin_unlock_bh(&rdev->beacon_registrations_lock);
12894 return;
12895 }
Johannes Berg5e760232011-11-04 11:18:17 +010012896
Ben Greear37c73b52012-10-26 14:49:25 -070012897 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12898 if (!hdr)
12899 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012900
Ben Greear37c73b52012-10-26 14:49:25 -070012901 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12902 (freq &&
12903 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12904 (sig_dbm &&
12905 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12906 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12907 goto nla_put_failure;
12908
12909 genlmsg_end(msg, hdr);
12910
12911 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012912 }
Ben Greear37c73b52012-10-26 14:49:25 -070012913 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012914 return;
12915
12916 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012917 spin_unlock_bh(&rdev->beacon_registrations_lock);
12918 if (hdr)
12919 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012920 nlmsg_free(msg);
12921}
12922EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12923
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012924#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012925static int cfg80211_net_detect_results(struct sk_buff *msg,
12926 struct cfg80211_wowlan_wakeup *wakeup)
12927{
12928 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12929 struct nlattr *nl_results, *nl_match, *nl_freqs;
12930 int i, j;
12931
12932 nl_results = nla_nest_start(
12933 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12934 if (!nl_results)
12935 return -EMSGSIZE;
12936
12937 for (i = 0; i < nd->n_matches; i++) {
12938 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12939
12940 nl_match = nla_nest_start(msg, i);
12941 if (!nl_match)
12942 break;
12943
12944 /* The SSID attribute is optional in nl80211, but for
12945 * simplicity reasons it's always present in the
12946 * cfg80211 structure. If a driver can't pass the
12947 * SSID, that needs to be changed. A zero length SSID
12948 * is still a valid SSID (wildcard), so it cannot be
12949 * used for this purpose.
12950 */
12951 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12952 match->ssid.ssid)) {
12953 nla_nest_cancel(msg, nl_match);
12954 goto out;
12955 }
12956
12957 if (match->n_channels) {
12958 nl_freqs = nla_nest_start(
12959 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12960 if (!nl_freqs) {
12961 nla_nest_cancel(msg, nl_match);
12962 goto out;
12963 }
12964
12965 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020012966 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012967 nla_nest_cancel(msg, nl_freqs);
12968 nla_nest_cancel(msg, nl_match);
12969 goto out;
12970 }
12971 }
12972
12973 nla_nest_end(msg, nl_freqs);
12974 }
12975
12976 nla_nest_end(msg, nl_match);
12977 }
12978
12979out:
12980 nla_nest_end(msg, nl_results);
12981 return 0;
12982}
12983
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012984void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12985 struct cfg80211_wowlan_wakeup *wakeup,
12986 gfp_t gfp)
12987{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012988 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012989 struct sk_buff *msg;
12990 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012991 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012992
12993 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12994
12995 if (wakeup)
12996 size += wakeup->packet_present_len;
12997
12998 msg = nlmsg_new(size, gfp);
12999 if (!msg)
13000 return;
13001
13002 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13003 if (!hdr)
13004 goto free_msg;
13005
13006 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13007 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13008 goto free_msg;
13009
13010 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13011 wdev->netdev->ifindex))
13012 goto free_msg;
13013
13014 if (wakeup) {
13015 struct nlattr *reasons;
13016
13017 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013018 if (!reasons)
13019 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013020
13021 if (wakeup->disconnect &&
13022 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13023 goto free_msg;
13024 if (wakeup->magic_pkt &&
13025 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13026 goto free_msg;
13027 if (wakeup->gtk_rekey_failure &&
13028 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13029 goto free_msg;
13030 if (wakeup->eap_identity_req &&
13031 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13032 goto free_msg;
13033 if (wakeup->four_way_handshake &&
13034 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13035 goto free_msg;
13036 if (wakeup->rfkill_release &&
13037 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13038 goto free_msg;
13039
13040 if (wakeup->pattern_idx >= 0 &&
13041 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13042 wakeup->pattern_idx))
13043 goto free_msg;
13044
Johannes Bergae917c92013-10-25 11:05:22 +020013045 if (wakeup->tcp_match &&
13046 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13047 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013048
Johannes Bergae917c92013-10-25 11:05:22 +020013049 if (wakeup->tcp_connlost &&
13050 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13051 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013052
Johannes Bergae917c92013-10-25 11:05:22 +020013053 if (wakeup->tcp_nomoretokens &&
13054 nla_put_flag(msg,
13055 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13056 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013057
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013058 if (wakeup->packet) {
13059 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13060 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13061
13062 if (!wakeup->packet_80211) {
13063 pkt_attr =
13064 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13065 len_attr =
13066 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13067 }
13068
13069 if (wakeup->packet_len &&
13070 nla_put_u32(msg, len_attr, wakeup->packet_len))
13071 goto free_msg;
13072
13073 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13074 wakeup->packet))
13075 goto free_msg;
13076 }
13077
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013078 if (wakeup->net_detect &&
13079 cfg80211_net_detect_results(msg, wakeup))
13080 goto free_msg;
13081
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013082 nla_nest_end(msg, reasons);
13083 }
13084
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013085 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013086
Johannes Berg68eb5502013-11-19 15:19:38 +010013087 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013088 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013089 return;
13090
13091 free_msg:
13092 nlmsg_free(msg);
13093}
13094EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13095#endif
13096
Jouni Malinen3475b092012-11-16 22:49:57 +020013097void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13098 enum nl80211_tdls_operation oper,
13099 u16 reason_code, gfp_t gfp)
13100{
13101 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013102 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013103 struct sk_buff *msg;
13104 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013105
13106 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13107 reason_code);
13108
13109 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13110 if (!msg)
13111 return;
13112
13113 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13114 if (!hdr) {
13115 nlmsg_free(msg);
13116 return;
13117 }
13118
13119 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13120 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13121 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13122 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13123 (reason_code > 0 &&
13124 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13125 goto nla_put_failure;
13126
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013127 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013128
Johannes Berg68eb5502013-11-19 15:19:38 +010013129 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013130 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013131 return;
13132
13133 nla_put_failure:
13134 genlmsg_cancel(msg, hdr);
13135 nlmsg_free(msg);
13136}
13137EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13138
Jouni Malinen026331c2010-02-15 12:53:10 +020013139static int nl80211_netlink_notify(struct notifier_block * nb,
13140 unsigned long state,
13141 void *_notify)
13142{
13143 struct netlink_notify *notify = _notify;
13144 struct cfg80211_registered_device *rdev;
13145 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013146 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013147
13148 if (state != NETLINK_URELEASE)
13149 return NOTIFY_DONE;
13150
13151 rcu_read_lock();
13152
Johannes Berg5e760232011-11-04 11:18:17 +010013153 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013154 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013155 bool schedule_scan_stop = false;
13156 struct cfg80211_sched_scan_request *sched_scan_req =
13157 rcu_dereference(rdev->sched_scan_req);
13158
13159 if (sched_scan_req && notify->portid &&
13160 sched_scan_req->owner_nlportid == notify->portid)
13161 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013162
13163 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013164 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013165
Johannes Berg78f22b62014-03-24 17:57:27 +010013166 if (wdev->owner_nlportid == notify->portid)
13167 schedule_destroy_work = true;
13168 }
13169
Ben Greear37c73b52012-10-26 14:49:25 -070013170 spin_lock_bh(&rdev->beacon_registrations_lock);
13171 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13172 list) {
13173 if (reg->nlportid == notify->portid) {
13174 list_del(&reg->list);
13175 kfree(reg);
13176 break;
13177 }
13178 }
13179 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013180
13181 if (schedule_destroy_work) {
13182 struct cfg80211_iface_destroy *destroy;
13183
13184 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13185 if (destroy) {
13186 destroy->nlportid = notify->portid;
13187 spin_lock(&rdev->destroy_list_lock);
13188 list_add(&destroy->list, &rdev->destroy_list);
13189 spin_unlock(&rdev->destroy_list_lock);
13190 schedule_work(&rdev->destroy_work);
13191 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013192 } else if (schedule_scan_stop) {
13193 sched_scan_req->owner_nlportid = 0;
13194
13195 if (rdev->ops->sched_scan_stop &&
13196 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13197 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013198 }
Johannes Berg5e760232011-11-04 11:18:17 +010013199 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013200
13201 rcu_read_unlock();
13202
Ilan peer05050752015-03-04 00:32:06 -050013203 /*
13204 * It is possible that the user space process that is controlling the
13205 * indoor setting disappeared, so notify the regulatory core.
13206 */
13207 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013208 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013209}
13210
13211static struct notifier_block nl80211_netlink_notifier = {
13212 .notifier_call = nl80211_netlink_notify,
13213};
13214
Jouni Malinen355199e2013-02-27 17:14:27 +020013215void cfg80211_ft_event(struct net_device *netdev,
13216 struct cfg80211_ft_event_params *ft_event)
13217{
13218 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013219 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013220 struct sk_buff *msg;
13221 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013222
13223 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13224
13225 if (!ft_event->target_ap)
13226 return;
13227
13228 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13229 if (!msg)
13230 return;
13231
13232 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013233 if (!hdr)
13234 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013235
Johannes Bergae917c92013-10-25 11:05:22 +020013236 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13237 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13238 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13239 goto out;
13240
13241 if (ft_event->ies &&
13242 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13243 goto out;
13244 if (ft_event->ric_ies &&
13245 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13246 ft_event->ric_ies))
13247 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013248
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013249 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013250
Johannes Berg68eb5502013-11-19 15:19:38 +010013251 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013252 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013253 return;
13254 out:
13255 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013256}
13257EXPORT_SYMBOL(cfg80211_ft_event);
13258
Arend van Spriel5de17982013-04-18 15:49:00 +020013259void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13260{
13261 struct cfg80211_registered_device *rdev;
13262 struct sk_buff *msg;
13263 void *hdr;
13264 u32 nlportid;
13265
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013266 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013267 if (!rdev->crit_proto_nlportid)
13268 return;
13269
13270 nlportid = rdev->crit_proto_nlportid;
13271 rdev->crit_proto_nlportid = 0;
13272
13273 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13274 if (!msg)
13275 return;
13276
13277 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13278 if (!hdr)
13279 goto nla_put_failure;
13280
13281 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13282 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13283 goto nla_put_failure;
13284
13285 genlmsg_end(msg, hdr);
13286
13287 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13288 return;
13289
13290 nla_put_failure:
13291 if (hdr)
13292 genlmsg_cancel(msg, hdr);
13293 nlmsg_free(msg);
13294
13295}
13296EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13297
Johannes Berg348baf02014-01-24 14:06:29 +010013298void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13299{
13300 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013301 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013302 struct sk_buff *msg;
13303 void *hdr;
13304
13305 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13306 if (!msg)
13307 return;
13308
13309 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13310 if (!hdr)
13311 goto out;
13312
13313 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13314 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
13315 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13316 goto out;
13317
13318 genlmsg_end(msg, hdr);
13319
13320 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13321 NL80211_MCGRP_MLME, GFP_KERNEL);
13322 return;
13323 out:
13324 nlmsg_free(msg);
13325}
13326
Johannes Berg55682962007-09-20 13:09:35 -040013327/* initialisation/exit functions */
13328
13329int nl80211_init(void)
13330{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013331 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013332
Johannes Berg2a94fe42013-11-19 15:19:39 +010013333 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13334 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013335 if (err)
13336 return err;
13337
Jouni Malinen026331c2010-02-15 12:53:10 +020013338 err = netlink_register_notifier(&nl80211_netlink_notifier);
13339 if (err)
13340 goto err_out;
13341
Johannes Berg55682962007-09-20 13:09:35 -040013342 return 0;
13343 err_out:
13344 genl_unregister_family(&nl80211_fam);
13345 return err;
13346}
13347
13348void nl80211_exit(void)
13349{
Jouni Malinen026331c2010-02-15 12:53:10 +020013350 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013351 genl_unregister_family(&nl80211_fam);
13352}