blob: 624174f20b1f8b7e264f1e5e715660fd785c4646 [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
Eliad Peller18998c32014-09-10 14:07:34 +03003435 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3436 params.smps_mode =
3437 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3438 switch (params.smps_mode) {
3439 case NL80211_SMPS_OFF:
3440 break;
3441 case NL80211_SMPS_STATIC:
3442 if (!(rdev->wiphy.features &
3443 NL80211_FEATURE_STATIC_SMPS))
3444 return -EINVAL;
3445 break;
3446 case NL80211_SMPS_DYNAMIC:
3447 if (!(rdev->wiphy.features &
3448 NL80211_FEATURE_DYNAMIC_SMPS))
3449 return -EINVAL;
3450 break;
3451 default:
3452 return -EINVAL;
3453 }
3454 } else {
3455 params.smps_mode = NL80211_SMPS_OFF;
3456 }
3457
Ola Olsson4baf6be2015-10-29 07:04:58 +01003458 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3459 params.acl = parse_acl_data(&rdev->wiphy, info);
3460 if (IS_ERR(params.acl))
3461 return PTR_ERR(params.acl);
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{
Ayala Bekere4208422015-10-23 11:20:06 +03003971 if (params->listen_interval != -1 &&
3972 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01003973 return -EINVAL;
Ayala Bekere4208422015-10-23 11:20:06 +03003974
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003975 if (params->aid &&
Ayala Bekere4208422015-10-23 11:20:06 +03003976 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
3977 statype != CFG80211_STA_AP_CLIENT_UNASSOC)
Johannes Berg77ee7c82013-02-15 00:48:33 +01003978 return -EINVAL;
3979
3980 /* When you run into this, adjust the code below for the new flag */
3981 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3982
3983 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003984 case CFG80211_STA_MESH_PEER_KERNEL:
3985 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003986 /*
3987 * No ignoring the TDLS flag here -- the userspace mesh
3988 * code doesn't have the bug of including TDLS in the
3989 * mask everywhere.
3990 */
3991 if (params->sta_flags_mask &
3992 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3993 BIT(NL80211_STA_FLAG_MFP) |
3994 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3995 return -EINVAL;
3996 break;
3997 case CFG80211_STA_TDLS_PEER_SETUP:
3998 case CFG80211_STA_TDLS_PEER_ACTIVE:
3999 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4000 return -EINVAL;
4001 /* ignore since it can't change */
4002 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4003 break;
4004 default:
4005 /* disallow mesh-specific things */
4006 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4007 return -EINVAL;
4008 if (params->local_pm)
4009 return -EINVAL;
4010 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4011 return -EINVAL;
4012 }
4013
4014 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4015 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4016 /* TDLS can't be set, ... */
4017 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4018 return -EINVAL;
4019 /*
4020 * ... but don't bother the driver with it. This works around
4021 * a hostapd/wpa_supplicant issue -- it always includes the
4022 * TLDS_PEER flag in the mask even for AP mode.
4023 */
4024 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4025 }
4026
Ayala Beker47edb112015-09-21 15:49:53 +03004027 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4028 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004029 /* reject other things that can't change */
4030 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4031 return -EINVAL;
4032 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4033 return -EINVAL;
4034 if (params->supported_rates)
4035 return -EINVAL;
4036 if (params->ext_capab || params->ht_capa || params->vht_capa)
4037 return -EINVAL;
4038 }
4039
Ayala Beker47edb112015-09-21 15:49:53 +03004040 if (statype != CFG80211_STA_AP_CLIENT &&
4041 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004042 if (params->vlan)
4043 return -EINVAL;
4044 }
4045
4046 switch (statype) {
4047 case CFG80211_STA_AP_MLME_CLIENT:
4048 /* Use this only for authorizing/unauthorizing a station */
4049 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4050 return -EOPNOTSUPP;
4051 break;
4052 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004053 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004054 /* accept only the listed bits */
4055 if (params->sta_flags_mask &
4056 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4057 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4058 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4059 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4060 BIT(NL80211_STA_FLAG_WME) |
4061 BIT(NL80211_STA_FLAG_MFP)))
4062 return -EINVAL;
4063
4064 /* but authenticated/associated only if driver handles it */
4065 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4066 params->sta_flags_mask &
4067 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4068 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4069 return -EINVAL;
4070 break;
4071 case CFG80211_STA_IBSS:
4072 case CFG80211_STA_AP_STA:
4073 /* reject any changes other than AUTHORIZED */
4074 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4075 return -EINVAL;
4076 break;
4077 case CFG80211_STA_TDLS_PEER_SETUP:
4078 /* reject any changes other than AUTHORIZED or WME */
4079 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4080 BIT(NL80211_STA_FLAG_WME)))
4081 return -EINVAL;
4082 /* force (at least) rates when authorizing */
4083 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4084 !params->supported_rates)
4085 return -EINVAL;
4086 break;
4087 case CFG80211_STA_TDLS_PEER_ACTIVE:
4088 /* reject any changes */
4089 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004090 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004091 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4092 return -EINVAL;
4093 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004094 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004095 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4096 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004097 return -EINVAL;
4098 break;
4099 }
4100
4101 return 0;
4102}
4103EXPORT_SYMBOL(cfg80211_check_station_change);
4104
Johannes Berg5727ef12007-12-19 02:03:34 +01004105/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004106 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004107 */
Johannes Berg80b99892011-11-18 16:23:01 +01004108static struct net_device *get_vlan(struct genl_info *info,
4109 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004110{
Johannes Berg463d0182009-07-14 00:33:35 +02004111 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004112 struct net_device *v;
4113 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004114
Johannes Berg80b99892011-11-18 16:23:01 +01004115 if (!vlanattr)
4116 return NULL;
4117
4118 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4119 if (!v)
4120 return ERR_PTR(-ENODEV);
4121
4122 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4123 ret = -EINVAL;
4124 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004125 }
Johannes Berg80b99892011-11-18 16:23:01 +01004126
Johannes Berg77ee7c82013-02-15 00:48:33 +01004127 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4128 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4129 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4130 ret = -EINVAL;
4131 goto error;
4132 }
4133
Johannes Berg80b99892011-11-18 16:23:01 +01004134 if (!netif_running(v)) {
4135 ret = -ENETDOWN;
4136 goto error;
4137 }
4138
4139 return v;
4140 error:
4141 dev_put(v);
4142 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004143}
4144
Johannes Berg94e860f2014-01-20 23:58:15 +01004145static const struct nla_policy
4146nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004147 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4148 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4149};
4150
Johannes Bergff276692013-02-15 00:09:01 +01004151static int nl80211_parse_sta_wme(struct genl_info *info,
4152 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004153{
Jouni Malinendf881292013-02-14 21:10:54 +02004154 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4155 struct nlattr *nla;
4156 int err;
4157
Jouni Malinendf881292013-02-14 21:10:54 +02004158 /* parse WME attributes if present */
4159 if (!info->attrs[NL80211_ATTR_STA_WME])
4160 return 0;
4161
4162 nla = info->attrs[NL80211_ATTR_STA_WME];
4163 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4164 nl80211_sta_wme_policy);
4165 if (err)
4166 return err;
4167
4168 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4169 params->uapsd_queues = nla_get_u8(
4170 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4171 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4172 return -EINVAL;
4173
4174 if (tb[NL80211_STA_WME_MAX_SP])
4175 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4176
4177 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4178 return -EINVAL;
4179
4180 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4181
4182 return 0;
4183}
4184
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304185static int nl80211_parse_sta_channel_info(struct genl_info *info,
4186 struct station_parameters *params)
4187{
4188 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4189 params->supported_channels =
4190 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4191 params->supported_channels_len =
4192 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4193 /*
4194 * Need to include at least one (first channel, number of
4195 * channels) tuple for each subband, and must have proper
4196 * tuples for the rest of the data as well.
4197 */
4198 if (params->supported_channels_len < 2)
4199 return -EINVAL;
4200 if (params->supported_channels_len % 2)
4201 return -EINVAL;
4202 }
4203
4204 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4205 params->supported_oper_classes =
4206 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4207 params->supported_oper_classes_len =
4208 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4209 /*
4210 * The value of the Length field of the Supported Operating
4211 * Classes element is between 2 and 253.
4212 */
4213 if (params->supported_oper_classes_len < 2 ||
4214 params->supported_oper_classes_len > 253)
4215 return -EINVAL;
4216 }
4217 return 0;
4218}
4219
Johannes Bergff276692013-02-15 00:09:01 +01004220static int nl80211_set_station_tdls(struct genl_info *info,
4221 struct station_parameters *params)
4222{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304223 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004224 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004225 if (info->attrs[NL80211_ATTR_PEER_AID])
4226 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004227 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4228 params->ht_capa =
4229 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4230 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4231 params->vht_capa =
4232 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4233
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304234 err = nl80211_parse_sta_channel_info(info, params);
4235 if (err)
4236 return err;
4237
Johannes Bergff276692013-02-15 00:09:01 +01004238 return nl80211_parse_sta_wme(info, params);
4239}
4240
Johannes Berg5727ef12007-12-19 02:03:34 +01004241static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4242{
Johannes Berg4c476992010-10-04 21:36:35 +02004243 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004244 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004245 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004246 u8 *mac_addr;
4247 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004248
4249 memset(&params, 0, sizeof(params));
4250
Johannes Berg77ee7c82013-02-15 00:48:33 +01004251 if (!rdev->ops->change_station)
4252 return -EOPNOTSUPP;
4253
Ayala Bekere4208422015-10-23 11:20:06 +03004254 /*
4255 * AID and listen_interval properties can be set only for unassociated
4256 * station. Include these parameters here and will check them in
4257 * cfg80211_check_station_change().
4258 */
4259 if (info->attrs[NL80211_ATTR_PEER_AID])
4260 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
4261
4262 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4263 params.listen_interval =
4264 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
4265 else
4266 params.listen_interval = -1;
Johannes Berg5727ef12007-12-19 02:03:34 +01004267
4268 if (!info->attrs[NL80211_ATTR_MAC])
4269 return -EINVAL;
4270
4271 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4272
4273 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4274 params.supported_rates =
4275 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4276 params.supported_rates_len =
4277 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4278 }
4279
Jouni Malinen9d62a982013-02-14 21:10:13 +02004280 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4281 params.capability =
4282 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4283 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4284 }
4285
4286 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4287 params.ext_capab =
4288 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4289 params.ext_capab_len =
4290 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4291 }
4292
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004293 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004294 return -EINVAL;
4295
Johannes Bergf8bacc22013-02-14 23:27:01 +01004296 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004297 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004298 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4299 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4300 return -EINVAL;
4301 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004302
Johannes Bergf8bacc22013-02-14 23:27:01 +01004303 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004304 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004305 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4306 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4307 return -EINVAL;
4308 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4309 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004310
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004311 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4312 enum nl80211_mesh_power_mode pm = nla_get_u32(
4313 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4314
4315 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4316 pm > NL80211_MESH_POWER_MAX)
4317 return -EINVAL;
4318
4319 params.local_pm = pm;
4320 }
4321
Johannes Berg77ee7c82013-02-15 00:48:33 +01004322 /* Include parameters for TDLS peer (will check later) */
4323 err = nl80211_set_station_tdls(info, &params);
4324 if (err)
4325 return err;
4326
4327 params.vlan = get_vlan(info, rdev);
4328 if (IS_ERR(params.vlan))
4329 return PTR_ERR(params.vlan);
4330
Johannes Berga97f4422009-06-18 17:23:43 +02004331 switch (dev->ieee80211_ptr->iftype) {
4332 case NL80211_IFTYPE_AP:
4333 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004334 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004335 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004336 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004337 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004338 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004339 break;
4340 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004341 err = -EOPNOTSUPP;
4342 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004343 }
4344
Johannes Berg77ee7c82013-02-15 00:48:33 +01004345 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004346 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004347
Johannes Berg77ee7c82013-02-15 00:48:33 +01004348 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004349 if (params.vlan)
4350 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004351
Johannes Berg5727ef12007-12-19 02:03:34 +01004352 return err;
4353}
4354
4355static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4356{
Johannes Berg4c476992010-10-04 21:36:35 +02004357 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004358 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004359 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004360 struct station_parameters params;
4361 u8 *mac_addr = NULL;
4362
4363 memset(&params, 0, sizeof(params));
4364
Johannes Berg984c3112013-02-14 23:43:25 +01004365 if (!rdev->ops->add_station)
4366 return -EOPNOTSUPP;
4367
Johannes Berg5727ef12007-12-19 02:03:34 +01004368 if (!info->attrs[NL80211_ATTR_MAC])
4369 return -EINVAL;
4370
Johannes Berg5727ef12007-12-19 02:03:34 +01004371 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4372 return -EINVAL;
4373
4374 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4375 return -EINVAL;
4376
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004377 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4378 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004379 return -EINVAL;
4380
Johannes Berg5727ef12007-12-19 02:03:34 +01004381 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4382 params.supported_rates =
4383 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4384 params.supported_rates_len =
4385 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4386 params.listen_interval =
4387 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004388
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004389 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004390 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004391 else
4392 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004393 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4394 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004395
Jouni Malinen9d62a982013-02-14 21:10:13 +02004396 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4397 params.capability =
4398 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4399 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4400 }
4401
4402 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4403 params.ext_capab =
4404 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4405 params.ext_capab_len =
4406 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4407 }
4408
Jouni Malinen36aedc92008-08-25 11:58:58 +03004409 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4410 params.ht_capa =
4411 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004412
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004413 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4414 params.vht_capa =
4415 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4416
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004417 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4418 params.opmode_notif_used = true;
4419 params.opmode_notif =
4420 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4421 }
4422
Johannes Bergf8bacc22013-02-14 23:27:01 +01004423 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004424 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004425 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4426 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4427 return -EINVAL;
4428 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004429
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304430 err = nl80211_parse_sta_channel_info(info, &params);
4431 if (err)
4432 return err;
4433
Johannes Bergff276692013-02-15 00:09:01 +01004434 err = nl80211_parse_sta_wme(info, &params);
4435 if (err)
4436 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004437
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004438 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004439 return -EINVAL;
4440
Johannes Berg496fcc22015-03-12 08:53:27 +02004441 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4442 * as userspace might just pass through the capabilities from the IEs
4443 * directly, rather than enforcing this restriction and returning an
4444 * error in this case.
4445 */
4446 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4447 params.ht_capa = NULL;
4448 params.vht_capa = NULL;
4449 }
4450
Johannes Berg77ee7c82013-02-15 00:48:33 +01004451 /* When you run into this, adjust the code below for the new flag */
4452 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4453
Johannes Bergbdd90d52011-12-14 12:20:27 +01004454 switch (dev->ieee80211_ptr->iftype) {
4455 case NL80211_IFTYPE_AP:
4456 case NL80211_IFTYPE_AP_VLAN:
4457 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004458 /* ignore WME attributes if iface/sta is not capable */
4459 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4460 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4461 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004462
Johannes Bergbdd90d52011-12-14 12:20:27 +01004463 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004464 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4465 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004466 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004467 /* but don't bother the driver with it */
4468 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004469
Johannes Bergd582cff2012-10-26 17:53:44 +02004470 /* allow authenticated/associated only if driver handles it */
4471 if (!(rdev->wiphy.features &
4472 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4473 params.sta_flags_mask &
4474 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4475 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4476 return -EINVAL;
4477
Johannes Bergbdd90d52011-12-14 12:20:27 +01004478 /* must be last in here for error handling */
4479 params.vlan = get_vlan(info, rdev);
4480 if (IS_ERR(params.vlan))
4481 return PTR_ERR(params.vlan);
4482 break;
4483 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004484 /* ignore uAPSD data */
4485 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4486
Johannes Bergd582cff2012-10-26 17:53:44 +02004487 /* associated is disallowed */
4488 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4489 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004490 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004491 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4492 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004493 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004494 break;
4495 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004496 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004497 /* ignore uAPSD data */
4498 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4499
Johannes Berg77ee7c82013-02-15 00:48:33 +01004500 /* these are disallowed */
4501 if (params.sta_flags_mask &
4502 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4503 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004504 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004505 /* Only TDLS peers can be added */
4506 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4507 return -EINVAL;
4508 /* Can only add if TDLS ... */
4509 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4510 return -EOPNOTSUPP;
4511 /* ... with external setup is supported */
4512 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4513 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004514 /*
4515 * Older wpa_supplicant versions always mark the TDLS peer
4516 * as authorized, but it shouldn't yet be.
4517 */
4518 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004519 break;
4520 default:
4521 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004522 }
4523
Johannes Bergbdd90d52011-12-14 12:20:27 +01004524 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004525
Hila Gonene35e4d22012-06-27 17:19:42 +03004526 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004527
Johannes Berg5727ef12007-12-19 02:03:34 +01004528 if (params.vlan)
4529 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004530 return err;
4531}
4532
4533static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4534{
Johannes Berg4c476992010-10-04 21:36:35 +02004535 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4536 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004537 struct station_del_parameters params;
4538
4539 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004540
4541 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004542 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004543
Johannes Berge80cf852009-05-11 14:43:13 +02004544 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004545 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004546 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004547 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4548 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004549
Johannes Berg4c476992010-10-04 21:36:35 +02004550 if (!rdev->ops->del_station)
4551 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004552
Jouni Malinen98856862014-10-20 13:20:45 +03004553 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4554 params.subtype =
4555 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4556 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4557 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4558 return -EINVAL;
4559 } else {
4560 /* Default to Deauthentication frame */
4561 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4562 }
4563
4564 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4565 params.reason_code =
4566 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4567 if (params.reason_code == 0)
4568 return -EINVAL; /* 0 is reserved */
4569 } else {
4570 /* Default to reason code 2 */
4571 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4572 }
4573
Jouni Malinen89c771e2014-10-10 20:52:40 +03004574 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004575}
4576
Eric W. Biederman15e47302012-09-07 20:12:54 +00004577static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004578 int flags, struct net_device *dev,
4579 u8 *dst, u8 *next_hop,
4580 struct mpath_info *pinfo)
4581{
4582 void *hdr;
4583 struct nlattr *pinfoattr;
4584
Henning Rogge1ef4c852014-11-04 16:14:58 +01004585 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004586 if (!hdr)
4587 return -1;
4588
David S. Miller9360ffd2012-03-29 04:41:26 -04004589 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4590 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4591 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4592 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4593 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004594
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004595 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4596 if (!pinfoattr)
4597 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004598 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4599 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4600 pinfo->frame_qlen))
4601 goto nla_put_failure;
4602 if (((pinfo->filled & MPATH_INFO_SN) &&
4603 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4604 ((pinfo->filled & MPATH_INFO_METRIC) &&
4605 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4606 pinfo->metric)) ||
4607 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4608 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4609 pinfo->exptime)) ||
4610 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4611 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4612 pinfo->flags)) ||
4613 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4614 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4615 pinfo->discovery_timeout)) ||
4616 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4617 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4618 pinfo->discovery_retries)))
4619 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004620
4621 nla_nest_end(msg, pinfoattr);
4622
Johannes Berg053c0952015-01-16 22:09:00 +01004623 genlmsg_end(msg, hdr);
4624 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004625
4626 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004627 genlmsg_cancel(msg, hdr);
4628 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004629}
4630
4631static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004632 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004633{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004634 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004635 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004636 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004637 u8 dst[ETH_ALEN];
4638 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004639 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004640 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004641
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004642 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004643 if (err)
4644 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004645
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004646 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004647 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004648 goto out_err;
4649 }
4650
Johannes Berg97990a02013-04-19 01:02:55 +02004651 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004652 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004653 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004654 }
4655
Johannes Bergbba95fe2008-07-29 13:22:51 +02004656 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004657 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004658 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004659 if (err == -ENOENT)
4660 break;
4661 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004662 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004663
Eric W. Biederman15e47302012-09-07 20:12:54 +00004664 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004665 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004666 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004667 &pinfo) < 0)
4668 goto out;
4669
4670 path_idx++;
4671 }
4672
4673
4674 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004675 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004676 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004677 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004678 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004679 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004680}
4681
4682static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4683{
Johannes Berg4c476992010-10-04 21:36:35 +02004684 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004685 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004686 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004687 struct mpath_info pinfo;
4688 struct sk_buff *msg;
4689 u8 *dst = NULL;
4690 u8 next_hop[ETH_ALEN];
4691
4692 memset(&pinfo, 0, sizeof(pinfo));
4693
4694 if (!info->attrs[NL80211_ATTR_MAC])
4695 return -EINVAL;
4696
4697 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4698
Johannes Berg4c476992010-10-04 21:36:35 +02004699 if (!rdev->ops->get_mpath)
4700 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004701
Johannes Berg4c476992010-10-04 21:36:35 +02004702 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4703 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004704
Hila Gonene35e4d22012-06-27 17:19:42 +03004705 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004706 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004707 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004708
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004709 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004710 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004711 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004712
Eric W. Biederman15e47302012-09-07 20:12:54 +00004713 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004714 dev, dst, next_hop, &pinfo) < 0) {
4715 nlmsg_free(msg);
4716 return -ENOBUFS;
4717 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004718
Johannes Berg4c476992010-10-04 21:36:35 +02004719 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004720}
4721
4722static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4723{
Johannes Berg4c476992010-10-04 21:36:35 +02004724 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4725 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004726 u8 *dst = NULL;
4727 u8 *next_hop = NULL;
4728
4729 if (!info->attrs[NL80211_ATTR_MAC])
4730 return -EINVAL;
4731
4732 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4733 return -EINVAL;
4734
4735 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4736 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4737
Johannes Berg4c476992010-10-04 21:36:35 +02004738 if (!rdev->ops->change_mpath)
4739 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004740
Johannes Berg4c476992010-10-04 21:36:35 +02004741 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4742 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004743
Hila Gonene35e4d22012-06-27 17:19:42 +03004744 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004745}
Johannes Berg4c476992010-10-04 21:36:35 +02004746
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004747static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4748{
Johannes Berg4c476992010-10-04 21:36:35 +02004749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4750 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004751 u8 *dst = NULL;
4752 u8 *next_hop = NULL;
4753
4754 if (!info->attrs[NL80211_ATTR_MAC])
4755 return -EINVAL;
4756
4757 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4758 return -EINVAL;
4759
4760 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4761 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4762
Johannes Berg4c476992010-10-04 21:36:35 +02004763 if (!rdev->ops->add_mpath)
4764 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004765
Johannes Berg4c476992010-10-04 21:36:35 +02004766 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4767 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004768
Hila Gonene35e4d22012-06-27 17:19:42 +03004769 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004770}
4771
4772static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4773{
Johannes Berg4c476992010-10-04 21:36:35 +02004774 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4775 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004776 u8 *dst = NULL;
4777
4778 if (info->attrs[NL80211_ATTR_MAC])
4779 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4780
Johannes Berg4c476992010-10-04 21:36:35 +02004781 if (!rdev->ops->del_mpath)
4782 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004783
Hila Gonene35e4d22012-06-27 17:19:42 +03004784 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004785}
4786
Henning Rogge66be7d22014-09-12 08:58:49 +02004787static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4788{
4789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4790 int err;
4791 struct net_device *dev = info->user_ptr[1];
4792 struct mpath_info pinfo;
4793 struct sk_buff *msg;
4794 u8 *dst = NULL;
4795 u8 mpp[ETH_ALEN];
4796
4797 memset(&pinfo, 0, sizeof(pinfo));
4798
4799 if (!info->attrs[NL80211_ATTR_MAC])
4800 return -EINVAL;
4801
4802 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4803
4804 if (!rdev->ops->get_mpp)
4805 return -EOPNOTSUPP;
4806
4807 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4808 return -EOPNOTSUPP;
4809
4810 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4811 if (err)
4812 return err;
4813
4814 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4815 if (!msg)
4816 return -ENOMEM;
4817
4818 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4819 dev, dst, mpp, &pinfo) < 0) {
4820 nlmsg_free(msg);
4821 return -ENOBUFS;
4822 }
4823
4824 return genlmsg_reply(msg, info);
4825}
4826
4827static int nl80211_dump_mpp(struct sk_buff *skb,
4828 struct netlink_callback *cb)
4829{
4830 struct mpath_info pinfo;
4831 struct cfg80211_registered_device *rdev;
4832 struct wireless_dev *wdev;
4833 u8 dst[ETH_ALEN];
4834 u8 mpp[ETH_ALEN];
4835 int path_idx = cb->args[2];
4836 int err;
4837
4838 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4839 if (err)
4840 return err;
4841
4842 if (!rdev->ops->dump_mpp) {
4843 err = -EOPNOTSUPP;
4844 goto out_err;
4845 }
4846
4847 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4848 err = -EOPNOTSUPP;
4849 goto out_err;
4850 }
4851
4852 while (1) {
4853 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4854 mpp, &pinfo);
4855 if (err == -ENOENT)
4856 break;
4857 if (err)
4858 goto out_err;
4859
4860 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4861 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4862 wdev->netdev, dst, mpp,
4863 &pinfo) < 0)
4864 goto out;
4865
4866 path_idx++;
4867 }
4868
4869 out:
4870 cb->args[2] = path_idx;
4871 err = skb->len;
4872 out_err:
4873 nl80211_finish_wdev_dump(rdev);
4874 return err;
4875}
4876
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004877static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4878{
Johannes Berg4c476992010-10-04 21:36:35 +02004879 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4880 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004881 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004882 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004883 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004884
4885 memset(&params, 0, sizeof(params));
4886 /* default to not changing parameters */
4887 params.use_cts_prot = -1;
4888 params.use_short_preamble = -1;
4889 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004890 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004891 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004892 params.p2p_ctwindow = -1;
4893 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004894
4895 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4896 params.use_cts_prot =
4897 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4898 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4899 params.use_short_preamble =
4900 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4901 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4902 params.use_short_slot_time =
4903 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004904 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4905 params.basic_rates =
4906 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4907 params.basic_rates_len =
4908 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4909 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004910 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4911 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004912 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4913 params.ht_opmode =
4914 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004915
Johannes Berg53cabad2012-11-14 15:17:28 +01004916 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4917 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4918 return -EINVAL;
4919 params.p2p_ctwindow =
4920 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4921 if (params.p2p_ctwindow < 0)
4922 return -EINVAL;
4923 if (params.p2p_ctwindow != 0 &&
4924 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4925 return -EINVAL;
4926 }
4927
4928 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4929 u8 tmp;
4930
4931 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4932 return -EINVAL;
4933 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4934 if (tmp > 1)
4935 return -EINVAL;
4936 params.p2p_opp_ps = tmp;
4937 if (params.p2p_opp_ps &&
4938 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4939 return -EINVAL;
4940 }
4941
Johannes Berg4c476992010-10-04 21:36:35 +02004942 if (!rdev->ops->change_bss)
4943 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004944
Johannes Berg074ac8d2010-09-16 14:58:22 +02004945 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004946 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4947 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004948
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004949 wdev_lock(wdev);
4950 err = rdev_change_bss(rdev, dev, &params);
4951 wdev_unlock(wdev);
4952
4953 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004954}
4955
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004956static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4957{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004958 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05004959 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004960 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05004961 u32 owner_nlportid;
4962
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004963
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004964 /*
4965 * You should only get this when cfg80211 hasn't yet initialized
4966 * completely when built-in to the kernel right between the time
4967 * window between nl80211_init() and regulatory_init(), if that is
4968 * even possible.
4969 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004970 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004971 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004972
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004973 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4974 user_reg_hint_type =
4975 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4976 else
4977 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4978
4979 switch (user_reg_hint_type) {
4980 case NL80211_USER_REG_HINT_USER:
4981 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004982 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4983 return -EINVAL;
4984
4985 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4986 return regulatory_hint_user(data, user_reg_hint_type);
4987 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05004988 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
4989 owner_nlportid = info->snd_portid;
4990 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
4991 } else {
4992 owner_nlportid = 0;
4993 is_indoor = true;
4994 }
4995
4996 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004997 default:
4998 return -EINVAL;
4999 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005000}
5001
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005002static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005003 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005004{
Johannes Berg4c476992010-10-04 21:36:35 +02005005 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005006 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005007 struct wireless_dev *wdev = dev->ieee80211_ptr;
5008 struct mesh_config cur_params;
5009 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005010 void *hdr;
5011 struct nlattr *pinfoattr;
5012 struct sk_buff *msg;
5013
Johannes Berg29cbe682010-12-03 09:20:44 +01005014 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5015 return -EOPNOTSUPP;
5016
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005017 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005018 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005019
Johannes Berg29cbe682010-12-03 09:20:44 +01005020 wdev_lock(wdev);
5021 /* If not connected, get default parameters */
5022 if (!wdev->mesh_id_len)
5023 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5024 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005025 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005026 wdev_unlock(wdev);
5027
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005028 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005029 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005030
5031 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005032 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005033 if (!msg)
5034 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005035 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005036 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005037 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005038 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005039 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005040 if (!pinfoattr)
5041 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005042 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5043 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5044 cur_params.dot11MeshRetryTimeout) ||
5045 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5046 cur_params.dot11MeshConfirmTimeout) ||
5047 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5048 cur_params.dot11MeshHoldingTimeout) ||
5049 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5050 cur_params.dot11MeshMaxPeerLinks) ||
5051 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5052 cur_params.dot11MeshMaxRetries) ||
5053 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5054 cur_params.dot11MeshTTL) ||
5055 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5056 cur_params.element_ttl) ||
5057 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5058 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005059 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5060 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005061 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5062 cur_params.dot11MeshHWMPmaxPREQretries) ||
5063 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5064 cur_params.path_refresh_time) ||
5065 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5066 cur_params.min_discovery_timeout) ||
5067 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5068 cur_params.dot11MeshHWMPactivePathTimeout) ||
5069 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5070 cur_params.dot11MeshHWMPpreqMinInterval) ||
5071 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5072 cur_params.dot11MeshHWMPperrMinInterval) ||
5073 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5074 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5075 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5076 cur_params.dot11MeshHWMPRootMode) ||
5077 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5078 cur_params.dot11MeshHWMPRannInterval) ||
5079 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5080 cur_params.dot11MeshGateAnnouncementProtocol) ||
5081 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5082 cur_params.dot11MeshForwarding) ||
5083 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005084 cur_params.rssi_threshold) ||
5085 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005086 cur_params.ht_opmode) ||
5087 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5088 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5089 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005090 cur_params.dot11MeshHWMProotInterval) ||
5091 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005092 cur_params.dot11MeshHWMPconfirmationInterval) ||
5093 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5094 cur_params.power_mode) ||
5095 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005096 cur_params.dot11MeshAwakeWindowDuration) ||
5097 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5098 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005099 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005100 nla_nest_end(msg, pinfoattr);
5101 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005102 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005103
Johannes Berg3b858752009-03-12 09:55:09 +01005104 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005105 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005106 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005107 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005108 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005109}
5110
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005111static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005112 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5113 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5114 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5115 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5116 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5117 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005118 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005119 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005120 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005121 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5122 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5123 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5124 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5125 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005126 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005127 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005128 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005129 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005130 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005131 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005132 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5133 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005134 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5135 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005136 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005137 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5138 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005139 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005140};
5141
Javier Cardonac80d5452010-12-16 17:37:49 -08005142static const struct nla_policy
5143 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005144 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005145 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5146 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005147 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005148 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005149 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005150 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005151 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005152 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005153};
5154
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005155static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005156 struct mesh_config *cfg,
5157 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005158{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005159 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005160 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005161
Marco Porschea54fba2013-01-07 16:04:48 +01005162#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5163do { \
5164 if (tb[attr]) { \
5165 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5166 return -EINVAL; \
5167 cfg->param = fn(tb[attr]); \
5168 mask |= (1 << (attr - 1)); \
5169 } \
5170} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005171
5172
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005173 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005174 return -EINVAL;
5175 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005176 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005177 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005178 return -EINVAL;
5179
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005180 /* This makes sure that there aren't more than 32 mesh config
5181 * parameters (otherwise our bitfield scheme would not work.) */
5182 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5183
5184 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005185 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005186 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5187 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005188 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005189 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5190 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005191 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005192 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5193 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005194 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005195 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5196 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005197 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005198 mask, NL80211_MESHCONF_MAX_RETRIES,
5199 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005200 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005201 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005202 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005203 mask, NL80211_MESHCONF_ELEMENT_TTL,
5204 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005205 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005206 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5207 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005208 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5209 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005210 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5211 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005212 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005213 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5214 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005215 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005216 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5217 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005219 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5220 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005221 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5222 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005223 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5224 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005225 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005226 1, 65535, mask,
5227 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005228 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005229 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005230 1, 65535, mask,
5231 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005232 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005233 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005234 dot11MeshHWMPnetDiameterTraversalTime,
5235 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005236 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5237 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005238 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5239 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5240 nla_get_u8);
5241 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5242 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005243 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005244 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005245 dot11MeshGateAnnouncementProtocol, 0, 1,
5246 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005247 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005248 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005249 mask, NL80211_MESHCONF_FORWARDING,
5250 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005251 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005252 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005253 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005254 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005255 mask, NL80211_MESHCONF_HT_OPMODE,
5256 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005257 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005258 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005259 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5260 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005261 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005262 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5263 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005264 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005265 dot11MeshHWMPconfirmationInterval,
5266 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005267 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5268 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005269 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5270 NL80211_MESH_POWER_ACTIVE,
5271 NL80211_MESH_POWER_MAX,
5272 mask, NL80211_MESHCONF_POWER_MODE,
5273 nla_get_u32);
5274 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5275 0, 65535, mask,
5276 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005277 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005278 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5279 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005280 if (mask_out)
5281 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005282
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005283 return 0;
5284
5285#undef FILL_IN_MESH_PARAM_IF_SET
5286}
5287
Javier Cardonac80d5452010-12-16 17:37:49 -08005288static int nl80211_parse_mesh_setup(struct genl_info *info,
5289 struct mesh_setup *setup)
5290{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005291 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005292 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5293
5294 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5295 return -EINVAL;
5296 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5297 info->attrs[NL80211_ATTR_MESH_SETUP],
5298 nl80211_mesh_setup_params_policy))
5299 return -EINVAL;
5300
Javier Cardonad299a1f2012-03-31 11:31:33 -07005301 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5302 setup->sync_method =
5303 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5304 IEEE80211_SYNC_METHOD_VENDOR :
5305 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5306
Javier Cardonac80d5452010-12-16 17:37:49 -08005307 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5308 setup->path_sel_proto =
5309 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5310 IEEE80211_PATH_PROTOCOL_VENDOR :
5311 IEEE80211_PATH_PROTOCOL_HWMP;
5312
5313 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5314 setup->path_metric =
5315 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5316 IEEE80211_PATH_METRIC_VENDOR :
5317 IEEE80211_PATH_METRIC_AIRTIME;
5318
Javier Cardona581a8b02011-04-07 15:08:27 -07005319
5320 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005321 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005322 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005323 if (!is_valid_ie_attr(ieattr))
5324 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005325 setup->ie = nla_data(ieattr);
5326 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005327 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005328 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5329 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5330 return -EINVAL;
5331 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005332 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5333 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005334 if (setup->is_secure)
5335 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005336
Colleen Twitty6e16d902013-05-08 11:45:59 -07005337 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5338 if (!setup->user_mpm)
5339 return -EINVAL;
5340 setup->auth_id =
5341 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5342 }
5343
Javier Cardonac80d5452010-12-16 17:37:49 -08005344 return 0;
5345}
5346
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005347static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005348 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005349{
5350 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5351 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005352 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005353 struct mesh_config cfg;
5354 u32 mask;
5355 int err;
5356
Johannes Berg29cbe682010-12-03 09:20:44 +01005357 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5358 return -EOPNOTSUPP;
5359
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005360 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005361 return -EOPNOTSUPP;
5362
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005363 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005364 if (err)
5365 return err;
5366
Johannes Berg29cbe682010-12-03 09:20:44 +01005367 wdev_lock(wdev);
5368 if (!wdev->mesh_id_len)
5369 err = -ENOLINK;
5370
5371 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005372 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005373
5374 wdev_unlock(wdev);
5375
5376 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005377}
5378
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005379static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5380 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005381{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005382 struct nlattr *nl_reg_rules;
5383 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005384
Johannes Berg458f4f92012-12-06 15:47:38 +01005385 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5386 (regdom->dfs_region &&
5387 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005388 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005389
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005390 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5391 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005392 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005393
Johannes Berg458f4f92012-12-06 15:47:38 +01005394 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005395 struct nlattr *nl_reg_rule;
5396 const struct ieee80211_reg_rule *reg_rule;
5397 const struct ieee80211_freq_range *freq_range;
5398 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005399 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005400
Johannes Berg458f4f92012-12-06 15:47:38 +01005401 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005402 freq_range = &reg_rule->freq_range;
5403 power_rule = &reg_rule->power_rule;
5404
5405 nl_reg_rule = nla_nest_start(msg, i);
5406 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005407 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005408
Janusz Dziedzic97524822014-01-30 09:52:20 +01005409 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5410 if (!max_bandwidth_khz)
5411 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5412 reg_rule);
5413
David S. Miller9360ffd2012-03-29 04:41:26 -04005414 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5415 reg_rule->flags) ||
5416 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5417 freq_range->start_freq_khz) ||
5418 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5419 freq_range->end_freq_khz) ||
5420 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005421 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005422 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5423 power_rule->max_antenna_gain) ||
5424 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005425 power_rule->max_eirp) ||
5426 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5427 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005428 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005429
5430 nla_nest_end(msg, nl_reg_rule);
5431 }
5432
5433 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005434 return 0;
5435
5436nla_put_failure:
5437 return -EMSGSIZE;
5438}
5439
5440static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5441{
5442 const struct ieee80211_regdomain *regdom = NULL;
5443 struct cfg80211_registered_device *rdev;
5444 struct wiphy *wiphy = NULL;
5445 struct sk_buff *msg;
5446 void *hdr;
5447
5448 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5449 if (!msg)
5450 return -ENOBUFS;
5451
5452 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5453 NL80211_CMD_GET_REG);
5454 if (!hdr)
5455 goto put_failure;
5456
5457 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005458 bool self_managed;
5459
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005460 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5461 if (IS_ERR(rdev)) {
5462 nlmsg_free(msg);
5463 return PTR_ERR(rdev);
5464 }
5465
5466 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005467 self_managed = wiphy->regulatory_flags &
5468 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005469 regdom = get_wiphy_regdom(wiphy);
5470
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005471 /* a self-managed-reg device must have a private regdom */
5472 if (WARN_ON(!regdom && self_managed)) {
5473 nlmsg_free(msg);
5474 return -EINVAL;
5475 }
5476
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005477 if (regdom &&
5478 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5479 goto nla_put_failure;
5480 }
5481
5482 if (!wiphy && reg_last_request_cell_base() &&
5483 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5484 NL80211_USER_REG_HINT_CELL_BASE))
5485 goto nla_put_failure;
5486
5487 rcu_read_lock();
5488
5489 if (!regdom)
5490 regdom = rcu_dereference(cfg80211_regdomain);
5491
5492 if (nl80211_put_regdom(regdom, msg))
5493 goto nla_put_failure_rcu;
5494
5495 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005496
5497 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005498 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005499
Johannes Berg458f4f92012-12-06 15:47:38 +01005500nla_put_failure_rcu:
5501 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005502nla_put_failure:
5503 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005504put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005505 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005506 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005507}
5508
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005509static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5510 u32 seq, int flags, struct wiphy *wiphy,
5511 const struct ieee80211_regdomain *regdom)
5512{
5513 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5514 NL80211_CMD_GET_REG);
5515
5516 if (!hdr)
5517 return -1;
5518
5519 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5520
5521 if (nl80211_put_regdom(regdom, msg))
5522 goto nla_put_failure;
5523
5524 if (!wiphy && reg_last_request_cell_base() &&
5525 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5526 NL80211_USER_REG_HINT_CELL_BASE))
5527 goto nla_put_failure;
5528
5529 if (wiphy &&
5530 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5531 goto nla_put_failure;
5532
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005533 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5534 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5535 goto nla_put_failure;
5536
Johannes Berg053c0952015-01-16 22:09:00 +01005537 genlmsg_end(msg, hdr);
5538 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005539
5540nla_put_failure:
5541 genlmsg_cancel(msg, hdr);
5542 return -EMSGSIZE;
5543}
5544
5545static int nl80211_get_reg_dump(struct sk_buff *skb,
5546 struct netlink_callback *cb)
5547{
5548 const struct ieee80211_regdomain *regdom = NULL;
5549 struct cfg80211_registered_device *rdev;
5550 int err, reg_idx, start = cb->args[2];
5551
5552 rtnl_lock();
5553
5554 if (cfg80211_regdomain && start == 0) {
5555 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5556 NLM_F_MULTI, NULL,
5557 rtnl_dereference(cfg80211_regdomain));
5558 if (err < 0)
5559 goto out_err;
5560 }
5561
5562 /* the global regdom is idx 0 */
5563 reg_idx = 1;
5564 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5565 regdom = get_wiphy_regdom(&rdev->wiphy);
5566 if (!regdom)
5567 continue;
5568
5569 if (++reg_idx <= start)
5570 continue;
5571
5572 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5573 NLM_F_MULTI, &rdev->wiphy, regdom);
5574 if (err < 0) {
5575 reg_idx--;
5576 break;
5577 }
5578 }
5579
5580 cb->args[2] = reg_idx;
5581 err = skb->len;
5582out_err:
5583 rtnl_unlock();
5584 return err;
5585}
5586
Johannes Bergb6863032015-10-15 09:25:18 +02005587#ifdef CONFIG_CFG80211_CRDA_SUPPORT
5588static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
5589 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
5590 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
5591 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
5592 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
5593 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
5594 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
5595 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
5596};
5597
5598static int parse_reg_rule(struct nlattr *tb[],
5599 struct ieee80211_reg_rule *reg_rule)
5600{
5601 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
5602 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
5603
5604 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
5605 return -EINVAL;
5606 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
5607 return -EINVAL;
5608 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
5609 return -EINVAL;
5610 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
5611 return -EINVAL;
5612 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
5613 return -EINVAL;
5614
5615 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
5616
5617 freq_range->start_freq_khz =
5618 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
5619 freq_range->end_freq_khz =
5620 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
5621 freq_range->max_bandwidth_khz =
5622 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
5623
5624 power_rule->max_eirp =
5625 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
5626
5627 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
5628 power_rule->max_antenna_gain =
5629 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
5630
5631 if (tb[NL80211_ATTR_DFS_CAC_TIME])
5632 reg_rule->dfs_cac_ms =
5633 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
5634
5635 return 0;
5636}
5637
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005638static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5639{
5640 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5641 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005642 char *alpha2;
5643 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005644 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005645 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005646 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005647
5648 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5649 return -EINVAL;
5650
5651 if (!info->attrs[NL80211_ATTR_REG_RULES])
5652 return -EINVAL;
5653
5654 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5655
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005656 if (info->attrs[NL80211_ATTR_DFS_REGION])
5657 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5658
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005659 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005660 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005661 num_rules++;
5662 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005663 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005664 }
5665
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005666 if (!reg_is_valid_request(alpha2))
5667 return -EINVAL;
5668
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005669 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005670 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005671
5672 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005673 if (!rd)
5674 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005675
5676 rd->n_reg_rules = num_rules;
5677 rd->alpha2[0] = alpha2[0];
5678 rd->alpha2[1] = alpha2[1];
5679
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005680 /*
5681 * Disable DFS master mode if the DFS region was
5682 * not supported or known on this kernel.
5683 */
5684 if (reg_supported_dfs_region(dfs_region))
5685 rd->dfs_region = dfs_region;
5686
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005687 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005688 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005689 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5690 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5691 reg_rule_policy);
5692 if (r)
5693 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005694 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5695 if (r)
5696 goto bad_reg;
5697
5698 rule_idx++;
5699
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005700 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5701 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005702 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005703 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005704 }
5705
Ilan peerc37722b2015-03-30 15:15:49 +03005706 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005707 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005708 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005709
Johannes Bergd2372b32008-10-24 20:32:20 +02005710 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005711 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005712 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005713}
Johannes Bergb6863032015-10-15 09:25:18 +02005714#endif /* CONFIG_CFG80211_CRDA_SUPPORT */
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005715
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005716static int validate_scan_freqs(struct nlattr *freqs)
5717{
5718 struct nlattr *attr1, *attr2;
5719 int n_channels = 0, tmp1, tmp2;
5720
5721 nla_for_each_nested(attr1, freqs, tmp1) {
5722 n_channels++;
5723 /*
5724 * Some hardware has a limited channel list for
5725 * scanning, and it is pretty much nonsensical
5726 * to scan for a channel twice, so disallow that
5727 * and don't require drivers to check that the
5728 * channel list they get isn't longer than what
5729 * they can scan, as long as they can scan all
5730 * the channels they registered at once.
5731 */
5732 nla_for_each_nested(attr2, freqs, tmp2)
5733 if (attr1 != attr2 &&
5734 nla_get_u32(attr1) == nla_get_u32(attr2))
5735 return 0;
5736 }
5737
5738 return n_channels;
5739}
5740
Johannes Bergad2b26a2014-06-12 21:39:05 +02005741static int nl80211_parse_random_mac(struct nlattr **attrs,
5742 u8 *mac_addr, u8 *mac_addr_mask)
5743{
5744 int i;
5745
5746 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005747 eth_zero_addr(mac_addr);
5748 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005749 mac_addr[0] = 0x2;
5750 mac_addr_mask[0] = 0x3;
5751
5752 return 0;
5753 }
5754
5755 /* need both or none */
5756 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5757 return -EINVAL;
5758
5759 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5760 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5761
5762 /* don't allow or configure an mcast address */
5763 if (!is_multicast_ether_addr(mac_addr_mask) ||
5764 is_multicast_ether_addr(mac_addr))
5765 return -EINVAL;
5766
5767 /*
5768 * allow users to pass a MAC address that has bits set outside
5769 * of the mask, but don't bother drivers with having to deal
5770 * with such bits
5771 */
5772 for (i = 0; i < ETH_ALEN; i++)
5773 mac_addr[i] &= mac_addr_mask[i];
5774
5775 return 0;
5776}
5777
Johannes Berg2a519312009-02-10 21:25:55 +01005778static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5779{
Johannes Berg4c476992010-10-04 21:36:35 +02005780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005781 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005782 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005783 struct nlattr *attr;
5784 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005785 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005786 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005787
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005788 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5789 return -EINVAL;
5790
Johannes Berg79c97e92009-07-07 03:56:12 +02005791 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005792
Johannes Berg4c476992010-10-04 21:36:35 +02005793 if (!rdev->ops->scan)
5794 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005795
Johannes Bergf9d15d12014-01-22 11:14:19 +02005796 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005797 err = -EBUSY;
5798 goto unlock;
5799 }
Johannes Berg2a519312009-02-10 21:25:55 +01005800
5801 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005802 n_channels = validate_scan_freqs(
5803 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005804 if (!n_channels) {
5805 err = -EINVAL;
5806 goto unlock;
5807 }
Johannes Berg2a519312009-02-10 21:25:55 +01005808 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005809 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005810 }
5811
5812 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5813 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5814 n_ssids++;
5815
Johannes Bergf9f47522013-03-19 15:04:07 +01005816 if (n_ssids > wiphy->max_scan_ssids) {
5817 err = -EINVAL;
5818 goto unlock;
5819 }
Johannes Berg2a519312009-02-10 21:25:55 +01005820
Jouni Malinen70692ad2009-02-16 19:39:13 +02005821 if (info->attrs[NL80211_ATTR_IE])
5822 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5823 else
5824 ie_len = 0;
5825
Johannes Bergf9f47522013-03-19 15:04:07 +01005826 if (ie_len > wiphy->max_scan_ie_len) {
5827 err = -EINVAL;
5828 goto unlock;
5829 }
Johannes Berg18a83652009-03-31 12:12:05 +02005830
Johannes Berg2a519312009-02-10 21:25:55 +01005831 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005832 + sizeof(*request->ssids) * n_ssids
5833 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005834 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005835 if (!request) {
5836 err = -ENOMEM;
5837 goto unlock;
5838 }
Johannes Berg2a519312009-02-10 21:25:55 +01005839
Johannes Berg2a519312009-02-10 21:25:55 +01005840 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005841 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005842 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005843 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005844 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005845 request->ie = (void *)(request->ssids + n_ssids);
5846 else
5847 request->ie = (void *)(request->channels + n_channels);
5848 }
Johannes Berg2a519312009-02-10 21:25:55 +01005849
Johannes Berg584991d2009-11-02 13:32:03 +01005850 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005851 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5852 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005853 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005854 struct ieee80211_channel *chan;
5855
5856 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5857
5858 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005859 err = -EINVAL;
5860 goto out_free;
5861 }
Johannes Berg584991d2009-11-02 13:32:03 +01005862
5863 /* ignore disabled channels */
5864 if (chan->flags & IEEE80211_CHAN_DISABLED)
5865 continue;
5866
5867 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005868 i++;
5869 }
5870 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005871 enum ieee80211_band band;
5872
Johannes Berg2a519312009-02-10 21:25:55 +01005873 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005874 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5875 int j;
5876 if (!wiphy->bands[band])
5877 continue;
5878 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005879 struct ieee80211_channel *chan;
5880
5881 chan = &wiphy->bands[band]->channels[j];
5882
5883 if (chan->flags & IEEE80211_CHAN_DISABLED)
5884 continue;
5885
5886 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005887 i++;
5888 }
5889 }
5890 }
5891
Johannes Berg584991d2009-11-02 13:32:03 +01005892 if (!i) {
5893 err = -EINVAL;
5894 goto out_free;
5895 }
5896
5897 request->n_channels = i;
5898
Johannes Berg2a519312009-02-10 21:25:55 +01005899 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005900 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005901 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005902 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005903 err = -EINVAL;
5904 goto out_free;
5905 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005906 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005907 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005908 i++;
5909 }
5910 }
5911
Jouni Malinen70692ad2009-02-16 19:39:13 +02005912 if (info->attrs[NL80211_ATTR_IE]) {
5913 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005914 memcpy((void *)request->ie,
5915 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005916 request->ie_len);
5917 }
5918
Johannes Berg34850ab2011-07-18 18:08:35 +02005919 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005920 if (wiphy->bands[i])
5921 request->rates[i] =
5922 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005923
5924 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5925 nla_for_each_nested(attr,
5926 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5927 tmp) {
5928 enum ieee80211_band band = nla_type(attr);
5929
Dan Carpenter84404622011-07-29 11:52:18 +03005930 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005931 err = -EINVAL;
5932 goto out_free;
5933 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005934
5935 if (!wiphy->bands[band])
5936 continue;
5937
Johannes Berg34850ab2011-07-18 18:08:35 +02005938 err = ieee80211_get_ratemask(wiphy->bands[band],
5939 nla_data(attr),
5940 nla_len(attr),
5941 &request->rates[band]);
5942 if (err)
5943 goto out_free;
5944 }
5945 }
5946
Sam Leffler46856bb2012-10-11 21:03:32 -07005947 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005948 request->flags = nla_get_u32(
5949 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005950 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5951 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005952 err = -EOPNOTSUPP;
5953 goto out_free;
5954 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005955
5956 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5957 if (!(wiphy->features &
5958 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5959 err = -EOPNOTSUPP;
5960 goto out_free;
5961 }
5962
5963 if (wdev->current_bss) {
5964 err = -EOPNOTSUPP;
5965 goto out_free;
5966 }
5967
5968 err = nl80211_parse_random_mac(info->attrs,
5969 request->mac_addr,
5970 request->mac_addr_mask);
5971 if (err)
5972 goto out_free;
5973 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005974 }
Sam Lefflered4737712012-10-11 21:03:31 -07005975
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305976 request->no_cck =
5977 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5978
Johannes Bergfd014282012-06-18 19:17:03 +02005979 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005980 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005981 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005982
Johannes Berg79c97e92009-07-07 03:56:12 +02005983 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005984 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005985
Johannes Berg463d0182009-07-14 00:33:35 +02005986 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005987 nl80211_send_scan_start(rdev, wdev);
5988 if (wdev->netdev)
5989 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005990 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005991 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005992 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005993 kfree(request);
5994 }
Johannes Berg3b858752009-03-12 09:55:09 +01005995
Johannes Bergf9f47522013-03-19 15:04:07 +01005996 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005997 return err;
5998}
5999
Avraham Stern3b06d272015-10-12 09:51:34 +03006000static int
6001nl80211_parse_sched_scan_plans(struct wiphy *wiphy, int n_plans,
6002 struct cfg80211_sched_scan_request *request,
6003 struct nlattr **attrs)
6004{
6005 int tmp, err, i = 0;
6006 struct nlattr *attr;
6007
6008 if (!attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6009 u32 interval;
6010
6011 /*
6012 * If scan plans are not specified,
6013 * %NL80211_ATTR_SCHED_SCAN_INTERVAL must be specified. In this
6014 * case one scan plan will be set with the specified scan
6015 * interval and infinite number of iterations.
6016 */
6017 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6018 return -EINVAL;
6019
6020 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
6021 if (!interval)
6022 return -EINVAL;
6023
6024 request->scan_plans[0].interval =
6025 DIV_ROUND_UP(interval, MSEC_PER_SEC);
6026 if (!request->scan_plans[0].interval)
6027 return -EINVAL;
6028
6029 if (request->scan_plans[0].interval >
6030 wiphy->max_sched_scan_plan_interval)
6031 request->scan_plans[0].interval =
6032 wiphy->max_sched_scan_plan_interval;
6033
6034 return 0;
6035 }
6036
6037 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp) {
6038 struct nlattr *plan[NL80211_SCHED_SCAN_PLAN_MAX + 1];
6039
6040 if (WARN_ON(i >= n_plans))
6041 return -EINVAL;
6042
6043 err = nla_parse(plan, NL80211_SCHED_SCAN_PLAN_MAX,
6044 nla_data(attr), nla_len(attr),
6045 nl80211_plan_policy);
6046 if (err)
6047 return err;
6048
6049 if (!plan[NL80211_SCHED_SCAN_PLAN_INTERVAL])
6050 return -EINVAL;
6051
6052 request->scan_plans[i].interval =
6053 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_INTERVAL]);
6054 if (!request->scan_plans[i].interval ||
6055 request->scan_plans[i].interval >
6056 wiphy->max_sched_scan_plan_interval)
6057 return -EINVAL;
6058
6059 if (plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]) {
6060 request->scan_plans[i].iterations =
6061 nla_get_u32(plan[NL80211_SCHED_SCAN_PLAN_ITERATIONS]);
6062 if (!request->scan_plans[i].iterations ||
6063 (request->scan_plans[i].iterations >
6064 wiphy->max_sched_scan_plan_iterations))
6065 return -EINVAL;
6066 } else if (i < n_plans - 1) {
6067 /*
6068 * All scan plans but the last one must specify
6069 * a finite number of iterations
6070 */
6071 return -EINVAL;
6072 }
6073
6074 i++;
6075 }
6076
6077 /*
6078 * The last scan plan must not specify the number of
6079 * iterations, it is supposed to run infinitely
6080 */
6081 if (request->scan_plans[n_plans - 1].iterations)
6082 return -EINVAL;
6083
6084 return 0;
6085}
6086
Luciano Coelho256da022014-11-10 16:13:46 +02006087static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02006088nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006089 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006090{
6091 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006092 struct nlattr *attr;
Avraham Stern3b06d272015-10-12 09:51:34 +03006093 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i, n_plans = 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006094 enum ieee80211_band band;
6095 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006096 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01006097 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006098
Luciano Coelho256da022014-11-10 16:13:46 +02006099 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
6100 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006101
Luciano Coelho256da022014-11-10 16:13:46 +02006102 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006103 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006104 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006105 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006106 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006107 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006108 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006109 }
6110
Luciano Coelho256da022014-11-10 16:13:46 +02006111 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6112 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006113 tmp)
6114 n_ssids++;
6115
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006116 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006117 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006118
Johannes Bergea73cbc2014-01-24 10:53:53 +01006119 /*
6120 * First, count the number of 'real' matchsets. Due to an issue with
6121 * the old implementation, matchsets containing only the RSSI attribute
6122 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6123 * RSSI for all matchsets, rather than their own matchset for reporting
6124 * all APs with a strong RSSI. This is needed to be compatible with
6125 * older userspace that treated a matchset with only the RSSI as the
6126 * global RSSI for all other matchsets - if there are other matchsets.
6127 */
Luciano Coelho256da022014-11-10 16:13:46 +02006128 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006129 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006130 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006131 tmp) {
6132 struct nlattr *rssi;
6133
6134 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6135 nla_data(attr), nla_len(attr),
6136 nl80211_match_policy);
6137 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006138 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006139 /* add other standalone attributes here */
6140 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6141 n_match_sets++;
6142 continue;
6143 }
6144 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6145 if (rssi)
6146 default_match_rssi = nla_get_s32(rssi);
6147 }
6148 }
6149
6150 /* However, if there's no other matchset, add the RSSI one */
6151 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6152 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006153
6154 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006155 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006156
Luciano Coelho256da022014-11-10 16:13:46 +02006157 if (attrs[NL80211_ATTR_IE])
6158 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006159 else
6160 ie_len = 0;
6161
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006162 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006163 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006164
Avraham Stern3b06d272015-10-12 09:51:34 +03006165 if (attrs[NL80211_ATTR_SCHED_SCAN_PLANS]) {
6166 /*
6167 * NL80211_ATTR_SCHED_SCAN_INTERVAL must not be specified since
6168 * each scan plan already specifies its own interval
6169 */
6170 if (attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6171 return ERR_PTR(-EINVAL);
6172
6173 nla_for_each_nested(attr,
6174 attrs[NL80211_ATTR_SCHED_SCAN_PLANS], tmp)
6175 n_plans++;
6176 } else {
6177 /*
6178 * The scan interval attribute is kept for backward
6179 * compatibility. If no scan plans are specified and sched scan
6180 * interval is specified, one scan plan will be set with this
6181 * scan interval and infinite number of iterations.
6182 */
6183 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
6184 return ERR_PTR(-EINVAL);
6185
6186 n_plans = 1;
6187 }
6188
6189 if (!n_plans || n_plans > wiphy->max_sched_scan_plans)
6190 return ERR_PTR(-EINVAL);
6191
Luciano Coelho807f8a82011-05-11 17:09:35 +03006192 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006193 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006194 + sizeof(*request->match_sets) * n_match_sets
Avraham Stern3b06d272015-10-12 09:51:34 +03006195 + sizeof(*request->scan_plans) * n_plans
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006196 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006197 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006198 if (!request)
6199 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006200
6201 if (n_ssids)
6202 request->ssids = (void *)&request->channels[n_channels];
6203 request->n_ssids = n_ssids;
6204 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006205 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006206 request->ie = (void *)(request->ssids + n_ssids);
6207 else
6208 request->ie = (void *)(request->channels + n_channels);
6209 }
6210
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006211 if (n_match_sets) {
6212 if (request->ie)
6213 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006214 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006215 request->match_sets =
6216 (void *)(request->ssids + n_ssids);
6217 else
6218 request->match_sets =
6219 (void *)(request->channels + n_channels);
6220 }
6221 request->n_match_sets = n_match_sets;
6222
Avraham Stern3b06d272015-10-12 09:51:34 +03006223 if (n_match_sets)
6224 request->scan_plans = (void *)(request->match_sets +
6225 n_match_sets);
6226 else if (request->ie)
6227 request->scan_plans = (void *)(request->ie + ie_len);
6228 else if (n_ssids)
6229 request->scan_plans = (void *)(request->ssids + n_ssids);
6230 else
6231 request->scan_plans = (void *)(request->channels + n_channels);
6232
6233 request->n_scan_plans = n_plans;
6234
Luciano Coelho807f8a82011-05-11 17:09:35 +03006235 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006236 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006237 /* user specified, bail out if channel not found */
6238 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006239 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006240 tmp) {
6241 struct ieee80211_channel *chan;
6242
6243 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6244
6245 if (!chan) {
6246 err = -EINVAL;
6247 goto out_free;
6248 }
6249
6250 /* ignore disabled channels */
6251 if (chan->flags & IEEE80211_CHAN_DISABLED)
6252 continue;
6253
6254 request->channels[i] = chan;
6255 i++;
6256 }
6257 } else {
6258 /* all channels */
6259 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6260 int j;
6261 if (!wiphy->bands[band])
6262 continue;
6263 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6264 struct ieee80211_channel *chan;
6265
6266 chan = &wiphy->bands[band]->channels[j];
6267
6268 if (chan->flags & IEEE80211_CHAN_DISABLED)
6269 continue;
6270
6271 request->channels[i] = chan;
6272 i++;
6273 }
6274 }
6275 }
6276
6277 if (!i) {
6278 err = -EINVAL;
6279 goto out_free;
6280 }
6281
6282 request->n_channels = i;
6283
6284 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006285 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006286 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006287 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006288 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006289 err = -EINVAL;
6290 goto out_free;
6291 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006292 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006293 memcpy(request->ssids[i].ssid, nla_data(attr),
6294 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006295 i++;
6296 }
6297 }
6298
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006299 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006300 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006301 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006302 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006303 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006304 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006305
Johannes Bergae811e22014-01-24 10:17:47 +01006306 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6307 nla_data(attr), nla_len(attr),
6308 nl80211_match_policy);
6309 if (err)
6310 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006311 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006312 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006313 if (WARN_ON(i >= n_match_sets)) {
6314 /* this indicates a programming error,
6315 * the loop above should have verified
6316 * things properly
6317 */
6318 err = -EINVAL;
6319 goto out_free;
6320 }
6321
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006322 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6323 err = -EINVAL;
6324 goto out_free;
6325 }
6326 memcpy(request->match_sets[i].ssid.ssid,
6327 nla_data(ssid), nla_len(ssid));
6328 request->match_sets[i].ssid.ssid_len =
6329 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006330 /* special attribute - old implemenation w/a */
6331 request->match_sets[i].rssi_thold =
6332 default_match_rssi;
6333 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6334 if (rssi)
6335 request->match_sets[i].rssi_thold =
6336 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006337 }
6338 i++;
6339 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006340
6341 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006342 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006343 request->match_sets[0].rssi_thold = default_match_rssi;
6344
6345 request->min_rssi_thold = INT_MAX;
6346 for (i = 0; i < n_match_sets; i++)
6347 request->min_rssi_thold =
6348 min(request->match_sets[i].rssi_thold,
6349 request->min_rssi_thold);
6350 } else {
6351 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006352 }
6353
Johannes Berg9900e482014-02-04 21:01:25 +01006354 if (ie_len) {
6355 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006356 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006357 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006358 request->ie_len);
6359 }
6360
Luciano Coelho256da022014-11-10 16:13:46 +02006361 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006362 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006363 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006364 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6365 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006366 err = -EOPNOTSUPP;
6367 goto out_free;
6368 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006369
6370 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6371 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6372
6373 if (!wdev) /* must be net-detect */
6374 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6375
6376 if (!(wiphy->features & flg)) {
6377 err = -EOPNOTSUPP;
6378 goto out_free;
6379 }
6380
6381 if (wdev && wdev->current_bss) {
6382 err = -EOPNOTSUPP;
6383 goto out_free;
6384 }
6385
6386 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6387 request->mac_addr_mask);
6388 if (err)
6389 goto out_free;
6390 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006391 }
Sam Lefflered4737712012-10-11 21:03:31 -07006392
Luciano Coelho9c748932015-01-16 16:04:09 +02006393 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6394 request->delay =
6395 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6396
Avraham Stern3b06d272015-10-12 09:51:34 +03006397 err = nl80211_parse_sched_scan_plans(wiphy, n_plans, request, attrs);
6398 if (err)
6399 goto out_free;
6400
Sam Leffler15d60302012-10-11 21:03:34 -07006401 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006402
Luciano Coelho256da022014-11-10 16:13:46 +02006403 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006404
6405out_free:
6406 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006407 return ERR_PTR(err);
6408}
6409
6410static int nl80211_start_sched_scan(struct sk_buff *skb,
6411 struct genl_info *info)
6412{
6413 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6414 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006415 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006416 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006417 int err;
6418
6419 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6420 !rdev->ops->sched_scan_start)
6421 return -EOPNOTSUPP;
6422
6423 if (rdev->sched_scan_req)
6424 return -EINPROGRESS;
6425
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006426 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6427 info->attrs);
6428
6429 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006430 if (err)
6431 goto out_err;
6432
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006433 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006434 if (err)
6435 goto out_free;
6436
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006437 sched_scan_req->dev = dev;
6438 sched_scan_req->wiphy = &rdev->wiphy;
6439
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006440 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6441 sched_scan_req->owner_nlportid = info->snd_portid;
6442
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006443 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006444
6445 nl80211_send_sched_scan(rdev, dev,
6446 NL80211_CMD_START_SCHED_SCAN);
6447 return 0;
6448
6449out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006450 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006451out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006452 return err;
6453}
6454
6455static int nl80211_stop_sched_scan(struct sk_buff *skb,
6456 struct genl_info *info)
6457{
6458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6459
6460 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6461 !rdev->ops->sched_scan_stop)
6462 return -EOPNOTSUPP;
6463
Johannes Berg5fe231e2013-05-08 21:45:15 +02006464 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006465}
6466
Simon Wunderlich04f39042013-02-08 18:16:19 +01006467static int nl80211_start_radar_detection(struct sk_buff *skb,
6468 struct genl_info *info)
6469{
6470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6471 struct net_device *dev = info->user_ptr[1];
6472 struct wireless_dev *wdev = dev->ieee80211_ptr;
6473 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006474 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006475 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006476 int err;
6477
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006478 dfs_region = reg_get_dfs_region(wdev->wiphy);
6479 if (dfs_region == NL80211_DFS_UNSET)
6480 return -EINVAL;
6481
Simon Wunderlich04f39042013-02-08 18:16:19 +01006482 err = nl80211_parse_chandef(rdev, info, &chandef);
6483 if (err)
6484 return err;
6485
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006486 if (netif_carrier_ok(dev))
6487 return -EBUSY;
6488
Simon Wunderlich04f39042013-02-08 18:16:19 +01006489 if (wdev->cac_started)
6490 return -EBUSY;
6491
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006492 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006493 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006494 if (err < 0)
6495 return err;
6496
6497 if (err == 0)
6498 return -EINVAL;
6499
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006500 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006501 return -EINVAL;
6502
6503 if (!rdev->ops->start_radar_detection)
6504 return -EOPNOTSUPP;
6505
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006506 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6507 if (WARN_ON(!cac_time_ms))
6508 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6509
6510 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6511 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006512 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006513 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006514 wdev->cac_started = true;
6515 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006516 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006517 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006518 return err;
6519}
6520
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006521static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6522{
6523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6524 struct net_device *dev = info->user_ptr[1];
6525 struct wireless_dev *wdev = dev->ieee80211_ptr;
6526 struct cfg80211_csa_settings params;
6527 /* csa_attrs is defined static to avoid waste of stack size - this
6528 * function is called under RTNL lock, so this should not be a problem.
6529 */
6530 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006531 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006532 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006533 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006534 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006535
6536 if (!rdev->ops->channel_switch ||
6537 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6538 return -EOPNOTSUPP;
6539
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006540 switch (dev->ieee80211_ptr->iftype) {
6541 case NL80211_IFTYPE_AP:
6542 case NL80211_IFTYPE_P2P_GO:
6543 need_new_beacon = true;
6544
6545 /* useless if AP is not running */
6546 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006547 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006548 break;
6549 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006550 if (!wdev->ssid_len)
6551 return -ENOTCONN;
6552 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006553 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006554 if (!wdev->mesh_id_len)
6555 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006556 break;
6557 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006558 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006559 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006560
6561 memset(&params, 0, sizeof(params));
6562
6563 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6564 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6565 return -EINVAL;
6566
6567 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006568 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006569 return -EINVAL;
6570
Luciano Coelho252e07c2014-10-08 09:48:34 +03006571 /* Even though the attribute is u32, the specification says
6572 * u8, so let's make sure we don't overflow.
6573 */
6574 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6575 if (cs_count > 255)
6576 return -EINVAL;
6577
6578 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006579
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006580 if (!need_new_beacon)
6581 goto skip_beacons;
6582
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006583 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6584 if (err)
6585 return err;
6586
6587 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6588 info->attrs[NL80211_ATTR_CSA_IES],
6589 nl80211_policy);
6590 if (err)
6591 return err;
6592
6593 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6594 if (err)
6595 return err;
6596
6597 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6598 return -EINVAL;
6599
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006600 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6601 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006602 return -EINVAL;
6603
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006604 params.n_counter_offsets_beacon = len / sizeof(u16);
6605 if (rdev->wiphy.max_num_csa_counters &&
6606 (params.n_counter_offsets_beacon >
6607 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006608 return -EINVAL;
6609
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006610 params.counter_offsets_beacon =
6611 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6612
6613 /* sanity checks - counters should fit and be the same */
6614 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6615 u16 offset = params.counter_offsets_beacon[i];
6616
6617 if (offset >= params.beacon_csa.tail_len)
6618 return -EINVAL;
6619
6620 if (params.beacon_csa.tail[offset] != params.count)
6621 return -EINVAL;
6622 }
6623
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006624 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006625 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6626 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006627 return -EINVAL;
6628
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006629 params.n_counter_offsets_presp = len / sizeof(u16);
6630 if (rdev->wiphy.max_num_csa_counters &&
6631 (params.n_counter_offsets_beacon >
6632 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006633 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006634
6635 params.counter_offsets_presp =
6636 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6637
6638 /* sanity checks - counters should fit and be the same */
6639 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6640 u16 offset = params.counter_offsets_presp[i];
6641
6642 if (offset >= params.beacon_csa.probe_resp_len)
6643 return -EINVAL;
6644
6645 if (params.beacon_csa.probe_resp[offset] !=
6646 params.count)
6647 return -EINVAL;
6648 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006649 }
6650
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006651skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006652 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6653 if (err)
6654 return err;
6655
Arik Nemtsov923b3522015-07-08 15:41:44 +03006656 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6657 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006658 return -EINVAL;
6659
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006660 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6661 &params.chandef,
6662 wdev->iftype);
6663 if (err < 0)
6664 return err;
6665
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006666 if (err > 0)
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006667 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006668
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006669 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6670 params.block_tx = true;
6671
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006672 wdev_lock(wdev);
6673 err = rdev_channel_switch(rdev, dev, &params);
6674 wdev_unlock(wdev);
6675
6676 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006677}
6678
Johannes Berg9720bb32011-06-21 09:45:33 +02006679static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6680 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006681 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006682 struct wireless_dev *wdev,
6683 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006684{
Johannes Berg48ab9052009-07-10 18:42:31 +02006685 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006686 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006687 void *hdr;
6688 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006689
6690 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006691
Eric W. Biederman15e47302012-09-07 20:12:54 +00006692 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006693 NL80211_CMD_NEW_SCAN_RESULTS);
6694 if (!hdr)
6695 return -1;
6696
Johannes Berg9720bb32011-06-21 09:45:33 +02006697 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6698
Johannes Berg97990a02013-04-19 01:02:55 +02006699 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6700 goto nla_put_failure;
6701 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006702 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6703 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006704 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6705 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006706
6707 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6708 if (!bss)
6709 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006710 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006711 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006712 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006713
6714 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006715 /* indicate whether we have probe response data or not */
6716 if (rcu_access_pointer(res->proberesp_ies) &&
6717 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6718 goto fail_unlock_rcu;
6719
6720 /* this pointer prefers to be pointed to probe response data
6721 * but is always valid
6722 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006723 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006724 if (ies) {
6725 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6726 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006727 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6728 ies->len, ies->data))
6729 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006730 }
Johannes Berg0e227082014-08-12 20:34:30 +02006731
6732 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006733 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006734 if (ies && ies->from_beacon) {
6735 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006736 goto fail_unlock_rcu;
6737 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6738 ies->len, ies->data))
6739 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006740 }
6741 rcu_read_unlock();
6742
David S. Miller9360ffd2012-03-29 04:41:26 -04006743 if (res->beacon_interval &&
6744 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6745 goto nla_put_failure;
6746 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6747 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006748 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006749 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6750 jiffies_to_msecs(jiffies - intbss->ts)))
6751 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006752
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006753 if (intbss->ts_boottime &&
6754 nla_put_u64(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6755 intbss->ts_boottime))
6756 goto nla_put_failure;
6757
Johannes Berg77965c92009-02-18 18:45:06 +01006758 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006759 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006760 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6761 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006762 break;
6763 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006764 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6765 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006766 break;
6767 default:
6768 break;
6769 }
6770
Johannes Berg48ab9052009-07-10 18:42:31 +02006771 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006772 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006773 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006774 if (intbss == wdev->current_bss &&
6775 nla_put_u32(msg, NL80211_BSS_STATUS,
6776 NL80211_BSS_STATUS_ASSOCIATED))
6777 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006778 break;
6779 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006780 if (intbss == wdev->current_bss &&
6781 nla_put_u32(msg, NL80211_BSS_STATUS,
6782 NL80211_BSS_STATUS_IBSS_JOINED))
6783 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006784 break;
6785 default:
6786 break;
6787 }
6788
Johannes Berg2a519312009-02-10 21:25:55 +01006789 nla_nest_end(msg, bss);
6790
Johannes Berg053c0952015-01-16 22:09:00 +01006791 genlmsg_end(msg, hdr);
6792 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006793
Johannes Berg8cef2c92013-02-05 16:54:31 +01006794 fail_unlock_rcu:
6795 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006796 nla_put_failure:
6797 genlmsg_cancel(msg, hdr);
6798 return -EMSGSIZE;
6799}
6800
Johannes Berg97990a02013-04-19 01:02:55 +02006801static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006802{
Johannes Berg48ab9052009-07-10 18:42:31 +02006803 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006804 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006805 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006806 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006807 int err;
6808
Johannes Berg97990a02013-04-19 01:02:55 +02006809 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006810 if (err)
6811 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006812
Johannes Berg48ab9052009-07-10 18:42:31 +02006813 wdev_lock(wdev);
6814 spin_lock_bh(&rdev->bss_lock);
6815 cfg80211_bss_expire(rdev);
6816
Johannes Berg9720bb32011-06-21 09:45:33 +02006817 cb->seq = rdev->bss_generation;
6818
Johannes Berg48ab9052009-07-10 18:42:31 +02006819 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006820 if (++idx <= start)
6821 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006822 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006823 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006824 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006825 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006826 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006827 }
6828 }
6829
Johannes Berg48ab9052009-07-10 18:42:31 +02006830 spin_unlock_bh(&rdev->bss_lock);
6831 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006832
Johannes Berg97990a02013-04-19 01:02:55 +02006833 cb->args[2] = idx;
6834 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006835
Johannes Berg67748892010-10-04 21:14:06 +02006836 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006837}
6838
Eric W. Biederman15e47302012-09-07 20:12:54 +00006839static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006840 int flags, struct net_device *dev,
6841 bool allow_radio_stats,
6842 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006843{
6844 void *hdr;
6845 struct nlattr *infoattr;
6846
Johannes Berg11f78ac2014-11-14 16:43:50 +01006847 /* skip radio stats if userspace didn't request them */
6848 if (!survey->channel && !allow_radio_stats)
6849 return 0;
6850
Eric W. Biederman15e47302012-09-07 20:12:54 +00006851 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006852 NL80211_CMD_NEW_SURVEY_RESULTS);
6853 if (!hdr)
6854 return -ENOMEM;
6855
David S. Miller9360ffd2012-03-29 04:41:26 -04006856 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6857 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006858
6859 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6860 if (!infoattr)
6861 goto nla_put_failure;
6862
Johannes Berg11f78ac2014-11-14 16:43:50 +01006863 if (survey->channel &&
6864 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006865 survey->channel->center_freq))
6866 goto nla_put_failure;
6867
6868 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6869 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6870 goto nla_put_failure;
6871 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6872 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6873 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006874 if ((survey->filled & SURVEY_INFO_TIME) &&
6875 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6876 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006877 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006878 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6879 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6880 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006881 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006882 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6883 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6884 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006885 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006886 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6887 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6888 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006889 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006890 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6891 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6892 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006893 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006894 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6895 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6896 survey->time_scan))
6897 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006898
6899 nla_nest_end(msg, infoattr);
6900
Johannes Berg053c0952015-01-16 22:09:00 +01006901 genlmsg_end(msg, hdr);
6902 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006903
6904 nla_put_failure:
6905 genlmsg_cancel(msg, hdr);
6906 return -EMSGSIZE;
6907}
6908
Johannes Berg11f78ac2014-11-14 16:43:50 +01006909static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006910{
6911 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006912 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006913 struct wireless_dev *wdev;
6914 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006915 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006916 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006917
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006918 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006919 if (res)
6920 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006921
Johannes Berg11f78ac2014-11-14 16:43:50 +01006922 /* prepare_wdev_dump parsed the attributes */
6923 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6924
Johannes Berg97990a02013-04-19 01:02:55 +02006925 if (!wdev->netdev) {
6926 res = -EINVAL;
6927 goto out_err;
6928 }
6929
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006930 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006931 res = -EOPNOTSUPP;
6932 goto out_err;
6933 }
6934
6935 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006936 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006937 if (res == -ENOENT)
6938 break;
6939 if (res)
6940 goto out_err;
6941
Johannes Berg11f78ac2014-11-14 16:43:50 +01006942 /* don't send disabled channels, but do send non-channel data */
6943 if (survey.channel &&
6944 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006945 survey_idx++;
6946 continue;
6947 }
6948
Holger Schurig61fa7132009-11-11 12:25:40 +01006949 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006950 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006951 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006952 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006953 goto out;
6954 survey_idx++;
6955 }
6956
6957 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006958 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006959 res = skb->len;
6960 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006961 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006962 return res;
6963}
6964
Samuel Ortizb23aa672009-07-01 21:26:54 +02006965static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6966{
6967 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6968 NL80211_WPA_VERSION_2));
6969}
6970
Jouni Malinen636a5d32009-03-19 13:39:22 +02006971static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6972{
Johannes Berg4c476992010-10-04 21:36:35 +02006973 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6974 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006975 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006976 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6977 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006978 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006979 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006980 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006981
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006982 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6983 return -EINVAL;
6984
6985 if (!info->attrs[NL80211_ATTR_MAC])
6986 return -EINVAL;
6987
Jouni Malinen17780922009-03-27 20:52:47 +02006988 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6989 return -EINVAL;
6990
Johannes Berg19957bb2009-07-02 17:20:43 +02006991 if (!info->attrs[NL80211_ATTR_SSID])
6992 return -EINVAL;
6993
6994 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6995 return -EINVAL;
6996
Johannes Bergfffd0932009-07-08 14:22:54 +02006997 err = nl80211_parse_key(info, &key);
6998 if (err)
6999 return err;
7000
7001 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02007002 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
7003 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02007004 if (!key.p.key || !key.p.key_len)
7005 return -EINVAL;
7006 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
7007 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
7008 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
7009 key.p.key_len != WLAN_KEY_LEN_WEP104))
7010 return -EINVAL;
7011 if (key.idx > 4)
7012 return -EINVAL;
7013 } else {
7014 key.p.key_len = 0;
7015 key.p.key = NULL;
7016 }
7017
Johannes Bergafea0b72010-08-10 09:46:42 +02007018 if (key.idx >= 0) {
7019 int i;
7020 bool ok = false;
7021 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
7022 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
7023 ok = true;
7024 break;
7025 }
7026 }
Johannes Berg4c476992010-10-04 21:36:35 +02007027 if (!ok)
7028 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02007029 }
7030
Johannes Berg4c476992010-10-04 21:36:35 +02007031 if (!rdev->ops->auth)
7032 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007033
Johannes Berg074ac8d2010-09-16 14:58:22 +02007034 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007035 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7036 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007037
Johannes Berg19957bb2009-07-02 17:20:43 +02007038 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02007039 chan = nl80211_get_valid_chan(&rdev->wiphy,
7040 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7041 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007042 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007043
Johannes Berg19957bb2009-07-02 17:20:43 +02007044 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7045 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7046
7047 if (info->attrs[NL80211_ATTR_IE]) {
7048 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7049 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7050 }
7051
7052 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007053 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02007054 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02007055
Jouni Malinene39e5b52012-09-30 19:29:39 +03007056 if (auth_type == NL80211_AUTHTYPE_SAE &&
7057 !info->attrs[NL80211_ATTR_SAE_DATA])
7058 return -EINVAL;
7059
7060 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
7061 if (auth_type != NL80211_AUTHTYPE_SAE)
7062 return -EINVAL;
7063 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
7064 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
7065 /* need to include at least Auth Transaction and Status Code */
7066 if (sae_data_len < 4)
7067 return -EINVAL;
7068 }
7069
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007070 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7071
Johannes Berg95de8172012-01-20 13:55:25 +01007072 /*
7073 * Since we no longer track auth state, ignore
7074 * requests to only change local state.
7075 */
7076 if (local_state_change)
7077 return 0;
7078
Johannes Berg91bf9b22013-05-15 17:44:01 +02007079 wdev_lock(dev->ieee80211_ptr);
7080 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
7081 ssid, ssid_len, ie, ie_len,
7082 key.p.key, key.p.key_len, key.idx,
7083 sae_data, sae_data_len);
7084 wdev_unlock(dev->ieee80211_ptr);
7085 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007086}
7087
Johannes Bergc0692b82010-08-27 14:26:53 +03007088static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
7089 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007090 struct cfg80211_crypto_settings *settings,
7091 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007092{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02007093 memset(settings, 0, sizeof(*settings));
7094
Samuel Ortizb23aa672009-07-01 21:26:54 +02007095 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
7096
Johannes Bergc0692b82010-08-27 14:26:53 +03007097 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
7098 u16 proto;
7099 proto = nla_get_u16(
7100 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
7101 settings->control_port_ethertype = cpu_to_be16(proto);
7102 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
7103 proto != ETH_P_PAE)
7104 return -EINVAL;
7105 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
7106 settings->control_port_no_encrypt = true;
7107 } else
7108 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
7109
Samuel Ortizb23aa672009-07-01 21:26:54 +02007110 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
7111 void *data;
7112 int len, i;
7113
7114 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7115 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
7116 settings->n_ciphers_pairwise = len / sizeof(u32);
7117
7118 if (len % sizeof(u32))
7119 return -EINVAL;
7120
Johannes Berg3dc27d22009-07-02 21:36:37 +02007121 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02007122 return -EINVAL;
7123
7124 memcpy(settings->ciphers_pairwise, data, len);
7125
7126 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007127 if (!cfg80211_supported_cipher_suite(
7128 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02007129 settings->ciphers_pairwise[i]))
7130 return -EINVAL;
7131 }
7132
7133 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
7134 settings->cipher_group =
7135 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03007136 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
7137 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007138 return -EINVAL;
7139 }
7140
7141 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
7142 settings->wpa_versions =
7143 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
7144 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7145 return -EINVAL;
7146 }
7147
7148 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7149 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007150 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007151
7152 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7153 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7154 settings->n_akm_suites = len / sizeof(u32);
7155
7156 if (len % sizeof(u32))
7157 return -EINVAL;
7158
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007159 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7160 return -EINVAL;
7161
Samuel Ortizb23aa672009-07-01 21:26:54 +02007162 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007163 }
7164
7165 return 0;
7166}
7167
Jouni Malinen636a5d32009-03-19 13:39:22 +02007168static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7169{
Johannes Berg4c476992010-10-04 21:36:35 +02007170 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7171 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007172 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007173 struct cfg80211_assoc_request req = {};
7174 const u8 *bssid, *ssid;
7175 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007176
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007177 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7178 return -EINVAL;
7179
7180 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007181 !info->attrs[NL80211_ATTR_SSID] ||
7182 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007183 return -EINVAL;
7184
Johannes Berg4c476992010-10-04 21:36:35 +02007185 if (!rdev->ops->assoc)
7186 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007187
Johannes Berg074ac8d2010-09-16 14:58:22 +02007188 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007189 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7190 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007191
Johannes Berg19957bb2009-07-02 17:20:43 +02007192 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007193
Jouni Malinen664834d2014-01-15 00:01:44 +02007194 chan = nl80211_get_valid_chan(&rdev->wiphy,
7195 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7196 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007197 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007198
Johannes Berg19957bb2009-07-02 17:20:43 +02007199 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7200 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007201
7202 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007203 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7204 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007205 }
7206
Jouni Malinendc6382c2009-05-06 22:09:37 +03007207 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007208 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007209 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007210 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007211 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007212 else if (mfp != NL80211_MFP_NO)
7213 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007214 }
7215
Johannes Berg3e5d7642009-07-07 14:37:26 +02007216 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007217 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007218
Ben Greear7e7c8922011-11-18 11:31:59 -08007219 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007220 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007221
7222 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007223 memcpy(&req.ht_capa_mask,
7224 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7225 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007226
7227 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007228 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007229 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007230 memcpy(&req.ht_capa,
7231 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7232 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007233 }
7234
Johannes Bergee2aca32013-02-21 17:36:01 +01007235 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007236 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007237
7238 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007239 memcpy(&req.vht_capa_mask,
7240 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7241 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007242
7243 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007244 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007245 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007246 memcpy(&req.vht_capa,
7247 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7248 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007249 }
7250
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007251 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7252 if (!(rdev->wiphy.features &
7253 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7254 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7255 return -EINVAL;
7256 req.flags |= ASSOC_REQ_USE_RRM;
7257 }
7258
Johannes Bergf62fab72013-02-21 20:09:09 +01007259 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007260 if (!err) {
7261 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007262 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7263 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007264 wdev_unlock(dev->ieee80211_ptr);
7265 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007266
Jouni Malinen636a5d32009-03-19 13:39:22 +02007267 return err;
7268}
7269
7270static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7271{
Johannes Berg4c476992010-10-04 21:36:35 +02007272 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7273 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007274 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007275 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007276 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007277 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007278
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007279 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7280 return -EINVAL;
7281
7282 if (!info->attrs[NL80211_ATTR_MAC])
7283 return -EINVAL;
7284
7285 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7286 return -EINVAL;
7287
Johannes Berg4c476992010-10-04 21:36:35 +02007288 if (!rdev->ops->deauth)
7289 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007290
Johannes Berg074ac8d2010-09-16 14:58:22 +02007291 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007292 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7293 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007294
Johannes Berg19957bb2009-07-02 17:20:43 +02007295 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007296
Johannes Berg19957bb2009-07-02 17:20:43 +02007297 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7298 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007299 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007300 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007301 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007302
7303 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007304 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7305 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007306 }
7307
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007308 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7309
Johannes Berg91bf9b22013-05-15 17:44:01 +02007310 wdev_lock(dev->ieee80211_ptr);
7311 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7312 local_state_change);
7313 wdev_unlock(dev->ieee80211_ptr);
7314 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007315}
7316
7317static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7318{
Johannes Berg4c476992010-10-04 21:36:35 +02007319 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7320 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007321 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007322 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007323 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007324 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007325
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007326 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7327 return -EINVAL;
7328
7329 if (!info->attrs[NL80211_ATTR_MAC])
7330 return -EINVAL;
7331
7332 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7333 return -EINVAL;
7334
Johannes Berg4c476992010-10-04 21:36:35 +02007335 if (!rdev->ops->disassoc)
7336 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007337
Johannes Berg074ac8d2010-09-16 14:58:22 +02007338 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007339 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7340 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007341
Johannes Berg19957bb2009-07-02 17:20:43 +02007342 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007343
Johannes Berg19957bb2009-07-02 17:20:43 +02007344 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7345 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007346 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007347 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007348 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007349
7350 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007351 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7352 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007353 }
7354
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007355 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7356
Johannes Berg91bf9b22013-05-15 17:44:01 +02007357 wdev_lock(dev->ieee80211_ptr);
7358 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7359 local_state_change);
7360 wdev_unlock(dev->ieee80211_ptr);
7361 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007362}
7363
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007364static bool
7365nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7366 int mcast_rate[IEEE80211_NUM_BANDS],
7367 int rateval)
7368{
7369 struct wiphy *wiphy = &rdev->wiphy;
7370 bool found = false;
7371 int band, i;
7372
7373 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7374 struct ieee80211_supported_band *sband;
7375
7376 sband = wiphy->bands[band];
7377 if (!sband)
7378 continue;
7379
7380 for (i = 0; i < sband->n_bitrates; i++) {
7381 if (sband->bitrates[i].bitrate == rateval) {
7382 mcast_rate[band] = i + 1;
7383 found = true;
7384 break;
7385 }
7386 }
7387 }
7388
7389 return found;
7390}
7391
Johannes Berg04a773a2009-04-19 21:24:32 +02007392static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7393{
Johannes Berg4c476992010-10-04 21:36:35 +02007394 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7395 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007396 struct cfg80211_ibss_params ibss;
7397 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007398 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007399 int err;
7400
Johannes Berg8e30bc52009-04-22 17:45:38 +02007401 memset(&ibss, 0, sizeof(ibss));
7402
Johannes Berg04a773a2009-04-19 21:24:32 +02007403 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7404 return -EINVAL;
7405
Johannes Berg683b6d32012-11-08 21:25:48 +01007406 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007407 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7408 return -EINVAL;
7409
Johannes Berg8e30bc52009-04-22 17:45:38 +02007410 ibss.beacon_interval = 100;
7411
7412 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7413 ibss.beacon_interval =
7414 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7415 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7416 return -EINVAL;
7417 }
7418
Johannes Berg4c476992010-10-04 21:36:35 +02007419 if (!rdev->ops->join_ibss)
7420 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007421
Johannes Berg4c476992010-10-04 21:36:35 +02007422 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7423 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007424
Johannes Berg79c97e92009-07-07 03:56:12 +02007425 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007426
Johannes Berg39193492011-09-16 13:45:25 +02007427 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007428 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007429
7430 if (!is_valid_ether_addr(ibss.bssid))
7431 return -EINVAL;
7432 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007433 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7434 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7435
7436 if (info->attrs[NL80211_ATTR_IE]) {
7437 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7438 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7439 }
7440
Johannes Berg683b6d32012-11-08 21:25:48 +01007441 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7442 if (err)
7443 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007444
Ilan Peer174e0cd2014-02-23 09:13:01 +02007445 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7446 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007447 return -EINVAL;
7448
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007449 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007450 case NL80211_CHAN_WIDTH_5:
7451 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007452 case NL80211_CHAN_WIDTH_20_NOHT:
7453 break;
7454 case NL80211_CHAN_WIDTH_20:
7455 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007456 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7457 return -EINVAL;
7458 break;
7459 case NL80211_CHAN_WIDTH_80:
7460 case NL80211_CHAN_WIDTH_80P80:
7461 case NL80211_CHAN_WIDTH_160:
7462 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7463 return -EINVAL;
7464 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7465 NL80211_EXT_FEATURE_VHT_IBSS))
7466 return -EINVAL;
7467 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007468 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007469 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007470 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007471
Johannes Berg04a773a2009-04-19 21:24:32 +02007472 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007473 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007474
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007475 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7476 u8 *rates =
7477 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7478 int n_rates =
7479 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7480 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007481 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007482
Johannes Berg34850ab2011-07-18 18:08:35 +02007483 err = ieee80211_get_ratemask(sband, rates, n_rates,
7484 &ibss.basic_rates);
7485 if (err)
7486 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007487 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007488
Simon Wunderlich803768f2013-06-28 10:39:58 +02007489 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7490 memcpy(&ibss.ht_capa_mask,
7491 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7492 sizeof(ibss.ht_capa_mask));
7493
7494 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7495 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7496 return -EINVAL;
7497 memcpy(&ibss.ht_capa,
7498 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7499 sizeof(ibss.ht_capa));
7500 }
7501
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007502 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7503 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7504 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7505 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007506
Johannes Berg4c476992010-10-04 21:36:35 +02007507 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307508 bool no_ht = false;
7509
Johannes Berg4c476992010-10-04 21:36:35 +02007510 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307511 info->attrs[NL80211_ATTR_KEYS],
7512 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007513 if (IS_ERR(connkeys))
7514 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307515
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007516 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7517 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307518 kfree(connkeys);
7519 return -EINVAL;
7520 }
Johannes Berg4c476992010-10-04 21:36:35 +02007521 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007522
Antonio Quartulli267335d2012-01-31 20:25:47 +01007523 ibss.control_port =
7524 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7525
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007526 ibss.userspace_handles_dfs =
7527 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7528
Johannes Berg4c476992010-10-04 21:36:35 +02007529 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007530 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007531 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007532 return err;
7533}
7534
7535static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7536{
Johannes Berg4c476992010-10-04 21:36:35 +02007537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7538 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007539
Johannes Berg4c476992010-10-04 21:36:35 +02007540 if (!rdev->ops->leave_ibss)
7541 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007542
Johannes Berg4c476992010-10-04 21:36:35 +02007543 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7544 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007545
Johannes Berg4c476992010-10-04 21:36:35 +02007546 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007547}
7548
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007549static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7550{
7551 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7552 struct net_device *dev = info->user_ptr[1];
7553 int mcast_rate[IEEE80211_NUM_BANDS];
7554 u32 nla_rate;
7555 int err;
7556
7557 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007558 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7559 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007560 return -EOPNOTSUPP;
7561
7562 if (!rdev->ops->set_mcast_rate)
7563 return -EOPNOTSUPP;
7564
7565 memset(mcast_rate, 0, sizeof(mcast_rate));
7566
7567 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7568 return -EINVAL;
7569
7570 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7571 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7572 return -EINVAL;
7573
7574 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7575
7576 return err;
7577}
7578
Johannes Bergad7e7182013-11-13 13:37:47 +01007579static struct sk_buff *
7580__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007581 struct wireless_dev *wdev, int approxlen,
7582 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007583 enum nl80211_attrs attr,
7584 const struct nl80211_vendor_cmd_info *info,
7585 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007586{
7587 struct sk_buff *skb;
7588 void *hdr;
7589 struct nlattr *data;
7590
7591 skb = nlmsg_new(approxlen + 100, gfp);
7592 if (!skb)
7593 return NULL;
7594
7595 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7596 if (!hdr) {
7597 kfree_skb(skb);
7598 return NULL;
7599 }
7600
7601 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7602 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007603
7604 if (info) {
7605 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7606 info->vendor_id))
7607 goto nla_put_failure;
7608 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7609 info->subcmd))
7610 goto nla_put_failure;
7611 }
7612
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007613 if (wdev) {
7614 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7615 wdev_id(wdev)))
7616 goto nla_put_failure;
7617 if (wdev->netdev &&
7618 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7619 wdev->netdev->ifindex))
7620 goto nla_put_failure;
7621 }
7622
Johannes Bergad7e7182013-11-13 13:37:47 +01007623 data = nla_nest_start(skb, attr);
7624
7625 ((void **)skb->cb)[0] = rdev;
7626 ((void **)skb->cb)[1] = hdr;
7627 ((void **)skb->cb)[2] = data;
7628
7629 return skb;
7630
7631 nla_put_failure:
7632 kfree_skb(skb);
7633 return NULL;
7634}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007635
Johannes Berge03ad6e2014-01-01 17:22:30 +01007636struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007637 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007638 enum nl80211_commands cmd,
7639 enum nl80211_attrs attr,
7640 int vendor_event_idx,
7641 int approxlen, gfp_t gfp)
7642{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007643 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007644 const struct nl80211_vendor_cmd_info *info;
7645
7646 switch (cmd) {
7647 case NL80211_CMD_TESTMODE:
7648 if (WARN_ON(vendor_event_idx != -1))
7649 return NULL;
7650 info = NULL;
7651 break;
7652 case NL80211_CMD_VENDOR:
7653 if (WARN_ON(vendor_event_idx < 0 ||
7654 vendor_event_idx >= wiphy->n_vendor_events))
7655 return NULL;
7656 info = &wiphy->vendor_events[vendor_event_idx];
7657 break;
7658 default:
7659 WARN_ON(1);
7660 return NULL;
7661 }
7662
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007663 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007664 cmd, attr, info, gfp);
7665}
7666EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7667
7668void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7669{
7670 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7671 void *hdr = ((void **)skb->cb)[1];
7672 struct nlattr *data = ((void **)skb->cb)[2];
7673 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7674
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007675 /* clear CB data for netlink core to own from now on */
7676 memset(skb->cb, 0, sizeof(skb->cb));
7677
Johannes Berge03ad6e2014-01-01 17:22:30 +01007678 nla_nest_end(skb, data);
7679 genlmsg_end(skb, hdr);
7680
7681 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7682 mcgrp = NL80211_MCGRP_VENDOR;
7683
7684 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7685 mcgrp, gfp);
7686}
7687EXPORT_SYMBOL(__cfg80211_send_event_skb);
7688
Johannes Bergaff89a92009-07-01 21:26:51 +02007689#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007690static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7691{
Johannes Berg4c476992010-10-04 21:36:35 +02007692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007693 struct wireless_dev *wdev =
7694 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007695 int err;
7696
David Spinadelfc73f112013-07-31 18:04:15 +03007697 if (!rdev->ops->testmode_cmd)
7698 return -EOPNOTSUPP;
7699
7700 if (IS_ERR(wdev)) {
7701 err = PTR_ERR(wdev);
7702 if (err != -EINVAL)
7703 return err;
7704 wdev = NULL;
7705 } else if (wdev->wiphy != &rdev->wiphy) {
7706 return -EINVAL;
7707 }
7708
Johannes Bergaff89a92009-07-01 21:26:51 +02007709 if (!info->attrs[NL80211_ATTR_TESTDATA])
7710 return -EINVAL;
7711
Johannes Bergad7e7182013-11-13 13:37:47 +01007712 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007713 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007714 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7715 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007716 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007717
Johannes Bergaff89a92009-07-01 21:26:51 +02007718 return err;
7719}
7720
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007721static int nl80211_testmode_dump(struct sk_buff *skb,
7722 struct netlink_callback *cb)
7723{
Johannes Berg00918d32011-12-13 17:22:05 +01007724 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007725 int err;
7726 long phy_idx;
7727 void *data = NULL;
7728 int data_len = 0;
7729
Johannes Berg5fe231e2013-05-08 21:45:15 +02007730 rtnl_lock();
7731
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007732 if (cb->args[0]) {
7733 /*
7734 * 0 is a valid index, but not valid for args[0],
7735 * so we need to offset by 1.
7736 */
7737 phy_idx = cb->args[0] - 1;
7738 } else {
7739 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7740 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7741 nl80211_policy);
7742 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007743 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007744
Johannes Berg2bd7e352012-06-15 14:23:16 +02007745 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7746 nl80211_fam.attrbuf);
7747 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007748 err = PTR_ERR(rdev);
7749 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007750 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007751 phy_idx = rdev->wiphy_idx;
7752 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007753
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007754 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7755 cb->args[1] =
7756 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7757 }
7758
7759 if (cb->args[1]) {
7760 data = nla_data((void *)cb->args[1]);
7761 data_len = nla_len((void *)cb->args[1]);
7762 }
7763
Johannes Berg00918d32011-12-13 17:22:05 +01007764 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7765 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007766 err = -ENOENT;
7767 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007768 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007769
Johannes Berg00918d32011-12-13 17:22:05 +01007770 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007771 err = -EOPNOTSUPP;
7772 goto out_err;
7773 }
7774
7775 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007776 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007777 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7778 NL80211_CMD_TESTMODE);
7779 struct nlattr *tmdata;
7780
Dan Carpentercb35fba2013-08-14 14:50:01 +03007781 if (!hdr)
7782 break;
7783
David S. Miller9360ffd2012-03-29 04:41:26 -04007784 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007785 genlmsg_cancel(skb, hdr);
7786 break;
7787 }
7788
7789 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7790 if (!tmdata) {
7791 genlmsg_cancel(skb, hdr);
7792 break;
7793 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007794 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007795 nla_nest_end(skb, tmdata);
7796
7797 if (err == -ENOBUFS || err == -ENOENT) {
7798 genlmsg_cancel(skb, hdr);
7799 break;
7800 } else if (err) {
7801 genlmsg_cancel(skb, hdr);
7802 goto out_err;
7803 }
7804
7805 genlmsg_end(skb, hdr);
7806 }
7807
7808 err = skb->len;
7809 /* see above */
7810 cb->args[0] = phy_idx + 1;
7811 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007812 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007813 return err;
7814}
Johannes Bergaff89a92009-07-01 21:26:51 +02007815#endif
7816
Samuel Ortizb23aa672009-07-01 21:26:54 +02007817static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7818{
Johannes Berg4c476992010-10-04 21:36:35 +02007819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7820 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007821 struct cfg80211_connect_params connect;
7822 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007823 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007824 int err;
7825
7826 memset(&connect, 0, sizeof(connect));
7827
7828 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7829 return -EINVAL;
7830
7831 if (!info->attrs[NL80211_ATTR_SSID] ||
7832 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7833 return -EINVAL;
7834
7835 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7836 connect.auth_type =
7837 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007838 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7839 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007840 return -EINVAL;
7841 } else
7842 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7843
7844 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7845
Johannes Bergc0692b82010-08-27 14:26:53 +03007846 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007847 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007848 if (err)
7849 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007850
Johannes Berg074ac8d2010-09-16 14:58:22 +02007851 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007852 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7853 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007854
Johannes Berg79c97e92009-07-07 03:56:12 +02007855 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007856
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307857 connect.bg_scan_period = -1;
7858 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7859 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7860 connect.bg_scan_period =
7861 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7862 }
7863
Samuel Ortizb23aa672009-07-01 21:26:54 +02007864 if (info->attrs[NL80211_ATTR_MAC])
7865 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007866 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7867 connect.bssid_hint =
7868 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007869 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7870 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7871
7872 if (info->attrs[NL80211_ATTR_IE]) {
7873 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7874 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7875 }
7876
Jouni Malinencee00a92013-01-15 17:15:57 +02007877 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7878 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7879 if (connect.mfp != NL80211_MFP_REQUIRED &&
7880 connect.mfp != NL80211_MFP_NO)
7881 return -EINVAL;
7882 } else {
7883 connect.mfp = NL80211_MFP_NO;
7884 }
7885
Samuel Ortizb23aa672009-07-01 21:26:54 +02007886 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007887 connect.channel = nl80211_get_valid_chan(
7888 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7889 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007890 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007891 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007892 connect.channel_hint = nl80211_get_valid_chan(
7893 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7894 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007895 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007896 }
7897
Johannes Bergfffd0932009-07-08 14:22:54 +02007898 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7899 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307900 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007901 if (IS_ERR(connkeys))
7902 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007903 }
7904
Ben Greear7e7c8922011-11-18 11:31:59 -08007905 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7906 connect.flags |= ASSOC_REQ_DISABLE_HT;
7907
7908 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7909 memcpy(&connect.ht_capa_mask,
7910 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7911 sizeof(connect.ht_capa_mask));
7912
7913 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007914 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007915 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007916 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007917 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007918 memcpy(&connect.ht_capa,
7919 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7920 sizeof(connect.ht_capa));
7921 }
7922
Johannes Bergee2aca32013-02-21 17:36:01 +01007923 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7924 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7925
7926 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7927 memcpy(&connect.vht_capa_mask,
7928 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7929 sizeof(connect.vht_capa_mask));
7930
7931 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7932 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007933 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007934 return -EINVAL;
7935 }
7936 memcpy(&connect.vht_capa,
7937 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7938 sizeof(connect.vht_capa));
7939 }
7940
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007941 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7942 if (!(rdev->wiphy.features &
7943 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7944 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7945 return -EINVAL;
7946 connect.flags |= ASSOC_REQ_USE_RRM;
7947 }
7948
Johannes Berg83739b02013-05-15 17:44:01 +02007949 wdev_lock(dev->ieee80211_ptr);
7950 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7951 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007952 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007953 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007954 return err;
7955}
7956
7957static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7958{
Johannes Berg4c476992010-10-04 21:36:35 +02007959 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7960 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007961 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007962 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007963
7964 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7965 reason = WLAN_REASON_DEAUTH_LEAVING;
7966 else
7967 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7968
7969 if (reason == 0)
7970 return -EINVAL;
7971
Johannes Berg074ac8d2010-09-16 14:58:22 +02007972 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007973 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7974 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007975
Johannes Berg83739b02013-05-15 17:44:01 +02007976 wdev_lock(dev->ieee80211_ptr);
7977 ret = cfg80211_disconnect(rdev, dev, reason, true);
7978 wdev_unlock(dev->ieee80211_ptr);
7979 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007980}
7981
Johannes Berg463d0182009-07-14 00:33:35 +02007982static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7983{
Johannes Berg4c476992010-10-04 21:36:35 +02007984 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007985 struct net *net;
7986 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007987
Vadim Kochan4b681c82015-01-12 16:34:05 +02007988 if (info->attrs[NL80211_ATTR_PID]) {
7989 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7990
7991 net = get_net_ns_by_pid(pid);
7992 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7993 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7994
7995 net = get_net_ns_by_fd(fd);
7996 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007997 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007998 }
Johannes Berg463d0182009-07-14 00:33:35 +02007999
Johannes Berg4c476992010-10-04 21:36:35 +02008000 if (IS_ERR(net))
8001 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008002
8003 err = 0;
8004
8005 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02008006 if (!net_eq(wiphy_net(&rdev->wiphy), net))
8007 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02008008
Johannes Berg463d0182009-07-14 00:33:35 +02008009 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02008010 return err;
8011}
8012
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008013static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
8014{
Johannes Berg4c476992010-10-04 21:36:35 +02008015 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008016 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
8017 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02008018 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008019 struct cfg80211_pmksa pmksa;
8020
8021 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
8022
8023 if (!info->attrs[NL80211_ATTR_MAC])
8024 return -EINVAL;
8025
8026 if (!info->attrs[NL80211_ATTR_PMKID])
8027 return -EINVAL;
8028
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008029 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
8030 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
8031
Johannes Berg074ac8d2010-09-16 14:58:22 +02008032 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008033 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8034 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008035
8036 switch (info->genlhdr->cmd) {
8037 case NL80211_CMD_SET_PMKSA:
8038 rdev_ops = rdev->ops->set_pmksa;
8039 break;
8040 case NL80211_CMD_DEL_PMKSA:
8041 rdev_ops = rdev->ops->del_pmksa;
8042 break;
8043 default:
8044 WARN_ON(1);
8045 break;
8046 }
8047
Johannes Berg4c476992010-10-04 21:36:35 +02008048 if (!rdev_ops)
8049 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008050
Johannes Berg4c476992010-10-04 21:36:35 +02008051 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008052}
8053
8054static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
8055{
Johannes Berg4c476992010-10-04 21:36:35 +02008056 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8057 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008058
Johannes Berg074ac8d2010-09-16 14:58:22 +02008059 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008060 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
8061 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008062
Johannes Berg4c476992010-10-04 21:36:35 +02008063 if (!rdev->ops->flush_pmksa)
8064 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008065
Hila Gonene35e4d22012-06-27 17:19:42 +03008066 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01008067}
8068
Arik Nemtsov109086c2011-09-28 14:12:50 +03008069static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
8070{
8071 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8072 struct net_device *dev = info->user_ptr[1];
8073 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308074 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008075 u16 status_code;
8076 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008077 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03008078
8079 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8080 !rdev->ops->tdls_mgmt)
8081 return -EOPNOTSUPP;
8082
8083 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
8084 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
8085 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
8086 !info->attrs[NL80211_ATTR_IE] ||
8087 !info->attrs[NL80211_ATTR_MAC])
8088 return -EINVAL;
8089
8090 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8091 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
8092 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
8093 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008094 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308095 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
8096 peer_capability =
8097 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008098
Hila Gonene35e4d22012-06-27 17:19:42 +03008099 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05308100 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03008101 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03008102 nla_data(info->attrs[NL80211_ATTR_IE]),
8103 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03008104}
8105
8106static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
8107{
8108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8109 struct net_device *dev = info->user_ptr[1];
8110 enum nl80211_tdls_operation operation;
8111 u8 *peer;
8112
8113 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
8114 !rdev->ops->tdls_oper)
8115 return -EOPNOTSUPP;
8116
8117 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
8118 !info->attrs[NL80211_ATTR_MAC])
8119 return -EINVAL;
8120
8121 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
8122 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
8123
Hila Gonene35e4d22012-06-27 17:19:42 +03008124 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03008125}
8126
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008127static int nl80211_remain_on_channel(struct sk_buff *skb,
8128 struct genl_info *info)
8129{
Johannes Berg4c476992010-10-04 21:36:35 +02008130 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008131 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008132 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008133 struct sk_buff *msg;
8134 void *hdr;
8135 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01008136 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008137 int err;
8138
8139 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
8140 !info->attrs[NL80211_ATTR_DURATION])
8141 return -EINVAL;
8142
8143 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
8144
Johannes Berg7c4ef712011-11-18 15:33:48 +01008145 if (!rdev->ops->remain_on_channel ||
8146 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008147 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008148
Johannes Bergebf348f2012-06-01 12:50:54 +02008149 /*
8150 * We should be on that channel for at least a minimum amount of
8151 * time (10ms) but no longer than the driver supports.
8152 */
8153 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8154 duration > rdev->wiphy.max_remain_on_channel_duration)
8155 return -EINVAL;
8156
Johannes Berg683b6d32012-11-08 21:25:48 +01008157 err = nl80211_parse_chandef(rdev, info, &chandef);
8158 if (err)
8159 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008160
8161 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008162 if (!msg)
8163 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008164
Eric W. Biederman15e47302012-09-07 20:12:54 +00008165 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008166 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008167 if (!hdr) {
8168 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008169 goto free_msg;
8170 }
8171
Johannes Berg683b6d32012-11-08 21:25:48 +01008172 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8173 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008174
8175 if (err)
8176 goto free_msg;
8177
David S. Miller9360ffd2012-03-29 04:41:26 -04008178 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8179 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008180
8181 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008182
8183 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008184
8185 nla_put_failure:
8186 err = -ENOBUFS;
8187 free_msg:
8188 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008189 return err;
8190}
8191
8192static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8193 struct genl_info *info)
8194{
Johannes Berg4c476992010-10-04 21:36:35 +02008195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008196 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008197 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008198
8199 if (!info->attrs[NL80211_ATTR_COOKIE])
8200 return -EINVAL;
8201
Johannes Berg4c476992010-10-04 21:36:35 +02008202 if (!rdev->ops->cancel_remain_on_channel)
8203 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008204
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008205 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8206
Hila Gonene35e4d22012-06-27 17:19:42 +03008207 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008208}
8209
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008210static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8211 u8 *rates, u8 rates_len)
8212{
8213 u8 i;
8214 u32 mask = 0;
8215
8216 for (i = 0; i < rates_len; i++) {
8217 int rate = (rates[i] & 0x7f) * 5;
8218 int ridx;
8219 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8220 struct ieee80211_rate *srate =
8221 &sband->bitrates[ridx];
8222 if (rate == srate->bitrate) {
8223 mask |= 1 << ridx;
8224 break;
8225 }
8226 }
8227 if (ridx == sband->n_bitrates)
8228 return 0; /* rate not found */
8229 }
8230
8231 return mask;
8232}
8233
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008234static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8235 u8 *rates, u8 rates_len,
8236 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8237{
8238 u8 i;
8239
8240 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8241
8242 for (i = 0; i < rates_len; i++) {
8243 int ridx, rbit;
8244
8245 ridx = rates[i] / 8;
8246 rbit = BIT(rates[i] % 8);
8247
8248 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008249 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008250 return false;
8251
8252 /* check availability */
8253 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8254 mcs[ridx] |= rbit;
8255 else
8256 return false;
8257 }
8258
8259 return true;
8260}
8261
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008262static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8263{
8264 u16 mcs_mask = 0;
8265
8266 switch (vht_mcs_map) {
8267 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8268 break;
8269 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8270 mcs_mask = 0x00FF;
8271 break;
8272 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8273 mcs_mask = 0x01FF;
8274 break;
8275 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8276 mcs_mask = 0x03FF;
8277 break;
8278 default:
8279 break;
8280 }
8281
8282 return mcs_mask;
8283}
8284
8285static void vht_build_mcs_mask(u16 vht_mcs_map,
8286 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8287{
8288 u8 nss;
8289
8290 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8291 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8292 vht_mcs_map >>= 2;
8293 }
8294}
8295
8296static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8297 struct nl80211_txrate_vht *txrate,
8298 u16 mcs[NL80211_VHT_NSS_MAX])
8299{
8300 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8301 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8302 u8 i;
8303
8304 if (!sband->vht_cap.vht_supported)
8305 return false;
8306
8307 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8308
8309 /* Build vht_mcs_mask from VHT capabilities */
8310 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8311
8312 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8313 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8314 mcs[i] = txrate->mcs[i];
8315 else
8316 return false;
8317 }
8318
8319 return true;
8320}
8321
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008322static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008323 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8324 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008325 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8326 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008327 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008328 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008329};
8330
8331static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8332 struct genl_info *info)
8333{
8334 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008335 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008336 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008337 int rem, i;
8338 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008339 struct nlattr *tx_rates;
8340 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008341 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008342
Johannes Berg4c476992010-10-04 21:36:35 +02008343 if (!rdev->ops->set_bitrate_mask)
8344 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008345
8346 memset(&mask, 0, sizeof(mask));
8347 /* Default to all rates enabled */
8348 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8349 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008350
8351 if (!sband)
8352 continue;
8353
8354 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008355 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008356 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008357 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008358
8359 if (!sband->vht_cap.vht_supported)
8360 continue;
8361
8362 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8363 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008364 }
8365
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008366 /* if no rates are given set it back to the defaults */
8367 if (!info->attrs[NL80211_ATTR_TX_RATES])
8368 goto out;
8369
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008370 /*
8371 * The nested attribute uses enum nl80211_band as the index. This maps
8372 * directly to the enum ieee80211_band values used in cfg80211.
8373 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008374 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008375 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008376 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008377 int err;
8378
Johannes Berg4c476992010-10-04 21:36:35 +02008379 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8380 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008381 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008382 if (sband == NULL)
8383 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008384 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8385 nla_len(tx_rates), nl80211_txattr_policy);
8386 if (err)
8387 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008388 if (tb[NL80211_TXRATE_LEGACY]) {
8389 mask.control[band].legacy = rateset_to_mask(
8390 sband,
8391 nla_data(tb[NL80211_TXRATE_LEGACY]),
8392 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308393 if ((mask.control[band].legacy == 0) &&
8394 nla_len(tb[NL80211_TXRATE_LEGACY]))
8395 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008396 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008397 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008398 if (!ht_rateset_to_mask(
8399 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008400 nla_data(tb[NL80211_TXRATE_HT]),
8401 nla_len(tb[NL80211_TXRATE_HT]),
8402 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008403 return -EINVAL;
8404 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008405 if (tb[NL80211_TXRATE_VHT]) {
8406 if (!vht_set_mcs_mask(
8407 sband,
8408 nla_data(tb[NL80211_TXRATE_VHT]),
8409 mask.control[band].vht_mcs))
8410 return -EINVAL;
8411 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008412 if (tb[NL80211_TXRATE_GI]) {
8413 mask.control[band].gi =
8414 nla_get_u8(tb[NL80211_TXRATE_GI]);
8415 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8416 return -EINVAL;
8417 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008418
8419 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008420 /* don't allow empty legacy rates if HT or VHT
8421 * are not even supported.
8422 */
8423 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8424 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008425 return -EINVAL;
8426
8427 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008428 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008429 goto out;
8430
8431 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8432 if (mask.control[band].vht_mcs[i])
8433 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008434
8435 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008436 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008437 }
8438 }
8439
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008440out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008441 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008442}
8443
Johannes Berg2e161f72010-08-12 15:38:38 +02008444static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008445{
Johannes Berg4c476992010-10-04 21:36:35 +02008446 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008447 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008448 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008449
8450 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8451 return -EINVAL;
8452
Johannes Berg2e161f72010-08-12 15:38:38 +02008453 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8454 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008455
Johannes Berg71bbc992012-06-15 15:30:18 +02008456 switch (wdev->iftype) {
8457 case NL80211_IFTYPE_STATION:
8458 case NL80211_IFTYPE_ADHOC:
8459 case NL80211_IFTYPE_P2P_CLIENT:
8460 case NL80211_IFTYPE_AP:
8461 case NL80211_IFTYPE_AP_VLAN:
8462 case NL80211_IFTYPE_MESH_POINT:
8463 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008464 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008465 break;
8466 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008467 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008468 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008469
8470 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008471 if (!rdev->ops->mgmt_tx)
8472 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008473
Eric W. Biederman15e47302012-09-07 20:12:54 +00008474 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008475 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8476 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008477}
8478
Johannes Berg2e161f72010-08-12 15:38:38 +02008479static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008480{
Johannes Berg4c476992010-10-04 21:36:35 +02008481 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008482 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008483 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008484 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008485 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008486 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008487 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008488 struct cfg80211_mgmt_tx_params params = {
8489 .dont_wait_for_ack =
8490 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8491 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008492
Johannes Berg683b6d32012-11-08 21:25:48 +01008493 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008494 return -EINVAL;
8495
Johannes Berg4c476992010-10-04 21:36:35 +02008496 if (!rdev->ops->mgmt_tx)
8497 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008498
Johannes Berg71bbc992012-06-15 15:30:18 +02008499 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008500 case NL80211_IFTYPE_P2P_DEVICE:
8501 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8502 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008503 case NL80211_IFTYPE_STATION:
8504 case NL80211_IFTYPE_ADHOC:
8505 case NL80211_IFTYPE_P2P_CLIENT:
8506 case NL80211_IFTYPE_AP:
8507 case NL80211_IFTYPE_AP_VLAN:
8508 case NL80211_IFTYPE_MESH_POINT:
8509 case NL80211_IFTYPE_P2P_GO:
8510 break;
8511 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008512 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008513 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008514
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008515 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008516 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008517 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008518 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008519
8520 /*
8521 * We should wait on the channel for at least a minimum amount
8522 * of time (10ms) but no longer than the driver supports.
8523 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008524 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8525 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008526 return -EINVAL;
8527
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008528 }
8529
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008530 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008531
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008532 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008533 return -EINVAL;
8534
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008535 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308536
Antonio Quartulliea141b752013-06-11 14:20:03 +02008537 /* get the channel if any has been specified, otherwise pass NULL to
8538 * the driver. The latter will use the current one
8539 */
8540 chandef.chan = NULL;
8541 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8542 err = nl80211_parse_chandef(rdev, info, &chandef);
8543 if (err)
8544 return err;
8545 }
8546
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008547 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008548 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008549
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008550 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8551 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8552
8553 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8554 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8555 int i;
8556
8557 if (len % sizeof(u16))
8558 return -EINVAL;
8559
8560 params.n_csa_offsets = len / sizeof(u16);
8561 params.csa_offsets =
8562 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8563
8564 /* check that all the offsets fit the frame */
8565 for (i = 0; i < params.n_csa_offsets; i++) {
8566 if (params.csa_offsets[i] >= params.len)
8567 return -EINVAL;
8568 }
8569 }
8570
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008571 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008572 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8573 if (!msg)
8574 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008575
Eric W. Biederman15e47302012-09-07 20:12:54 +00008576 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008577 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008578 if (!hdr) {
8579 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008580 goto free_msg;
8581 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008582 }
Johannes Berge247bd902011-11-04 11:18:21 +01008583
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008584 params.chan = chandef.chan;
8585 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008586 if (err)
8587 goto free_msg;
8588
Johannes Berge247bd902011-11-04 11:18:21 +01008589 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008590 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8591 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008592
Johannes Berge247bd902011-11-04 11:18:21 +01008593 genlmsg_end(msg, hdr);
8594 return genlmsg_reply(msg, info);
8595 }
8596
8597 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008598
8599 nla_put_failure:
8600 err = -ENOBUFS;
8601 free_msg:
8602 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008603 return err;
8604}
8605
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008606static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8607{
8608 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008609 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008610 u64 cookie;
8611
8612 if (!info->attrs[NL80211_ATTR_COOKIE])
8613 return -EINVAL;
8614
8615 if (!rdev->ops->mgmt_tx_cancel_wait)
8616 return -EOPNOTSUPP;
8617
Johannes Berg71bbc992012-06-15 15:30:18 +02008618 switch (wdev->iftype) {
8619 case NL80211_IFTYPE_STATION:
8620 case NL80211_IFTYPE_ADHOC:
8621 case NL80211_IFTYPE_P2P_CLIENT:
8622 case NL80211_IFTYPE_AP:
8623 case NL80211_IFTYPE_AP_VLAN:
8624 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008625 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008626 break;
8627 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008628 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008629 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008630
8631 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8632
Hila Gonene35e4d22012-06-27 17:19:42 +03008633 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008634}
8635
Kalle Valoffb9eb32010-02-17 17:58:10 +02008636static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8637{
Johannes Berg4c476992010-10-04 21:36:35 +02008638 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008639 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008640 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008641 u8 ps_state;
8642 bool state;
8643 int err;
8644
Johannes Berg4c476992010-10-04 21:36:35 +02008645 if (!info->attrs[NL80211_ATTR_PS_STATE])
8646 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008647
8648 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8649
Johannes Berg4c476992010-10-04 21:36:35 +02008650 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8651 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008652
8653 wdev = dev->ieee80211_ptr;
8654
Johannes Berg4c476992010-10-04 21:36:35 +02008655 if (!rdev->ops->set_power_mgmt)
8656 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008657
8658 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8659
8660 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008661 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008662
Hila Gonene35e4d22012-06-27 17:19:42 +03008663 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008664 if (!err)
8665 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008666 return err;
8667}
8668
8669static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8670{
Johannes Berg4c476992010-10-04 21:36:35 +02008671 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008672 enum nl80211_ps_state ps_state;
8673 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008674 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008675 struct sk_buff *msg;
8676 void *hdr;
8677 int err;
8678
Kalle Valoffb9eb32010-02-17 17:58:10 +02008679 wdev = dev->ieee80211_ptr;
8680
Johannes Berg4c476992010-10-04 21:36:35 +02008681 if (!rdev->ops->set_power_mgmt)
8682 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008683
8684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008685 if (!msg)
8686 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008687
Eric W. Biederman15e47302012-09-07 20:12:54 +00008688 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008689 NL80211_CMD_GET_POWER_SAVE);
8690 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008691 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008692 goto free_msg;
8693 }
8694
8695 if (wdev->ps)
8696 ps_state = NL80211_PS_ENABLED;
8697 else
8698 ps_state = NL80211_PS_DISABLED;
8699
David S. Miller9360ffd2012-03-29 04:41:26 -04008700 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8701 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008702
8703 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008704 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008705
Johannes Berg4c476992010-10-04 21:36:35 +02008706 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008707 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008708 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008709 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008710 return err;
8711}
8712
Johannes Berg94e860f2014-01-20 23:58:15 +01008713static const struct nla_policy
8714nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008715 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8716 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8717 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008718 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8719 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8720 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008721};
8722
Thomas Pedersen84f10702012-07-12 16:17:33 -07008723static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008724 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008725{
8726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008727 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008728 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008729
Johannes Bergd9d8b012012-11-26 12:51:52 +01008730 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008731 return -EINVAL;
8732
Thomas Pedersen84f10702012-07-12 16:17:33 -07008733 if (!rdev->ops->set_cqm_txe_config)
8734 return -EOPNOTSUPP;
8735
8736 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8737 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8738 return -EOPNOTSUPP;
8739
Hila Gonene35e4d22012-06-27 17:19:42 +03008740 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008741}
8742
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008743static int nl80211_set_cqm_rssi(struct genl_info *info,
8744 s32 threshold, u32 hysteresis)
8745{
Johannes Berg4c476992010-10-04 21:36:35 +02008746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008747 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008748 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008749
8750 if (threshold > 0)
8751 return -EINVAL;
8752
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008753 /* disabling - hysteresis should also be zero then */
8754 if (threshold == 0)
8755 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008756
Johannes Berg4c476992010-10-04 21:36:35 +02008757 if (!rdev->ops->set_cqm_rssi_config)
8758 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008759
Johannes Berg074ac8d2010-09-16 14:58:22 +02008760 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008761 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8762 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008763
Hila Gonene35e4d22012-06-27 17:19:42 +03008764 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008765}
8766
8767static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8768{
8769 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8770 struct nlattr *cqm;
8771 int err;
8772
8773 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008774 if (!cqm)
8775 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008776
8777 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8778 nl80211_attr_cqm_policy);
8779 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008780 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008781
8782 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8783 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008784 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8785 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008786
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008787 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8788 }
8789
8790 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8791 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8792 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8793 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8794 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8795 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8796
8797 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8798 }
8799
8800 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008801}
8802
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008803static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8804{
8805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8806 struct net_device *dev = info->user_ptr[1];
8807 struct ocb_setup setup = {};
8808 int err;
8809
8810 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8811 if (err)
8812 return err;
8813
8814 return cfg80211_join_ocb(rdev, dev, &setup);
8815}
8816
8817static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8818{
8819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8820 struct net_device *dev = info->user_ptr[1];
8821
8822 return cfg80211_leave_ocb(rdev, dev);
8823}
8824
Johannes Berg29cbe682010-12-03 09:20:44 +01008825static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8826{
8827 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8828 struct net_device *dev = info->user_ptr[1];
8829 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008830 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008831 int err;
8832
8833 /* start with default */
8834 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008835 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008836
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008837 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008838 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008839 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008840 if (err)
8841 return err;
8842 }
8843
8844 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8845 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8846 return -EINVAL;
8847
Javier Cardonac80d5452010-12-16 17:37:49 -08008848 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8849 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8850
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008851 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8852 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8853 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8854 return -EINVAL;
8855
Marco Porsch9bdbf042013-01-07 16:04:51 +01008856 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8857 setup.beacon_interval =
8858 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8859 if (setup.beacon_interval < 10 ||
8860 setup.beacon_interval > 10000)
8861 return -EINVAL;
8862 }
8863
8864 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8865 setup.dtim_period =
8866 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8867 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8868 return -EINVAL;
8869 }
8870
Javier Cardonac80d5452010-12-16 17:37:49 -08008871 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8872 /* parse additional setup parameters if given */
8873 err = nl80211_parse_mesh_setup(info, &setup);
8874 if (err)
8875 return err;
8876 }
8877
Thomas Pedersend37bb182013-03-04 13:06:13 -08008878 if (setup.user_mpm)
8879 cfg.auto_open_plinks = false;
8880
Johannes Bergcc1d2802012-05-16 23:50:20 +02008881 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008882 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8883 if (err)
8884 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008885 } else {
8886 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008887 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008888 }
8889
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008890 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8891 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8892 int n_rates =
8893 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8894 struct ieee80211_supported_band *sband;
8895
8896 if (!setup.chandef.chan)
8897 return -EINVAL;
8898
8899 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8900
8901 err = ieee80211_get_ratemask(sband, rates, n_rates,
8902 &setup.basic_rates);
8903 if (err)
8904 return err;
8905 }
8906
Javier Cardonac80d5452010-12-16 17:37:49 -08008907 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008908}
8909
8910static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8911{
8912 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8913 struct net_device *dev = info->user_ptr[1];
8914
8915 return cfg80211_leave_mesh(rdev, dev);
8916}
8917
Johannes Bergdfb89c52012-06-27 09:23:48 +02008918#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008919static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8920 struct cfg80211_registered_device *rdev)
8921{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008922 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008923 struct nlattr *nl_pats, *nl_pat;
8924 int i, pat_len;
8925
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008926 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008927 return 0;
8928
8929 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8930 if (!nl_pats)
8931 return -ENOBUFS;
8932
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008933 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008934 nl_pat = nla_nest_start(msg, i + 1);
8935 if (!nl_pat)
8936 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008937 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008938 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008939 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008940 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8941 wowlan->patterns[i].pattern) ||
8942 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008943 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008944 return -ENOBUFS;
8945 nla_nest_end(msg, nl_pat);
8946 }
8947 nla_nest_end(msg, nl_pats);
8948
8949 return 0;
8950}
8951
Johannes Berg2a0e0472013-01-23 22:57:40 +01008952static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8953 struct cfg80211_wowlan_tcp *tcp)
8954{
8955 struct nlattr *nl_tcp;
8956
8957 if (!tcp)
8958 return 0;
8959
8960 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8961 if (!nl_tcp)
8962 return -ENOBUFS;
8963
Jiri Benc930345e2015-03-29 16:59:25 +02008964 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8965 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01008966 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8967 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8968 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8969 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8970 tcp->payload_len, tcp->payload) ||
8971 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8972 tcp->data_interval) ||
8973 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8974 tcp->wake_len, tcp->wake_data) ||
8975 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8976 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8977 return -ENOBUFS;
8978
8979 if (tcp->payload_seq.len &&
8980 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8981 sizeof(tcp->payload_seq), &tcp->payload_seq))
8982 return -ENOBUFS;
8983
8984 if (tcp->payload_tok.len &&
8985 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8986 sizeof(tcp->payload_tok) + tcp->tokens_size,
8987 &tcp->payload_tok))
8988 return -ENOBUFS;
8989
Johannes Berge248ad32013-05-16 10:24:28 +02008990 nla_nest_end(msg, nl_tcp);
8991
Johannes Berg2a0e0472013-01-23 22:57:40 +01008992 return 0;
8993}
8994
Luciano Coelho75453cc2015-01-09 14:06:37 +02008995static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8996 struct cfg80211_sched_scan_request *req)
8997{
Avraham Stern3b06d272015-10-12 09:51:34 +03008998 struct nlattr *nd, *freqs, *matches, *match, *scan_plans, *scan_plan;
Luciano Coelho75453cc2015-01-09 14:06:37 +02008999 int i;
9000
9001 if (!req)
9002 return 0;
9003
9004 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
9005 if (!nd)
9006 return -ENOBUFS;
9007
Avraham Stern3b06d272015-10-12 09:51:34 +03009008 if (req->n_scan_plans == 1 &&
9009 nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL,
9010 req->scan_plans[0].interval * 1000))
Luciano Coelho75453cc2015-01-09 14:06:37 +02009011 return -ENOBUFS;
9012
Luciano Coelho21fea562015-03-17 16:36:01 +02009013 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
9014 return -ENOBUFS;
9015
Luciano Coelho75453cc2015-01-09 14:06:37 +02009016 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
9017 if (!freqs)
9018 return -ENOBUFS;
9019
9020 for (i = 0; i < req->n_channels; i++)
9021 nla_put_u32(msg, i, req->channels[i]->center_freq);
9022
9023 nla_nest_end(msg, freqs);
9024
9025 if (req->n_match_sets) {
9026 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
9027 for (i = 0; i < req->n_match_sets; i++) {
9028 match = nla_nest_start(msg, i);
9029 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
9030 req->match_sets[i].ssid.ssid_len,
9031 req->match_sets[i].ssid.ssid);
9032 nla_nest_end(msg, match);
9033 }
9034 nla_nest_end(msg, matches);
9035 }
9036
Avraham Stern3b06d272015-10-12 09:51:34 +03009037 scan_plans = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_PLANS);
9038 if (!scan_plans)
9039 return -ENOBUFS;
9040
9041 for (i = 0; i < req->n_scan_plans; i++) {
9042 scan_plan = nla_nest_start(msg, i + 1);
9043 if (!scan_plan ||
9044 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_INTERVAL,
9045 req->scan_plans[i].interval) ||
9046 (req->scan_plans[i].iterations &&
9047 nla_put_u32(msg, NL80211_SCHED_SCAN_PLAN_ITERATIONS,
9048 req->scan_plans[i].iterations)))
9049 return -ENOBUFS;
9050 nla_nest_end(msg, scan_plan);
9051 }
9052 nla_nest_end(msg, scan_plans);
9053
Luciano Coelho75453cc2015-01-09 14:06:37 +02009054 nla_nest_end(msg, nd);
9055
9056 return 0;
9057}
9058
Johannes Bergff1b6e62011-05-04 15:37:28 +02009059static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
9060{
9061 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9062 struct sk_buff *msg;
9063 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009064 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009065
Johannes Berg964dc9e2013-06-03 17:25:34 +02009066 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009067 return -EOPNOTSUPP;
9068
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009069 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01009070 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009071 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
9072 rdev->wiphy.wowlan_config->tcp->payload_len +
9073 rdev->wiphy.wowlan_config->tcp->wake_len +
9074 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009075 }
9076
9077 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009078 if (!msg)
9079 return -ENOMEM;
9080
Eric W. Biederman15e47302012-09-07 20:12:54 +00009081 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02009082 NL80211_CMD_GET_WOWLAN);
9083 if (!hdr)
9084 goto nla_put_failure;
9085
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009086 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009087 struct nlattr *nl_wowlan;
9088
9089 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
9090 if (!nl_wowlan)
9091 goto nla_put_failure;
9092
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009093 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009094 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009095 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009096 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009097 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009098 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009099 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009100 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009101 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009102 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009103 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009104 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009105 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04009106 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
9107 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009108
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009109 if (nl80211_send_wowlan_patterns(msg, rdev))
9110 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009111
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009112 if (nl80211_send_wowlan_tcp(msg,
9113 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01009114 goto nla_put_failure;
9115
Luciano Coelho75453cc2015-01-09 14:06:37 +02009116 if (nl80211_send_wowlan_nd(
9117 msg,
9118 rdev->wiphy.wowlan_config->nd_config))
9119 goto nla_put_failure;
9120
Johannes Bergff1b6e62011-05-04 15:37:28 +02009121 nla_nest_end(msg, nl_wowlan);
9122 }
9123
9124 genlmsg_end(msg, hdr);
9125 return genlmsg_reply(msg, info);
9126
9127nla_put_failure:
9128 nlmsg_free(msg);
9129 return -ENOBUFS;
9130}
9131
Johannes Berg2a0e0472013-01-23 22:57:40 +01009132static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
9133 struct nlattr *attr,
9134 struct cfg80211_wowlan *trig)
9135{
9136 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
9137 struct cfg80211_wowlan_tcp *cfg;
9138 struct nl80211_wowlan_tcp_data_token *tok = NULL;
9139 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
9140 u32 size;
9141 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
9142 int err, port;
9143
Johannes Berg964dc9e2013-06-03 17:25:34 +02009144 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009145 return -EINVAL;
9146
9147 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
9148 nla_data(attr), nla_len(attr),
9149 nl80211_wowlan_tcp_policy);
9150 if (err)
9151 return err;
9152
9153 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
9154 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
9155 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
9156 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
9157 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
9158 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
9159 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
9160 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
9161 return -EINVAL;
9162
9163 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009164 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009165 return -EINVAL;
9166
9167 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009168 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009169 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009170 return -EINVAL;
9171
9172 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009173 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009174 return -EINVAL;
9175
9176 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9177 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9178 return -EINVAL;
9179
9180 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9181 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9182
9183 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9184 tokens_size = tokln - sizeof(*tok);
9185
9186 if (!tok->len || tokens_size % tok->len)
9187 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009188 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009189 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009190 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009191 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009192 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009193 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009194 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009195 return -EINVAL;
9196 if (tok->offset + tok->len > data_size)
9197 return -EINVAL;
9198 }
9199
9200 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9201 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009202 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009203 return -EINVAL;
9204 if (seq->len == 0 || seq->len > 4)
9205 return -EINVAL;
9206 if (seq->len + seq->offset > data_size)
9207 return -EINVAL;
9208 }
9209
9210 size = sizeof(*cfg);
9211 size += data_size;
9212 size += wake_size + wake_mask_size;
9213 size += tokens_size;
9214
9215 cfg = kzalloc(size, GFP_KERNEL);
9216 if (!cfg)
9217 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009218 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9219 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009220 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9221 ETH_ALEN);
9222 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9223 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9224 else
9225 port = 0;
9226#ifdef CONFIG_INET
9227 /* allocate a socket and port for it and use it */
9228 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9229 IPPROTO_TCP, &cfg->sock, 1);
9230 if (err) {
9231 kfree(cfg);
9232 return err;
9233 }
9234 if (inet_csk_get_port(cfg->sock->sk, port)) {
9235 sock_release(cfg->sock);
9236 kfree(cfg);
9237 return -EADDRINUSE;
9238 }
9239 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9240#else
9241 if (!port) {
9242 kfree(cfg);
9243 return -EINVAL;
9244 }
9245 cfg->src_port = port;
9246#endif
9247
9248 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9249 cfg->payload_len = data_size;
9250 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9251 memcpy((void *)cfg->payload,
9252 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9253 data_size);
9254 if (seq)
9255 cfg->payload_seq = *seq;
9256 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9257 cfg->wake_len = wake_size;
9258 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9259 memcpy((void *)cfg->wake_data,
9260 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9261 wake_size);
9262 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9263 data_size + wake_size;
9264 memcpy((void *)cfg->wake_mask,
9265 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9266 wake_mask_size);
9267 if (tok) {
9268 cfg->tokens_size = tokens_size;
9269 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9270 }
9271
9272 trig->tcp = cfg;
9273
9274 return 0;
9275}
9276
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009277static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9278 const struct wiphy_wowlan_support *wowlan,
9279 struct nlattr *attr,
9280 struct cfg80211_wowlan *trig)
9281{
9282 struct nlattr **tb;
9283 int err;
9284
9285 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9286 if (!tb)
9287 return -ENOMEM;
9288
9289 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9290 err = -EOPNOTSUPP;
9291 goto out;
9292 }
9293
9294 err = nla_parse(tb, NL80211_ATTR_MAX,
9295 nla_data(attr), nla_len(attr),
9296 nl80211_policy);
9297 if (err)
9298 goto out;
9299
Johannes Bergad2b26a2014-06-12 21:39:05 +02009300 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009301 err = PTR_ERR_OR_ZERO(trig->nd_config);
9302 if (err)
9303 trig->nd_config = NULL;
9304
9305out:
9306 kfree(tb);
9307 return err;
9308}
9309
Johannes Bergff1b6e62011-05-04 15:37:28 +02009310static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9311{
9312 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9313 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009314 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009315 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009316 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009317 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009318 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009319 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009320
Johannes Berg964dc9e2013-06-03 17:25:34 +02009321 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009322 return -EOPNOTSUPP;
9323
Johannes Bergae33bd82012-07-12 16:25:02 +02009324 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9325 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009326 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009327 goto set_wakeup;
9328 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009329
9330 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9331 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9332 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9333 nl80211_wowlan_policy);
9334 if (err)
9335 return err;
9336
9337 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9338 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9339 return -EINVAL;
9340 new_triggers.any = true;
9341 }
9342
9343 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9344 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9345 return -EINVAL;
9346 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009347 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009348 }
9349
9350 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9351 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9352 return -EINVAL;
9353 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009354 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009355 }
9356
Johannes Berg77dbbb12011-07-13 10:48:55 +02009357 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9358 return -EINVAL;
9359
9360 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9361 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9362 return -EINVAL;
9363 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009364 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009365 }
9366
9367 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9368 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9369 return -EINVAL;
9370 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009371 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009372 }
9373
9374 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9375 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9376 return -EINVAL;
9377 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009378 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009379 }
9380
9381 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9382 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9383 return -EINVAL;
9384 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009385 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009386 }
9387
Johannes Bergff1b6e62011-05-04 15:37:28 +02009388 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9389 struct nlattr *pat;
9390 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009391 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009392 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009393
Johannes Berg98fc4382015-03-01 09:10:13 +02009394 regular = true;
9395
Johannes Bergff1b6e62011-05-04 15:37:28 +02009396 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9397 rem)
9398 n_patterns++;
9399 if (n_patterns > wowlan->n_patterns)
9400 return -EINVAL;
9401
9402 new_triggers.patterns = kcalloc(n_patterns,
9403 sizeof(new_triggers.patterns[0]),
9404 GFP_KERNEL);
9405 if (!new_triggers.patterns)
9406 return -ENOMEM;
9407
9408 new_triggers.n_patterns = n_patterns;
9409 i = 0;
9410
9411 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9412 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009413 u8 *mask_pat;
9414
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009415 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9416 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009417 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009418 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9419 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009420 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009421 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009422 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009423 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009424 goto error;
9425 if (pat_len > wowlan->pattern_max_len ||
9426 pat_len < wowlan->pattern_min_len)
9427 goto error;
9428
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009429 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009430 pkt_offset = 0;
9431 else
9432 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009433 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009434 if (pkt_offset > wowlan->max_pkt_offset)
9435 goto error;
9436 new_triggers.patterns[i].pkt_offset = pkt_offset;
9437
Johannes Berg922bd802014-05-19 17:59:50 +02009438 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9439 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009440 err = -ENOMEM;
9441 goto error;
9442 }
Johannes Berg922bd802014-05-19 17:59:50 +02009443 new_triggers.patterns[i].mask = mask_pat;
9444 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009445 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009446 mask_pat += mask_len;
9447 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009448 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009449 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009450 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009451 pat_len);
9452 i++;
9453 }
9454 }
9455
Johannes Berg2a0e0472013-01-23 22:57:40 +01009456 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009457 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009458 err = nl80211_parse_wowlan_tcp(
9459 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9460 &new_triggers);
9461 if (err)
9462 goto error;
9463 }
9464
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009465 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009466 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009467 err = nl80211_parse_wowlan_nd(
9468 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9469 &new_triggers);
9470 if (err)
9471 goto error;
9472 }
9473
Johannes Berg98fc4382015-03-01 09:10:13 +02009474 /* The 'any' trigger means the device continues operating more or less
9475 * as in its normal operation mode and wakes up the host on most of the
9476 * normal interrupts (like packet RX, ...)
9477 * It therefore makes little sense to combine with the more constrained
9478 * wakeup trigger modes.
9479 */
9480 if (new_triggers.any && regular) {
9481 err = -EINVAL;
9482 goto error;
9483 }
9484
Johannes Bergae33bd82012-07-12 16:25:02 +02009485 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9486 if (!ntrig) {
9487 err = -ENOMEM;
9488 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009489 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009490 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009491 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009492
Johannes Bergae33bd82012-07-12 16:25:02 +02009493 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009494 if (rdev->ops->set_wakeup &&
9495 prev_enabled != !!rdev->wiphy.wowlan_config)
9496 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009497
Johannes Bergff1b6e62011-05-04 15:37:28 +02009498 return 0;
9499 error:
9500 for (i = 0; i < new_triggers.n_patterns; i++)
9501 kfree(new_triggers.patterns[i].mask);
9502 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009503 if (new_triggers.tcp && new_triggers.tcp->sock)
9504 sock_release(new_triggers.tcp->sock);
9505 kfree(new_triggers.tcp);
Ola Olssone5dbe072015-12-12 23:17:17 +01009506 kfree(new_triggers.nd_config);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009507 return err;
9508}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009509#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009510
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009511static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9512 struct cfg80211_registered_device *rdev)
9513{
9514 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9515 int i, j, pat_len;
9516 struct cfg80211_coalesce_rules *rule;
9517
9518 if (!rdev->coalesce->n_rules)
9519 return 0;
9520
9521 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9522 if (!nl_rules)
9523 return -ENOBUFS;
9524
9525 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9526 nl_rule = nla_nest_start(msg, i + 1);
9527 if (!nl_rule)
9528 return -ENOBUFS;
9529
9530 rule = &rdev->coalesce->rules[i];
9531 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9532 rule->delay))
9533 return -ENOBUFS;
9534
9535 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9536 rule->condition))
9537 return -ENOBUFS;
9538
9539 nl_pats = nla_nest_start(msg,
9540 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9541 if (!nl_pats)
9542 return -ENOBUFS;
9543
9544 for (j = 0; j < rule->n_patterns; j++) {
9545 nl_pat = nla_nest_start(msg, j + 1);
9546 if (!nl_pat)
9547 return -ENOBUFS;
9548 pat_len = rule->patterns[j].pattern_len;
9549 if (nla_put(msg, NL80211_PKTPAT_MASK,
9550 DIV_ROUND_UP(pat_len, 8),
9551 rule->patterns[j].mask) ||
9552 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9553 rule->patterns[j].pattern) ||
9554 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9555 rule->patterns[j].pkt_offset))
9556 return -ENOBUFS;
9557 nla_nest_end(msg, nl_pat);
9558 }
9559 nla_nest_end(msg, nl_pats);
9560 nla_nest_end(msg, nl_rule);
9561 }
9562 nla_nest_end(msg, nl_rules);
9563
9564 return 0;
9565}
9566
9567static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9568{
9569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9570 struct sk_buff *msg;
9571 void *hdr;
9572
9573 if (!rdev->wiphy.coalesce)
9574 return -EOPNOTSUPP;
9575
9576 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9577 if (!msg)
9578 return -ENOMEM;
9579
9580 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9581 NL80211_CMD_GET_COALESCE);
9582 if (!hdr)
9583 goto nla_put_failure;
9584
9585 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9586 goto nla_put_failure;
9587
9588 genlmsg_end(msg, hdr);
9589 return genlmsg_reply(msg, info);
9590
9591nla_put_failure:
9592 nlmsg_free(msg);
9593 return -ENOBUFS;
9594}
9595
9596void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9597{
9598 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9599 int i, j;
9600 struct cfg80211_coalesce_rules *rule;
9601
9602 if (!coalesce)
9603 return;
9604
9605 for (i = 0; i < coalesce->n_rules; i++) {
9606 rule = &coalesce->rules[i];
9607 for (j = 0; j < rule->n_patterns; j++)
9608 kfree(rule->patterns[j].mask);
9609 kfree(rule->patterns);
9610 }
9611 kfree(coalesce->rules);
9612 kfree(coalesce);
9613 rdev->coalesce = NULL;
9614}
9615
9616static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9617 struct nlattr *rule,
9618 struct cfg80211_coalesce_rules *new_rule)
9619{
9620 int err, i;
9621 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9622 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9623 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9624 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9625
9626 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9627 nla_len(rule), nl80211_coalesce_policy);
9628 if (err)
9629 return err;
9630
9631 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9632 new_rule->delay =
9633 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9634 if (new_rule->delay > coalesce->max_delay)
9635 return -EINVAL;
9636
9637 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9638 new_rule->condition =
9639 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9640 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9641 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9642 return -EINVAL;
9643
9644 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9645 return -EINVAL;
9646
9647 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9648 rem)
9649 n_patterns++;
9650 if (n_patterns > coalesce->n_patterns)
9651 return -EINVAL;
9652
9653 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9654 GFP_KERNEL);
9655 if (!new_rule->patterns)
9656 return -ENOMEM;
9657
9658 new_rule->n_patterns = n_patterns;
9659 i = 0;
9660
9661 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9662 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009663 u8 *mask_pat;
9664
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009665 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9666 nla_len(pat), NULL);
9667 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9668 !pat_tb[NL80211_PKTPAT_PATTERN])
9669 return -EINVAL;
9670 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9671 mask_len = DIV_ROUND_UP(pat_len, 8);
9672 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9673 return -EINVAL;
9674 if (pat_len > coalesce->pattern_max_len ||
9675 pat_len < coalesce->pattern_min_len)
9676 return -EINVAL;
9677
9678 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9679 pkt_offset = 0;
9680 else
9681 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9682 if (pkt_offset > coalesce->max_pkt_offset)
9683 return -EINVAL;
9684 new_rule->patterns[i].pkt_offset = pkt_offset;
9685
Johannes Berg922bd802014-05-19 17:59:50 +02009686 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9687 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009688 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009689
9690 new_rule->patterns[i].mask = mask_pat;
9691 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9692 mask_len);
9693
9694 mask_pat += mask_len;
9695 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009696 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009697 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9698 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009699 i++;
9700 }
9701
9702 return 0;
9703}
9704
9705static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9706{
9707 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9708 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9709 struct cfg80211_coalesce new_coalesce = {};
9710 struct cfg80211_coalesce *n_coalesce;
9711 int err, rem_rule, n_rules = 0, i, j;
9712 struct nlattr *rule;
9713 struct cfg80211_coalesce_rules *tmp_rule;
9714
9715 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9716 return -EOPNOTSUPP;
9717
9718 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9719 cfg80211_rdev_free_coalesce(rdev);
9720 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9721 return 0;
9722 }
9723
9724 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9725 rem_rule)
9726 n_rules++;
9727 if (n_rules > coalesce->n_rules)
9728 return -EINVAL;
9729
9730 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9731 GFP_KERNEL);
9732 if (!new_coalesce.rules)
9733 return -ENOMEM;
9734
9735 new_coalesce.n_rules = n_rules;
9736 i = 0;
9737
9738 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9739 rem_rule) {
9740 err = nl80211_parse_coalesce_rule(rdev, rule,
9741 &new_coalesce.rules[i]);
9742 if (err)
9743 goto error;
9744
9745 i++;
9746 }
9747
9748 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9749 if (err)
9750 goto error;
9751
9752 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9753 if (!n_coalesce) {
9754 err = -ENOMEM;
9755 goto error;
9756 }
9757 cfg80211_rdev_free_coalesce(rdev);
9758 rdev->coalesce = n_coalesce;
9759
9760 return 0;
9761error:
9762 for (i = 0; i < new_coalesce.n_rules; i++) {
9763 tmp_rule = &new_coalesce.rules[i];
9764 for (j = 0; j < tmp_rule->n_patterns; j++)
9765 kfree(tmp_rule->patterns[j].mask);
9766 kfree(tmp_rule->patterns);
9767 }
9768 kfree(new_coalesce.rules);
9769
9770 return err;
9771}
9772
Johannes Berge5497d72011-07-05 16:35:40 +02009773static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9774{
9775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9776 struct net_device *dev = info->user_ptr[1];
9777 struct wireless_dev *wdev = dev->ieee80211_ptr;
9778 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9779 struct cfg80211_gtk_rekey_data rekey_data;
9780 int err;
9781
9782 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9783 return -EINVAL;
9784
9785 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9786 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9787 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9788 nl80211_rekey_policy);
9789 if (err)
9790 return err;
9791
9792 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9793 return -ERANGE;
9794 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9795 return -ERANGE;
9796 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9797 return -ERANGE;
9798
Johannes Berg78f686c2014-09-10 22:28:06 +03009799 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9800 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9801 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009802
9803 wdev_lock(wdev);
9804 if (!wdev->current_bss) {
9805 err = -ENOTCONN;
9806 goto out;
9807 }
9808
9809 if (!rdev->ops->set_rekey_data) {
9810 err = -EOPNOTSUPP;
9811 goto out;
9812 }
9813
Hila Gonene35e4d22012-06-27 17:19:42 +03009814 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009815 out:
9816 wdev_unlock(wdev);
9817 return err;
9818}
9819
Johannes Berg28946da2011-11-04 11:18:12 +01009820static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9821 struct genl_info *info)
9822{
9823 struct net_device *dev = info->user_ptr[1];
9824 struct wireless_dev *wdev = dev->ieee80211_ptr;
9825
9826 if (wdev->iftype != NL80211_IFTYPE_AP &&
9827 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9828 return -EINVAL;
9829
Eric W. Biederman15e47302012-09-07 20:12:54 +00009830 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009831 return -EBUSY;
9832
Eric W. Biederman15e47302012-09-07 20:12:54 +00009833 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009834 return 0;
9835}
9836
Johannes Berg7f6cf312011-11-04 11:18:15 +01009837static int nl80211_probe_client(struct sk_buff *skb,
9838 struct genl_info *info)
9839{
9840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9841 struct net_device *dev = info->user_ptr[1];
9842 struct wireless_dev *wdev = dev->ieee80211_ptr;
9843 struct sk_buff *msg;
9844 void *hdr;
9845 const u8 *addr;
9846 u64 cookie;
9847 int err;
9848
9849 if (wdev->iftype != NL80211_IFTYPE_AP &&
9850 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9851 return -EOPNOTSUPP;
9852
9853 if (!info->attrs[NL80211_ATTR_MAC])
9854 return -EINVAL;
9855
9856 if (!rdev->ops->probe_client)
9857 return -EOPNOTSUPP;
9858
9859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9860 if (!msg)
9861 return -ENOMEM;
9862
Eric W. Biederman15e47302012-09-07 20:12:54 +00009863 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009864 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009865 if (!hdr) {
9866 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009867 goto free_msg;
9868 }
9869
9870 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9871
Hila Gonene35e4d22012-06-27 17:19:42 +03009872 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009873 if (err)
9874 goto free_msg;
9875
David S. Miller9360ffd2012-03-29 04:41:26 -04009876 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9877 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009878
9879 genlmsg_end(msg, hdr);
9880
9881 return genlmsg_reply(msg, info);
9882
9883 nla_put_failure:
9884 err = -ENOBUFS;
9885 free_msg:
9886 nlmsg_free(msg);
9887 return err;
9888}
9889
Johannes Berg5e760232011-11-04 11:18:17 +01009890static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9891{
9892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009893 struct cfg80211_beacon_registration *reg, *nreg;
9894 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009895
9896 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9897 return -EOPNOTSUPP;
9898
Ben Greear37c73b52012-10-26 14:49:25 -07009899 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9900 if (!nreg)
9901 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009902
Ben Greear37c73b52012-10-26 14:49:25 -07009903 /* First, check if already registered. */
9904 spin_lock_bh(&rdev->beacon_registrations_lock);
9905 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9906 if (reg->nlportid == info->snd_portid) {
9907 rv = -EALREADY;
9908 goto out_err;
9909 }
9910 }
9911 /* Add it to the list */
9912 nreg->nlportid = info->snd_portid;
9913 list_add(&nreg->list, &rdev->beacon_registrations);
9914
9915 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009916
9917 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009918out_err:
9919 spin_unlock_bh(&rdev->beacon_registrations_lock);
9920 kfree(nreg);
9921 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009922}
9923
Johannes Berg98104fde2012-06-16 00:19:54 +02009924static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9925{
9926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9927 struct wireless_dev *wdev = info->user_ptr[1];
9928 int err;
9929
9930 if (!rdev->ops->start_p2p_device)
9931 return -EOPNOTSUPP;
9932
9933 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9934 return -EOPNOTSUPP;
9935
9936 if (wdev->p2p_started)
9937 return 0;
9938
Luciano Coelhob6a55012014-02-27 11:07:21 +02009939 if (rfkill_blocked(rdev->rfkill))
9940 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009941
Johannes Bergeeb126e2012-10-23 15:16:50 +02009942 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009943 if (err)
9944 return err;
9945
9946 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009947 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009948
9949 return 0;
9950}
9951
9952static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9953{
9954 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9955 struct wireless_dev *wdev = info->user_ptr[1];
9956
9957 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9958 return -EOPNOTSUPP;
9959
9960 if (!rdev->ops->stop_p2p_device)
9961 return -EOPNOTSUPP;
9962
Johannes Bergf9f47522013-03-19 15:04:07 +01009963 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009964
9965 return 0;
9966}
9967
Johannes Berg3713b4e2013-02-14 16:19:38 +01009968static int nl80211_get_protocol_features(struct sk_buff *skb,
9969 struct genl_info *info)
9970{
9971 void *hdr;
9972 struct sk_buff *msg;
9973
9974 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9975 if (!msg)
9976 return -ENOMEM;
9977
9978 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9979 NL80211_CMD_GET_PROTOCOL_FEATURES);
9980 if (!hdr)
9981 goto nla_put_failure;
9982
9983 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9984 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9985 goto nla_put_failure;
9986
9987 genlmsg_end(msg, hdr);
9988 return genlmsg_reply(msg, info);
9989
9990 nla_put_failure:
9991 kfree_skb(msg);
9992 return -ENOBUFS;
9993}
9994
Jouni Malinen355199e2013-02-27 17:14:27 +02009995static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9996{
9997 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9998 struct cfg80211_update_ft_ies_params ft_params;
9999 struct net_device *dev = info->user_ptr[1];
10000
10001 if (!rdev->ops->update_ft_ies)
10002 return -EOPNOTSUPP;
10003
10004 if (!info->attrs[NL80211_ATTR_MDID] ||
10005 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
10006 return -EINVAL;
10007
10008 memset(&ft_params, 0, sizeof(ft_params));
10009 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
10010 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
10011 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
10012
10013 return rdev_update_ft_ies(rdev, dev, &ft_params);
10014}
10015
Arend van Spriel5de17982013-04-18 15:49:00 +020010016static int nl80211_crit_protocol_start(struct sk_buff *skb,
10017 struct genl_info *info)
10018{
10019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10020 struct wireless_dev *wdev = info->user_ptr[1];
10021 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
10022 u16 duration;
10023 int ret;
10024
10025 if (!rdev->ops->crit_proto_start)
10026 return -EOPNOTSUPP;
10027
10028 if (WARN_ON(!rdev->ops->crit_proto_stop))
10029 return -EINVAL;
10030
10031 if (rdev->crit_proto_nlportid)
10032 return -EBUSY;
10033
10034 /* determine protocol if provided */
10035 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
10036 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
10037
10038 if (proto >= NUM_NL80211_CRIT_PROTO)
10039 return -EINVAL;
10040
10041 /* timeout must be provided */
10042 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
10043 return -EINVAL;
10044
10045 duration =
10046 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
10047
10048 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
10049 return -ERANGE;
10050
10051 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
10052 if (!ret)
10053 rdev->crit_proto_nlportid = info->snd_portid;
10054
10055 return ret;
10056}
10057
10058static int nl80211_crit_protocol_stop(struct sk_buff *skb,
10059 struct genl_info *info)
10060{
10061 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10062 struct wireless_dev *wdev = info->user_ptr[1];
10063
10064 if (!rdev->ops->crit_proto_stop)
10065 return -EOPNOTSUPP;
10066
10067 if (rdev->crit_proto_nlportid) {
10068 rdev->crit_proto_nlportid = 0;
10069 rdev_crit_proto_stop(rdev, wdev);
10070 }
10071 return 0;
10072}
10073
Johannes Bergad7e7182013-11-13 13:37:47 +010010074static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
10075{
10076 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10077 struct wireless_dev *wdev =
10078 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
10079 int i, err;
10080 u32 vid, subcmd;
10081
10082 if (!rdev->wiphy.vendor_commands)
10083 return -EOPNOTSUPP;
10084
10085 if (IS_ERR(wdev)) {
10086 err = PTR_ERR(wdev);
10087 if (err != -EINVAL)
10088 return err;
10089 wdev = NULL;
10090 } else if (wdev->wiphy != &rdev->wiphy) {
10091 return -EINVAL;
10092 }
10093
10094 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
10095 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
10096 return -EINVAL;
10097
10098 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
10099 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
10100 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
10101 const struct wiphy_vendor_command *vcmd;
10102 void *data = NULL;
10103 int len = 0;
10104
10105 vcmd = &rdev->wiphy.vendor_commands[i];
10106
10107 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10108 continue;
10109
10110 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10111 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10112 if (!wdev)
10113 return -EINVAL;
10114 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10115 !wdev->netdev)
10116 return -EINVAL;
10117
10118 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10119 if (wdev->netdev &&
10120 !netif_running(wdev->netdev))
10121 return -ENETDOWN;
10122 if (!wdev->netdev && !wdev->p2p_started)
10123 return -ENETDOWN;
10124 }
Johannes Berg7bdbe402015-08-15 22:39:49 +030010125
10126 if (!vcmd->doit)
10127 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +010010128 } else {
10129 wdev = NULL;
10130 }
10131
10132 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
10133 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10134 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
10135 }
10136
10137 rdev->cur_cmd_info = info;
10138 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
10139 data, len);
10140 rdev->cur_cmd_info = NULL;
10141 return err;
10142 }
10143
10144 return -EOPNOTSUPP;
10145}
10146
Johannes Berg7bdbe402015-08-15 22:39:49 +030010147static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
10148 struct netlink_callback *cb,
10149 struct cfg80211_registered_device **rdev,
10150 struct wireless_dev **wdev)
10151{
10152 u32 vid, subcmd;
10153 unsigned int i;
10154 int vcmd_idx = -1;
10155 int err;
10156 void *data = NULL;
10157 unsigned int data_len = 0;
10158
10159 rtnl_lock();
10160
10161 if (cb->args[0]) {
10162 /* subtract the 1 again here */
10163 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
10164 struct wireless_dev *tmp;
10165
10166 if (!wiphy) {
10167 err = -ENODEV;
10168 goto out_unlock;
10169 }
10170 *rdev = wiphy_to_rdev(wiphy);
10171 *wdev = NULL;
10172
10173 if (cb->args[1]) {
10174 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
10175 if (tmp->identifier == cb->args[1] - 1) {
10176 *wdev = tmp;
10177 break;
10178 }
10179 }
10180 }
10181
10182 /* keep rtnl locked in successful case */
10183 return 0;
10184 }
10185
10186 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10187 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10188 nl80211_policy);
10189 if (err)
10190 goto out_unlock;
10191
10192 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10193 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10194 err = -EINVAL;
10195 goto out_unlock;
10196 }
10197
10198 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10199 nl80211_fam.attrbuf);
10200 if (IS_ERR(*wdev))
10201 *wdev = NULL;
10202
10203 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10204 nl80211_fam.attrbuf);
10205 if (IS_ERR(*rdev)) {
10206 err = PTR_ERR(*rdev);
10207 goto out_unlock;
10208 }
10209
10210 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10211 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10212
10213 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10214 const struct wiphy_vendor_command *vcmd;
10215
10216 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10217
10218 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10219 continue;
10220
10221 if (!vcmd->dumpit) {
10222 err = -EOPNOTSUPP;
10223 goto out_unlock;
10224 }
10225
10226 vcmd_idx = i;
10227 break;
10228 }
10229
10230 if (vcmd_idx < 0) {
10231 err = -EOPNOTSUPP;
10232 goto out_unlock;
10233 }
10234
10235 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10236 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10237 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10238 }
10239
10240 /* 0 is the first index - add 1 to parse only once */
10241 cb->args[0] = (*rdev)->wiphy_idx + 1;
10242 /* add 1 to know if it was NULL */
10243 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10244 cb->args[2] = vcmd_idx;
10245 cb->args[3] = (unsigned long)data;
10246 cb->args[4] = data_len;
10247
10248 /* keep rtnl locked in successful case */
10249 return 0;
10250 out_unlock:
10251 rtnl_unlock();
10252 return err;
10253}
10254
10255static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10256 struct netlink_callback *cb)
10257{
10258 struct cfg80211_registered_device *rdev;
10259 struct wireless_dev *wdev;
10260 unsigned int vcmd_idx;
10261 const struct wiphy_vendor_command *vcmd;
10262 void *data;
10263 int data_len;
10264 int err;
10265 struct nlattr *vendor_data;
10266
10267 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10268 if (err)
10269 return err;
10270
10271 vcmd_idx = cb->args[2];
10272 data = (void *)cb->args[3];
10273 data_len = cb->args[4];
10274 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10275
10276 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10277 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10278 if (!wdev)
10279 return -EINVAL;
10280 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10281 !wdev->netdev)
10282 return -EINVAL;
10283
10284 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10285 if (wdev->netdev &&
10286 !netif_running(wdev->netdev))
10287 return -ENETDOWN;
10288 if (!wdev->netdev && !wdev->p2p_started)
10289 return -ENETDOWN;
10290 }
10291 }
10292
10293 while (1) {
10294 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10295 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10296 NL80211_CMD_VENDOR);
10297 if (!hdr)
10298 break;
10299
10300 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10301 (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV,
10302 wdev_id(wdev)))) {
10303 genlmsg_cancel(skb, hdr);
10304 break;
10305 }
10306
10307 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10308 if (!vendor_data) {
10309 genlmsg_cancel(skb, hdr);
10310 break;
10311 }
10312
10313 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10314 (unsigned long *)&cb->args[5]);
10315 nla_nest_end(skb, vendor_data);
10316
10317 if (err == -ENOBUFS || err == -ENOENT) {
10318 genlmsg_cancel(skb, hdr);
10319 break;
10320 } else if (err) {
10321 genlmsg_cancel(skb, hdr);
10322 goto out;
10323 }
10324
10325 genlmsg_end(skb, hdr);
10326 }
10327
10328 err = skb->len;
10329 out:
10330 rtnl_unlock();
10331 return err;
10332}
10333
Johannes Bergad7e7182013-11-13 13:37:47 +010010334struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10335 enum nl80211_commands cmd,
10336 enum nl80211_attrs attr,
10337 int approxlen)
10338{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010339 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010340
10341 if (WARN_ON(!rdev->cur_cmd_info))
10342 return NULL;
10343
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010344 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010345 rdev->cur_cmd_info->snd_portid,
10346 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010347 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010348}
10349EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10350
10351int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10352{
10353 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10354 void *hdr = ((void **)skb->cb)[1];
10355 struct nlattr *data = ((void **)skb->cb)[2];
10356
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010357 /* clear CB data for netlink core to own from now on */
10358 memset(skb->cb, 0, sizeof(skb->cb));
10359
Johannes Bergad7e7182013-11-13 13:37:47 +010010360 if (WARN_ON(!rdev->cur_cmd_info)) {
10361 kfree_skb(skb);
10362 return -EINVAL;
10363 }
10364
10365 nla_nest_end(skb, data);
10366 genlmsg_end(skb, hdr);
10367 return genlmsg_reply(skb, rdev->cur_cmd_info);
10368}
10369EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10370
10371
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010372static int nl80211_set_qos_map(struct sk_buff *skb,
10373 struct genl_info *info)
10374{
10375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10376 struct cfg80211_qos_map *qos_map = NULL;
10377 struct net_device *dev = info->user_ptr[1];
10378 u8 *pos, len, num_des, des_len, des;
10379 int ret;
10380
10381 if (!rdev->ops->set_qos_map)
10382 return -EOPNOTSUPP;
10383
10384 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10385 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10386 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10387
10388 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10389 len > IEEE80211_QOS_MAP_LEN_MAX)
10390 return -EINVAL;
10391
10392 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10393 if (!qos_map)
10394 return -ENOMEM;
10395
10396 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10397 if (num_des) {
10398 des_len = num_des *
10399 sizeof(struct cfg80211_dscp_exception);
10400 memcpy(qos_map->dscp_exception, pos, des_len);
10401 qos_map->num_des = num_des;
10402 for (des = 0; des < num_des; des++) {
10403 if (qos_map->dscp_exception[des].up > 7) {
10404 kfree(qos_map);
10405 return -EINVAL;
10406 }
10407 }
10408 pos += des_len;
10409 }
10410 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10411 }
10412
10413 wdev_lock(dev->ieee80211_ptr);
10414 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10415 if (!ret)
10416 ret = rdev_set_qos_map(rdev, dev, qos_map);
10417 wdev_unlock(dev->ieee80211_ptr);
10418
10419 kfree(qos_map);
10420 return ret;
10421}
10422
Johannes Berg960d01a2014-09-09 22:55:35 +030010423static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10424{
10425 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10426 struct net_device *dev = info->user_ptr[1];
10427 struct wireless_dev *wdev = dev->ieee80211_ptr;
10428 const u8 *peer;
10429 u8 tsid, up;
10430 u16 admitted_time = 0;
10431 int err;
10432
Johannes Berg723e73a2014-10-22 09:25:06 +020010433 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010434 return -EOPNOTSUPP;
10435
10436 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10437 !info->attrs[NL80211_ATTR_USER_PRIO])
10438 return -EINVAL;
10439
10440 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10441 if (tsid >= IEEE80211_NUM_TIDS)
10442 return -EINVAL;
10443
10444 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10445 if (up >= IEEE80211_NUM_UPS)
10446 return -EINVAL;
10447
10448 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010449 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010450 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010451 * need more attributes for that (e.g. BA session requirement);
10452 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010453 */
10454 return -EINVAL;
10455 }
10456
10457 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10458
10459 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10460 admitted_time =
10461 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10462 if (!admitted_time)
10463 return -EINVAL;
10464 }
10465
10466 wdev_lock(wdev);
10467 switch (wdev->iftype) {
10468 case NL80211_IFTYPE_STATION:
10469 case NL80211_IFTYPE_P2P_CLIENT:
10470 if (wdev->current_bss)
10471 break;
10472 err = -ENOTCONN;
10473 goto out;
10474 default:
10475 err = -EOPNOTSUPP;
10476 goto out;
10477 }
10478
10479 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10480
10481 out:
10482 wdev_unlock(wdev);
10483 return err;
10484}
10485
10486static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10487{
10488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10489 struct net_device *dev = info->user_ptr[1];
10490 struct wireless_dev *wdev = dev->ieee80211_ptr;
10491 const u8 *peer;
10492 u8 tsid;
10493 int err;
10494
10495 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10496 return -EINVAL;
10497
10498 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10499 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10500
10501 wdev_lock(wdev);
10502 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10503 wdev_unlock(wdev);
10504
10505 return err;
10506}
10507
Arik Nemtsov1057d352014-11-19 12:54:26 +020010508static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10509 struct genl_info *info)
10510{
10511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10512 struct net_device *dev = info->user_ptr[1];
10513 struct wireless_dev *wdev = dev->ieee80211_ptr;
10514 struct cfg80211_chan_def chandef = {};
10515 const u8 *addr;
10516 u8 oper_class;
10517 int err;
10518
10519 if (!rdev->ops->tdls_channel_switch ||
10520 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10521 return -EOPNOTSUPP;
10522
10523 switch (dev->ieee80211_ptr->iftype) {
10524 case NL80211_IFTYPE_STATION:
10525 case NL80211_IFTYPE_P2P_CLIENT:
10526 break;
10527 default:
10528 return -EOPNOTSUPP;
10529 }
10530
10531 if (!info->attrs[NL80211_ATTR_MAC] ||
10532 !info->attrs[NL80211_ATTR_OPER_CLASS])
10533 return -EINVAL;
10534
10535 err = nl80211_parse_chandef(rdev, info, &chandef);
10536 if (err)
10537 return err;
10538
10539 /*
10540 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10541 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10542 * specification is not defined for them.
10543 */
10544 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10545 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10546 chandef.width != NL80211_CHAN_WIDTH_20)
10547 return -EINVAL;
10548
10549 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010550 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10551 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010552 return -EINVAL;
10553
10554 /* don't allow switching to DFS channels */
10555 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10556 return -EINVAL;
10557
10558 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10559 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10560
10561 wdev_lock(wdev);
10562 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10563 wdev_unlock(wdev);
10564
10565 return err;
10566}
10567
10568static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10569 struct genl_info *info)
10570{
10571 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10572 struct net_device *dev = info->user_ptr[1];
10573 struct wireless_dev *wdev = dev->ieee80211_ptr;
10574 const u8 *addr;
10575
10576 if (!rdev->ops->tdls_channel_switch ||
10577 !rdev->ops->tdls_cancel_channel_switch ||
10578 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10579 return -EOPNOTSUPP;
10580
10581 switch (dev->ieee80211_ptr->iftype) {
10582 case NL80211_IFTYPE_STATION:
10583 case NL80211_IFTYPE_P2P_CLIENT:
10584 break;
10585 default:
10586 return -EOPNOTSUPP;
10587 }
10588
10589 if (!info->attrs[NL80211_ATTR_MAC])
10590 return -EINVAL;
10591
10592 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10593
10594 wdev_lock(wdev);
10595 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10596 wdev_unlock(wdev);
10597
10598 return 0;
10599}
10600
Johannes Berg4c476992010-10-04 21:36:35 +020010601#define NL80211_FLAG_NEED_WIPHY 0x01
10602#define NL80211_FLAG_NEED_NETDEV 0x02
10603#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010604#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10605#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10606 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010607#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010608/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010609#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10610 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010611#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010612
Johannes Bergf84f7712013-11-14 17:14:45 +010010613static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010614 struct genl_info *info)
10615{
10616 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010617 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010618 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010619 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10620
10621 if (rtnl)
10622 rtnl_lock();
10623
10624 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010625 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010626 if (IS_ERR(rdev)) {
10627 if (rtnl)
10628 rtnl_unlock();
10629 return PTR_ERR(rdev);
10630 }
10631 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010632 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10633 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010634 ASSERT_RTNL();
10635
Johannes Berg89a54e42012-06-15 14:33:17 +020010636 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10637 info->attrs);
10638 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010639 if (rtnl)
10640 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010641 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010642 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010643
Johannes Berg89a54e42012-06-15 14:33:17 +020010644 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010645 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010646
Johannes Berg1bf614e2012-06-15 15:23:36 +020010647 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10648 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010649 if (rtnl)
10650 rtnl_unlock();
10651 return -EINVAL;
10652 }
10653
10654 info->user_ptr[1] = dev;
10655 } else {
10656 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010657 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010658
Johannes Berg1bf614e2012-06-15 15:23:36 +020010659 if (dev) {
10660 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10661 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010662 if (rtnl)
10663 rtnl_unlock();
10664 return -ENETDOWN;
10665 }
10666
10667 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010668 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10669 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010670 if (rtnl)
10671 rtnl_unlock();
10672 return -ENETDOWN;
10673 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010674 }
10675
Johannes Berg4c476992010-10-04 21:36:35 +020010676 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010677 }
10678
10679 return 0;
10680}
10681
Johannes Bergf84f7712013-11-14 17:14:45 +010010682static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010683 struct genl_info *info)
10684{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010685 if (info->user_ptr[1]) {
10686 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10687 struct wireless_dev *wdev = info->user_ptr[1];
10688
10689 if (wdev->netdev)
10690 dev_put(wdev->netdev);
10691 } else {
10692 dev_put(info->user_ptr[1]);
10693 }
10694 }
Johannes Berg5393b912014-09-10 15:00:16 +030010695
Johannes Berg4c476992010-10-04 21:36:35 +020010696 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10697 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010698
10699 /* If needed, clear the netlink message payload from the SKB
10700 * as it might contain key data that shouldn't stick around on
10701 * the heap after the SKB is freed. The netlink message header
10702 * is still needed for further processing, so leave it intact.
10703 */
10704 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10705 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10706
10707 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10708 }
Johannes Berg4c476992010-10-04 21:36:35 +020010709}
10710
Johannes Berg4534de82013-11-14 17:14:46 +010010711static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010712 {
10713 .cmd = NL80211_CMD_GET_WIPHY,
10714 .doit = nl80211_get_wiphy,
10715 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010716 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010717 .policy = nl80211_policy,
10718 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010719 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10720 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010721 },
10722 {
10723 .cmd = NL80211_CMD_SET_WIPHY,
10724 .doit = nl80211_set_wiphy,
10725 .policy = nl80211_policy,
10726 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010727 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010728 },
10729 {
10730 .cmd = NL80211_CMD_GET_INTERFACE,
10731 .doit = nl80211_get_interface,
10732 .dumpit = nl80211_dump_interface,
10733 .policy = nl80211_policy,
10734 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010735 .internal_flags = NL80211_FLAG_NEED_WDEV |
10736 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010737 },
10738 {
10739 .cmd = NL80211_CMD_SET_INTERFACE,
10740 .doit = nl80211_set_interface,
10741 .policy = nl80211_policy,
10742 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010743 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10744 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010745 },
10746 {
10747 .cmd = NL80211_CMD_NEW_INTERFACE,
10748 .doit = nl80211_new_interface,
10749 .policy = nl80211_policy,
10750 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010751 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10752 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010753 },
10754 {
10755 .cmd = NL80211_CMD_DEL_INTERFACE,
10756 .doit = nl80211_del_interface,
10757 .policy = nl80211_policy,
10758 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010759 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010760 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010761 },
Johannes Berg41ade002007-12-19 02:03:29 +010010762 {
10763 .cmd = NL80211_CMD_GET_KEY,
10764 .doit = nl80211_get_key,
10765 .policy = nl80211_policy,
10766 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010767 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010768 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010769 },
10770 {
10771 .cmd = NL80211_CMD_SET_KEY,
10772 .doit = nl80211_set_key,
10773 .policy = nl80211_policy,
10774 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010775 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010776 NL80211_FLAG_NEED_RTNL |
10777 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010778 },
10779 {
10780 .cmd = NL80211_CMD_NEW_KEY,
10781 .doit = nl80211_new_key,
10782 .policy = nl80211_policy,
10783 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010784 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010785 NL80211_FLAG_NEED_RTNL |
10786 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010787 },
10788 {
10789 .cmd = NL80211_CMD_DEL_KEY,
10790 .doit = nl80211_del_key,
10791 .policy = nl80211_policy,
10792 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010793 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010794 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010795 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010796 {
10797 .cmd = NL80211_CMD_SET_BEACON,
10798 .policy = nl80211_policy,
10799 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010800 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010801 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010802 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010803 },
10804 {
Johannes Berg88600202012-02-13 15:17:18 +010010805 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010806 .policy = nl80211_policy,
10807 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010808 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010809 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010810 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010811 },
10812 {
Johannes Berg88600202012-02-13 15:17:18 +010010813 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010814 .policy = nl80211_policy,
10815 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010816 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010817 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010818 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010819 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010820 {
10821 .cmd = NL80211_CMD_GET_STATION,
10822 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010823 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010824 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010825 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10826 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010827 },
10828 {
10829 .cmd = NL80211_CMD_SET_STATION,
10830 .doit = nl80211_set_station,
10831 .policy = nl80211_policy,
10832 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010833 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010834 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010835 },
10836 {
10837 .cmd = NL80211_CMD_NEW_STATION,
10838 .doit = nl80211_new_station,
10839 .policy = nl80211_policy,
10840 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010841 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010842 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010843 },
10844 {
10845 .cmd = NL80211_CMD_DEL_STATION,
10846 .doit = nl80211_del_station,
10847 .policy = nl80211_policy,
10848 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010849 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010850 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010851 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010852 {
10853 .cmd = NL80211_CMD_GET_MPATH,
10854 .doit = nl80211_get_mpath,
10855 .dumpit = nl80211_dump_mpath,
10856 .policy = nl80211_policy,
10857 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010858 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010859 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010860 },
10861 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010862 .cmd = NL80211_CMD_GET_MPP,
10863 .doit = nl80211_get_mpp,
10864 .dumpit = nl80211_dump_mpp,
10865 .policy = nl80211_policy,
10866 .flags = GENL_ADMIN_PERM,
10867 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10868 NL80211_FLAG_NEED_RTNL,
10869 },
10870 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010871 .cmd = NL80211_CMD_SET_MPATH,
10872 .doit = nl80211_set_mpath,
10873 .policy = nl80211_policy,
10874 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010875 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010876 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010877 },
10878 {
10879 .cmd = NL80211_CMD_NEW_MPATH,
10880 .doit = nl80211_new_mpath,
10881 .policy = nl80211_policy,
10882 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010883 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010884 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010885 },
10886 {
10887 .cmd = NL80211_CMD_DEL_MPATH,
10888 .doit = nl80211_del_mpath,
10889 .policy = nl80211_policy,
10890 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010891 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010892 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010893 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010894 {
10895 .cmd = NL80211_CMD_SET_BSS,
10896 .doit = nl80211_set_bss,
10897 .policy = nl80211_policy,
10898 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010899 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010900 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010901 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010902 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010903 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010904 .doit = nl80211_get_reg_do,
10905 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010906 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010907 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010908 /* can be retrieved by unprivileged users */
10909 },
Johannes Bergb6863032015-10-15 09:25:18 +020010910#ifdef CONFIG_CFG80211_CRDA_SUPPORT
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010911 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010912 .cmd = NL80211_CMD_SET_REG,
10913 .doit = nl80211_set_reg,
10914 .policy = nl80211_policy,
10915 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010916 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010917 },
Johannes Bergb6863032015-10-15 09:25:18 +020010918#endif
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010919 {
10920 .cmd = NL80211_CMD_REQ_SET_REG,
10921 .doit = nl80211_req_set_reg,
10922 .policy = nl80211_policy,
10923 .flags = GENL_ADMIN_PERM,
10924 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010925 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010926 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10927 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010928 .policy = nl80211_policy,
10929 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010930 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010931 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010932 },
10933 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010934 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10935 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010936 .policy = nl80211_policy,
10937 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010938 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010939 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010940 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010941 {
Johannes Berg2a519312009-02-10 21:25:55 +010010942 .cmd = NL80211_CMD_TRIGGER_SCAN,
10943 .doit = nl80211_trigger_scan,
10944 .policy = nl80211_policy,
10945 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010946 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010947 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010948 },
10949 {
10950 .cmd = NL80211_CMD_GET_SCAN,
10951 .policy = nl80211_policy,
10952 .dumpit = nl80211_dump_scan,
10953 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010954 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010955 .cmd = NL80211_CMD_START_SCHED_SCAN,
10956 .doit = nl80211_start_sched_scan,
10957 .policy = nl80211_policy,
10958 .flags = GENL_ADMIN_PERM,
10959 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10960 NL80211_FLAG_NEED_RTNL,
10961 },
10962 {
10963 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10964 .doit = nl80211_stop_sched_scan,
10965 .policy = nl80211_policy,
10966 .flags = GENL_ADMIN_PERM,
10967 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10968 NL80211_FLAG_NEED_RTNL,
10969 },
10970 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010971 .cmd = NL80211_CMD_AUTHENTICATE,
10972 .doit = nl80211_authenticate,
10973 .policy = nl80211_policy,
10974 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010976 NL80211_FLAG_NEED_RTNL |
10977 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010978 },
10979 {
10980 .cmd = NL80211_CMD_ASSOCIATE,
10981 .doit = nl80211_associate,
10982 .policy = nl80211_policy,
10983 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010984 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010985 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010986 },
10987 {
10988 .cmd = NL80211_CMD_DEAUTHENTICATE,
10989 .doit = nl80211_deauthenticate,
10990 .policy = nl80211_policy,
10991 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010992 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010993 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010994 },
10995 {
10996 .cmd = NL80211_CMD_DISASSOCIATE,
10997 .doit = nl80211_disassociate,
10998 .policy = nl80211_policy,
10999 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011000 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011001 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020011002 },
Johannes Berg04a773a2009-04-19 21:24:32 +020011003 {
11004 .cmd = NL80211_CMD_JOIN_IBSS,
11005 .doit = nl80211_join_ibss,
11006 .policy = nl80211_policy,
11007 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011008 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011009 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011010 },
11011 {
11012 .cmd = NL80211_CMD_LEAVE_IBSS,
11013 .doit = nl80211_leave_ibss,
11014 .policy = nl80211_policy,
11015 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011016 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011017 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020011018 },
Johannes Bergaff89a92009-07-01 21:26:51 +020011019#ifdef CONFIG_NL80211_TESTMODE
11020 {
11021 .cmd = NL80211_CMD_TESTMODE,
11022 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070011023 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020011024 .policy = nl80211_policy,
11025 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011026 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11027 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020011028 },
11029#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020011030 {
11031 .cmd = NL80211_CMD_CONNECT,
11032 .doit = nl80211_connect,
11033 .policy = nl80211_policy,
11034 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011035 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011036 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011037 },
11038 {
11039 .cmd = NL80211_CMD_DISCONNECT,
11040 .doit = nl80211_disconnect,
11041 .policy = nl80211_policy,
11042 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020011043 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011044 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020011045 },
Johannes Berg463d0182009-07-14 00:33:35 +020011046 {
11047 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
11048 .doit = nl80211_wiphy_netns,
11049 .policy = nl80211_policy,
11050 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011051 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11052 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020011053 },
Holger Schurig61fa7132009-11-11 12:25:40 +010011054 {
11055 .cmd = NL80211_CMD_GET_SURVEY,
11056 .policy = nl80211_policy,
11057 .dumpit = nl80211_dump_survey,
11058 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011059 {
11060 .cmd = NL80211_CMD_SET_PMKSA,
11061 .doit = nl80211_setdel_pmksa,
11062 .policy = nl80211_policy,
11063 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011064 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011065 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011066 },
11067 {
11068 .cmd = NL80211_CMD_DEL_PMKSA,
11069 .doit = nl80211_setdel_pmksa,
11070 .policy = nl80211_policy,
11071 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011072 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011073 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011074 },
11075 {
11076 .cmd = NL80211_CMD_FLUSH_PMKSA,
11077 .doit = nl80211_flush_pmksa,
11078 .policy = nl80211_policy,
11079 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011080 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011081 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010011082 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011083 {
11084 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
11085 .doit = nl80211_remain_on_channel,
11086 .policy = nl80211_policy,
11087 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011088 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011089 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011090 },
11091 {
11092 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
11093 .doit = nl80211_cancel_remain_on_channel,
11094 .policy = nl80211_policy,
11095 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011096 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011097 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011098 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011099 {
11100 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
11101 .doit = nl80211_set_tx_bitrate_mask,
11102 .policy = nl80211_policy,
11103 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011104 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11105 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020011106 },
Jouni Malinen026331c2010-02-15 12:53:10 +020011107 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011108 .cmd = NL80211_CMD_REGISTER_FRAME,
11109 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011110 .policy = nl80211_policy,
11111 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011112 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020011113 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011114 },
11115 {
Johannes Berg2e161f72010-08-12 15:38:38 +020011116 .cmd = NL80211_CMD_FRAME,
11117 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020011118 .policy = nl80211_policy,
11119 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011120 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020011121 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020011122 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020011123 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011124 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
11125 .doit = nl80211_tx_mgmt_cancel_wait,
11126 .policy = nl80211_policy,
11127 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020011128 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010011129 NL80211_FLAG_NEED_RTNL,
11130 },
11131 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020011132 .cmd = NL80211_CMD_SET_POWER_SAVE,
11133 .doit = nl80211_set_power_save,
11134 .policy = nl80211_policy,
11135 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011136 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11137 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011138 },
11139 {
11140 .cmd = NL80211_CMD_GET_POWER_SAVE,
11141 .doit = nl80211_get_power_save,
11142 .policy = nl80211_policy,
11143 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020011144 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11145 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020011146 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011147 {
11148 .cmd = NL80211_CMD_SET_CQM,
11149 .doit = nl80211_set_cqm,
11150 .policy = nl80211_policy,
11151 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011152 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11153 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011154 },
Johannes Bergf444de02010-05-05 15:25:02 +020011155 {
11156 .cmd = NL80211_CMD_SET_CHANNEL,
11157 .doit = nl80211_set_channel,
11158 .policy = nl80211_policy,
11159 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020011160 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11161 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020011162 },
Bill Jordane8347eb2010-10-01 13:54:28 -040011163 {
11164 .cmd = NL80211_CMD_SET_WDS_PEER,
11165 .doit = nl80211_set_wds_peer,
11166 .policy = nl80211_policy,
11167 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011168 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11169 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011170 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011171 {
11172 .cmd = NL80211_CMD_JOIN_MESH,
11173 .doit = nl80211_join_mesh,
11174 .policy = nl80211_policy,
11175 .flags = GENL_ADMIN_PERM,
11176 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11177 NL80211_FLAG_NEED_RTNL,
11178 },
11179 {
11180 .cmd = NL80211_CMD_LEAVE_MESH,
11181 .doit = nl80211_leave_mesh,
11182 .policy = nl80211_policy,
11183 .flags = GENL_ADMIN_PERM,
11184 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11185 NL80211_FLAG_NEED_RTNL,
11186 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011187 {
11188 .cmd = NL80211_CMD_JOIN_OCB,
11189 .doit = nl80211_join_ocb,
11190 .policy = nl80211_policy,
11191 .flags = GENL_ADMIN_PERM,
11192 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11193 NL80211_FLAG_NEED_RTNL,
11194 },
11195 {
11196 .cmd = NL80211_CMD_LEAVE_OCB,
11197 .doit = nl80211_leave_ocb,
11198 .policy = nl80211_policy,
11199 .flags = GENL_ADMIN_PERM,
11200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11201 NL80211_FLAG_NEED_RTNL,
11202 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011203#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011204 {
11205 .cmd = NL80211_CMD_GET_WOWLAN,
11206 .doit = nl80211_get_wowlan,
11207 .policy = nl80211_policy,
11208 /* can be retrieved by unprivileged users */
11209 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11210 NL80211_FLAG_NEED_RTNL,
11211 },
11212 {
11213 .cmd = NL80211_CMD_SET_WOWLAN,
11214 .doit = nl80211_set_wowlan,
11215 .policy = nl80211_policy,
11216 .flags = GENL_ADMIN_PERM,
11217 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11218 NL80211_FLAG_NEED_RTNL,
11219 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011220#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011221 {
11222 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11223 .doit = nl80211_set_rekey_data,
11224 .policy = nl80211_policy,
11225 .flags = GENL_ADMIN_PERM,
11226 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011227 NL80211_FLAG_NEED_RTNL |
11228 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011229 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011230 {
11231 .cmd = NL80211_CMD_TDLS_MGMT,
11232 .doit = nl80211_tdls_mgmt,
11233 .policy = nl80211_policy,
11234 .flags = GENL_ADMIN_PERM,
11235 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11236 NL80211_FLAG_NEED_RTNL,
11237 },
11238 {
11239 .cmd = NL80211_CMD_TDLS_OPER,
11240 .doit = nl80211_tdls_oper,
11241 .policy = nl80211_policy,
11242 .flags = GENL_ADMIN_PERM,
11243 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11244 NL80211_FLAG_NEED_RTNL,
11245 },
Johannes Berg28946da2011-11-04 11:18:12 +010011246 {
11247 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11248 .doit = nl80211_register_unexpected_frame,
11249 .policy = nl80211_policy,
11250 .flags = GENL_ADMIN_PERM,
11251 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11252 NL80211_FLAG_NEED_RTNL,
11253 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011254 {
11255 .cmd = NL80211_CMD_PROBE_CLIENT,
11256 .doit = nl80211_probe_client,
11257 .policy = nl80211_policy,
11258 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011259 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011260 NL80211_FLAG_NEED_RTNL,
11261 },
Johannes Berg5e760232011-11-04 11:18:17 +010011262 {
11263 .cmd = NL80211_CMD_REGISTER_BEACONS,
11264 .doit = nl80211_register_beacons,
11265 .policy = nl80211_policy,
11266 .flags = GENL_ADMIN_PERM,
11267 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11268 NL80211_FLAG_NEED_RTNL,
11269 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011270 {
11271 .cmd = NL80211_CMD_SET_NOACK_MAP,
11272 .doit = nl80211_set_noack_map,
11273 .policy = nl80211_policy,
11274 .flags = GENL_ADMIN_PERM,
11275 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11276 NL80211_FLAG_NEED_RTNL,
11277 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011278 {
11279 .cmd = NL80211_CMD_START_P2P_DEVICE,
11280 .doit = nl80211_start_p2p_device,
11281 .policy = nl80211_policy,
11282 .flags = GENL_ADMIN_PERM,
11283 .internal_flags = NL80211_FLAG_NEED_WDEV |
11284 NL80211_FLAG_NEED_RTNL,
11285 },
11286 {
11287 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11288 .doit = nl80211_stop_p2p_device,
11289 .policy = nl80211_policy,
11290 .flags = GENL_ADMIN_PERM,
11291 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11292 NL80211_FLAG_NEED_RTNL,
11293 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011294 {
11295 .cmd = NL80211_CMD_SET_MCAST_RATE,
11296 .doit = nl80211_set_mcast_rate,
11297 .policy = nl80211_policy,
11298 .flags = GENL_ADMIN_PERM,
11299 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11300 NL80211_FLAG_NEED_RTNL,
11301 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011302 {
11303 .cmd = NL80211_CMD_SET_MAC_ACL,
11304 .doit = nl80211_set_mac_acl,
11305 .policy = nl80211_policy,
11306 .flags = GENL_ADMIN_PERM,
11307 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11308 NL80211_FLAG_NEED_RTNL,
11309 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011310 {
11311 .cmd = NL80211_CMD_RADAR_DETECT,
11312 .doit = nl80211_start_radar_detection,
11313 .policy = nl80211_policy,
11314 .flags = GENL_ADMIN_PERM,
11315 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11316 NL80211_FLAG_NEED_RTNL,
11317 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011318 {
11319 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11320 .doit = nl80211_get_protocol_features,
11321 .policy = nl80211_policy,
11322 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011323 {
11324 .cmd = NL80211_CMD_UPDATE_FT_IES,
11325 .doit = nl80211_update_ft_ies,
11326 .policy = nl80211_policy,
11327 .flags = GENL_ADMIN_PERM,
11328 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11329 NL80211_FLAG_NEED_RTNL,
11330 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011331 {
11332 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11333 .doit = nl80211_crit_protocol_start,
11334 .policy = nl80211_policy,
11335 .flags = GENL_ADMIN_PERM,
11336 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11337 NL80211_FLAG_NEED_RTNL,
11338 },
11339 {
11340 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11341 .doit = nl80211_crit_protocol_stop,
11342 .policy = nl80211_policy,
11343 .flags = GENL_ADMIN_PERM,
11344 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11345 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011346 },
11347 {
11348 .cmd = NL80211_CMD_GET_COALESCE,
11349 .doit = nl80211_get_coalesce,
11350 .policy = nl80211_policy,
11351 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11352 NL80211_FLAG_NEED_RTNL,
11353 },
11354 {
11355 .cmd = NL80211_CMD_SET_COALESCE,
11356 .doit = nl80211_set_coalesce,
11357 .policy = nl80211_policy,
11358 .flags = GENL_ADMIN_PERM,
11359 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11360 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011361 },
11362 {
11363 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11364 .doit = nl80211_channel_switch,
11365 .policy = nl80211_policy,
11366 .flags = GENL_ADMIN_PERM,
11367 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11368 NL80211_FLAG_NEED_RTNL,
11369 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011370 {
11371 .cmd = NL80211_CMD_VENDOR,
11372 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011373 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011374 .policy = nl80211_policy,
11375 .flags = GENL_ADMIN_PERM,
11376 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11377 NL80211_FLAG_NEED_RTNL,
11378 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011379 {
11380 .cmd = NL80211_CMD_SET_QOS_MAP,
11381 .doit = nl80211_set_qos_map,
11382 .policy = nl80211_policy,
11383 .flags = GENL_ADMIN_PERM,
11384 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11385 NL80211_FLAG_NEED_RTNL,
11386 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011387 {
11388 .cmd = NL80211_CMD_ADD_TX_TS,
11389 .doit = nl80211_add_tx_ts,
11390 .policy = nl80211_policy,
11391 .flags = GENL_ADMIN_PERM,
11392 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11393 NL80211_FLAG_NEED_RTNL,
11394 },
11395 {
11396 .cmd = NL80211_CMD_DEL_TX_TS,
11397 .doit = nl80211_del_tx_ts,
11398 .policy = nl80211_policy,
11399 .flags = GENL_ADMIN_PERM,
11400 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11401 NL80211_FLAG_NEED_RTNL,
11402 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011403 {
11404 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11405 .doit = nl80211_tdls_channel_switch,
11406 .policy = nl80211_policy,
11407 .flags = GENL_ADMIN_PERM,
11408 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11409 NL80211_FLAG_NEED_RTNL,
11410 },
11411 {
11412 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11413 .doit = nl80211_tdls_cancel_channel_switch,
11414 .policy = nl80211_policy,
11415 .flags = GENL_ADMIN_PERM,
11416 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11417 NL80211_FLAG_NEED_RTNL,
11418 },
Johannes Berg55682962007-09-20 13:09:35 -040011419};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011420
Johannes Berg55682962007-09-20 13:09:35 -040011421/* notification functions */
11422
Johannes Berg3bb20552014-05-26 13:52:25 +020011423void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11424 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011425{
11426 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011427 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011428
Johannes Berg3bb20552014-05-26 13:52:25 +020011429 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11430 cmd != NL80211_CMD_DEL_WIPHY);
11431
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011432 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011433 if (!msg)
11434 return;
11435
Johannes Berg3bb20552014-05-26 13:52:25 +020011436 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011437 nlmsg_free(msg);
11438 return;
11439 }
11440
Johannes Berg68eb5502013-11-19 15:19:38 +010011441 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011442 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011443}
11444
Johannes Berg362a4152009-05-24 16:43:15 +020011445static int nl80211_add_scan_req(struct sk_buff *msg,
11446 struct cfg80211_registered_device *rdev)
11447{
11448 struct cfg80211_scan_request *req = rdev->scan_req;
11449 struct nlattr *nest;
11450 int i;
11451
11452 if (WARN_ON(!req))
11453 return 0;
11454
11455 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11456 if (!nest)
11457 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011458 for (i = 0; i < req->n_ssids; i++) {
11459 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11460 goto nla_put_failure;
11461 }
Johannes Berg362a4152009-05-24 16:43:15 +020011462 nla_nest_end(msg, nest);
11463
11464 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11465 if (!nest)
11466 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011467 for (i = 0; i < req->n_channels; i++) {
11468 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11469 goto nla_put_failure;
11470 }
Johannes Berg362a4152009-05-24 16:43:15 +020011471 nla_nest_end(msg, nest);
11472
David S. Miller9360ffd2012-03-29 04:41:26 -040011473 if (req->ie &&
11474 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11475 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011476
Johannes Bergae917c92013-10-25 11:05:22 +020011477 if (req->flags &&
11478 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11479 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011480
Johannes Berg362a4152009-05-24 16:43:15 +020011481 return 0;
11482 nla_put_failure:
11483 return -ENOBUFS;
11484}
11485
Johannes Berga538e2d2009-06-16 19:56:42 +020011486static int nl80211_send_scan_msg(struct sk_buff *msg,
11487 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011488 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011489 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011490 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011491{
11492 void *hdr;
11493
Eric W. Biederman15e47302012-09-07 20:12:54 +000011494 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011495 if (!hdr)
11496 return -1;
11497
David S. Miller9360ffd2012-03-29 04:41:26 -040011498 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011499 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11500 wdev->netdev->ifindex)) ||
11501 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011502 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011503
Johannes Berg362a4152009-05-24 16:43:15 +020011504 /* ignore errors and send incomplete event anyway */
11505 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011506
Johannes Berg053c0952015-01-16 22:09:00 +010011507 genlmsg_end(msg, hdr);
11508 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011509
11510 nla_put_failure:
11511 genlmsg_cancel(msg, hdr);
11512 return -EMSGSIZE;
11513}
11514
Luciano Coelho807f8a82011-05-11 17:09:35 +030011515static int
11516nl80211_send_sched_scan_msg(struct sk_buff *msg,
11517 struct cfg80211_registered_device *rdev,
11518 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011519 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011520{
11521 void *hdr;
11522
Eric W. Biederman15e47302012-09-07 20:12:54 +000011523 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011524 if (!hdr)
11525 return -1;
11526
David S. Miller9360ffd2012-03-29 04:41:26 -040011527 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11528 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11529 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011530
Johannes Berg053c0952015-01-16 22:09:00 +010011531 genlmsg_end(msg, hdr);
11532 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011533
11534 nla_put_failure:
11535 genlmsg_cancel(msg, hdr);
11536 return -EMSGSIZE;
11537}
11538
Johannes Berga538e2d2009-06-16 19:56:42 +020011539void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011540 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011541{
11542 struct sk_buff *msg;
11543
Thomas Graf58050fc2012-06-28 03:57:45 +000011544 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011545 if (!msg)
11546 return;
11547
Johannes Bergfd014282012-06-18 19:17:03 +020011548 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011549 NL80211_CMD_TRIGGER_SCAN) < 0) {
11550 nlmsg_free(msg);
11551 return;
11552 }
11553
Johannes Berg68eb5502013-11-19 15:19:38 +010011554 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011555 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011556}
11557
Johannes Bergf9d15d12014-01-22 11:14:19 +020011558struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11559 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011560{
11561 struct sk_buff *msg;
11562
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011563 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011564 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011565 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011566
Johannes Bergfd014282012-06-18 19:17:03 +020011567 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011568 aborted ? NL80211_CMD_SCAN_ABORTED :
11569 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011570 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011571 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011572 }
11573
Johannes Bergf9d15d12014-01-22 11:14:19 +020011574 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011575}
11576
Johannes Bergf9d15d12014-01-22 11:14:19 +020011577void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11578 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011579{
Johannes Berg2a519312009-02-10 21:25:55 +010011580 if (!msg)
11581 return;
11582
Johannes Berg68eb5502013-11-19 15:19:38 +010011583 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011584 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011585}
11586
Luciano Coelho807f8a82011-05-11 17:09:35 +030011587void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11588 struct net_device *netdev)
11589{
11590 struct sk_buff *msg;
11591
11592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11593 if (!msg)
11594 return;
11595
11596 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11597 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11598 nlmsg_free(msg);
11599 return;
11600 }
11601
Johannes Berg68eb5502013-11-19 15:19:38 +010011602 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011603 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011604}
11605
11606void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11607 struct net_device *netdev, u32 cmd)
11608{
11609 struct sk_buff *msg;
11610
Thomas Graf58050fc2012-06-28 03:57:45 +000011611 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011612 if (!msg)
11613 return;
11614
11615 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11616 nlmsg_free(msg);
11617 return;
11618 }
11619
Johannes Berg68eb5502013-11-19 15:19:38 +010011620 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011621 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011622}
11623
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011624static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11625 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011626{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011627 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011628 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11629 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011630
David S. Miller9360ffd2012-03-29 04:41:26 -040011631 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11632 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11633 NL80211_REGDOM_TYPE_WORLD))
11634 goto nla_put_failure;
11635 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11636 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11637 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11638 goto nla_put_failure;
11639 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11640 request->intersect) {
11641 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11642 NL80211_REGDOM_TYPE_INTERSECTION))
11643 goto nla_put_failure;
11644 } else {
11645 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11646 NL80211_REGDOM_TYPE_COUNTRY) ||
11647 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11648 request->alpha2))
11649 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011650 }
11651
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011652 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11653 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11654
11655 if (wiphy &&
11656 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11657 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011658
11659 if (wiphy &&
11660 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11661 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11662 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011663 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011664
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011665 return true;
11666
11667nla_put_failure:
11668 return false;
11669}
11670
11671/*
11672 * This can happen on global regulatory changes or device specific settings
11673 * based on custom regulatory domains.
11674 */
11675void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11676 struct regulatory_request *request)
11677{
11678 struct sk_buff *msg;
11679 void *hdr;
11680
11681 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11682 if (!msg)
11683 return;
11684
11685 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11686 if (!hdr) {
11687 nlmsg_free(msg);
11688 return;
11689 }
11690
11691 if (nl80211_reg_change_event_fill(msg, request) == false)
11692 goto nla_put_failure;
11693
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011694 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011695
Johannes Bergbc43b282009-07-25 10:54:13 +020011696 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011697 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011698 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011699 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011700
11701 return;
11702
11703nla_put_failure:
11704 genlmsg_cancel(msg, hdr);
11705 nlmsg_free(msg);
11706}
11707
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011708static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11709 struct net_device *netdev,
11710 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011711 enum nl80211_commands cmd, gfp_t gfp,
11712 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011713{
11714 struct sk_buff *msg;
11715 void *hdr;
11716
Johannes Berge6d6e342009-07-01 21:26:47 +020011717 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011718 if (!msg)
11719 return;
11720
11721 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11722 if (!hdr) {
11723 nlmsg_free(msg);
11724 return;
11725 }
11726
David S. Miller9360ffd2012-03-29 04:41:26 -040011727 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11728 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11729 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11730 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011731
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011732 if (uapsd_queues >= 0) {
11733 struct nlattr *nla_wmm =
11734 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11735 if (!nla_wmm)
11736 goto nla_put_failure;
11737
11738 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11739 uapsd_queues))
11740 goto nla_put_failure;
11741
11742 nla_nest_end(msg, nla_wmm);
11743 }
11744
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011745 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011746
Johannes Berg68eb5502013-11-19 15:19:38 +010011747 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011748 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011749 return;
11750
11751 nla_put_failure:
11752 genlmsg_cancel(msg, hdr);
11753 nlmsg_free(msg);
11754}
11755
11756void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011757 struct net_device *netdev, const u8 *buf,
11758 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011759{
11760 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011761 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011762}
11763
11764void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11765 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011766 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011767{
Johannes Berge6d6e342009-07-01 21:26:47 +020011768 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011769 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011770}
11771
Jouni Malinen53b46b82009-03-27 20:53:56 +020011772void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011773 struct net_device *netdev, const u8 *buf,
11774 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011775{
11776 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011777 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011778}
11779
Jouni Malinen53b46b82009-03-27 20:53:56 +020011780void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11781 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011782 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011783{
11784 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011785 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011786}
11787
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011788void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11789 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011790{
Johannes Berg947add32013-02-22 22:05:20 +010011791 struct wireless_dev *wdev = dev->ieee80211_ptr;
11792 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011793 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011794 const struct ieee80211_mgmt *mgmt = (void *)buf;
11795 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011796
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011797 if (WARN_ON(len < 2))
11798 return;
11799
11800 if (ieee80211_is_deauth(mgmt->frame_control))
11801 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11802 else
11803 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11804
11805 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011806 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011807}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011808EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011809
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011810static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11811 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011812 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011813{
11814 struct sk_buff *msg;
11815 void *hdr;
11816
Johannes Berge6d6e342009-07-01 21:26:47 +020011817 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011818 if (!msg)
11819 return;
11820
11821 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11822 if (!hdr) {
11823 nlmsg_free(msg);
11824 return;
11825 }
11826
David S. Miller9360ffd2012-03-29 04:41:26 -040011827 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11828 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11829 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11830 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11831 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011832
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011833 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011834
Johannes Berg68eb5502013-11-19 15:19:38 +010011835 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011836 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011837 return;
11838
11839 nla_put_failure:
11840 genlmsg_cancel(msg, hdr);
11841 nlmsg_free(msg);
11842}
11843
11844void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011845 struct net_device *netdev, const u8 *addr,
11846 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011847{
11848 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011849 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011850}
11851
11852void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011853 struct net_device *netdev, const u8 *addr,
11854 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011855{
Johannes Berge6d6e342009-07-01 21:26:47 +020011856 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11857 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011858}
11859
Samuel Ortizb23aa672009-07-01 21:26:54 +020011860void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11861 struct net_device *netdev, const u8 *bssid,
11862 const u8 *req_ie, size_t req_ie_len,
11863 const u8 *resp_ie, size_t resp_ie_len,
11864 u16 status, gfp_t gfp)
11865{
11866 struct sk_buff *msg;
11867 void *hdr;
11868
Thomas Graf58050fc2012-06-28 03:57:45 +000011869 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011870 if (!msg)
11871 return;
11872
11873 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11874 if (!hdr) {
11875 nlmsg_free(msg);
11876 return;
11877 }
11878
David S. Miller9360ffd2012-03-29 04:41:26 -040011879 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11880 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11881 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11882 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11883 (req_ie &&
11884 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11885 (resp_ie &&
11886 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11887 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011888
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011889 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011890
Johannes Berg68eb5502013-11-19 15:19:38 +010011891 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011892 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011893 return;
11894
11895 nla_put_failure:
11896 genlmsg_cancel(msg, hdr);
11897 nlmsg_free(msg);
11898
11899}
11900
11901void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11902 struct net_device *netdev, const u8 *bssid,
11903 const u8 *req_ie, size_t req_ie_len,
11904 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11905{
11906 struct sk_buff *msg;
11907 void *hdr;
11908
Thomas Graf58050fc2012-06-28 03:57:45 +000011909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011910 if (!msg)
11911 return;
11912
11913 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11914 if (!hdr) {
11915 nlmsg_free(msg);
11916 return;
11917 }
11918
David S. Miller9360ffd2012-03-29 04:41:26 -040011919 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11920 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11921 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11922 (req_ie &&
11923 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11924 (resp_ie &&
11925 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11926 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011927
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011928 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011929
Johannes Berg68eb5502013-11-19 15:19:38 +010011930 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011931 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011932 return;
11933
11934 nla_put_failure:
11935 genlmsg_cancel(msg, hdr);
11936 nlmsg_free(msg);
11937
11938}
11939
11940void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11941 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011942 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011943{
11944 struct sk_buff *msg;
11945 void *hdr;
11946
Thomas Graf58050fc2012-06-28 03:57:45 +000011947 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011948 if (!msg)
11949 return;
11950
11951 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11952 if (!hdr) {
11953 nlmsg_free(msg);
11954 return;
11955 }
11956
David S. Miller9360ffd2012-03-29 04:41:26 -040011957 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11958 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11959 (from_ap && reason &&
11960 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11961 (from_ap &&
11962 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11963 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11964 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011965
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011966 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011967
Johannes Berg68eb5502013-11-19 15:19:38 +010011968 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011969 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011970 return;
11971
11972 nla_put_failure:
11973 genlmsg_cancel(msg, hdr);
11974 nlmsg_free(msg);
11975
11976}
11977
Johannes Berg04a773a2009-04-19 21:24:32 +020011978void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11979 struct net_device *netdev, const u8 *bssid,
11980 gfp_t gfp)
11981{
11982 struct sk_buff *msg;
11983 void *hdr;
11984
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011985 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011986 if (!msg)
11987 return;
11988
11989 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11990 if (!hdr) {
11991 nlmsg_free(msg);
11992 return;
11993 }
11994
David S. Miller9360ffd2012-03-29 04:41:26 -040011995 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11996 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11997 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11998 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011999
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012000 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020012001
Johannes Berg68eb5502013-11-19 15:19:38 +010012002 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012003 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020012004 return;
12005
12006 nla_put_failure:
12007 genlmsg_cancel(msg, hdr);
12008 nlmsg_free(msg);
12009}
12010
Johannes Berg947add32013-02-22 22:05:20 +010012011void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
12012 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070012013{
Johannes Berg947add32013-02-22 22:05:20 +010012014 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012015 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012016 struct sk_buff *msg;
12017 void *hdr;
12018
Johannes Berg947add32013-02-22 22:05:20 +010012019 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
12020 return;
12021
12022 trace_cfg80211_notify_new_peer_candidate(dev, addr);
12023
Javier Cardonac93b5e72011-04-07 15:08:34 -070012024 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12025 if (!msg)
12026 return;
12027
12028 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
12029 if (!hdr) {
12030 nlmsg_free(msg);
12031 return;
12032 }
12033
David S. Miller9360ffd2012-03-29 04:41:26 -040012034 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012035 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12036 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012037 (ie_len && ie &&
12038 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
12039 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070012040
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012041 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012042
Johannes Berg68eb5502013-11-19 15:19:38 +010012043 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012044 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012045 return;
12046
12047 nla_put_failure:
12048 genlmsg_cancel(msg, hdr);
12049 nlmsg_free(msg);
12050}
Johannes Berg947add32013-02-22 22:05:20 +010012051EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070012052
Jouni Malinena3b8b052009-03-27 21:59:49 +020012053void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
12054 struct net_device *netdev, const u8 *addr,
12055 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020012056 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020012057{
12058 struct sk_buff *msg;
12059 void *hdr;
12060
Johannes Berge6d6e342009-07-01 21:26:47 +020012061 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012062 if (!msg)
12063 return;
12064
12065 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
12066 if (!hdr) {
12067 nlmsg_free(msg);
12068 return;
12069 }
12070
David S. Miller9360ffd2012-03-29 04:41:26 -040012071 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12072 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12073 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
12074 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
12075 (key_id != -1 &&
12076 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
12077 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
12078 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020012079
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012080 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012081
Johannes Berg68eb5502013-11-19 15:19:38 +010012082 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012083 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020012084 return;
12085
12086 nla_put_failure:
12087 genlmsg_cancel(msg, hdr);
12088 nlmsg_free(msg);
12089}
12090
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012091void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
12092 struct ieee80211_channel *channel_before,
12093 struct ieee80211_channel *channel_after)
12094{
12095 struct sk_buff *msg;
12096 void *hdr;
12097 struct nlattr *nl_freq;
12098
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070012099 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012100 if (!msg)
12101 return;
12102
12103 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
12104 if (!hdr) {
12105 nlmsg_free(msg);
12106 return;
12107 }
12108
12109 /*
12110 * Since we are applying the beacon hint to a wiphy we know its
12111 * wiphy_idx is valid
12112 */
David S. Miller9360ffd2012-03-29 04:41:26 -040012113 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
12114 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012115
12116 /* Before */
12117 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
12118 if (!nl_freq)
12119 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012120 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012121 goto nla_put_failure;
12122 nla_nest_end(msg, nl_freq);
12123
12124 /* After */
12125 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
12126 if (!nl_freq)
12127 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010012128 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012129 goto nla_put_failure;
12130 nla_nest_end(msg, nl_freq);
12131
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012132 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012133
Johannes Berg463d0182009-07-14 00:33:35 +020012134 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010012135 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012136 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020012137 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040012138
12139 return;
12140
12141nla_put_failure:
12142 genlmsg_cancel(msg, hdr);
12143 nlmsg_free(msg);
12144}
12145
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012146static void nl80211_send_remain_on_chan_event(
12147 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020012148 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012149 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012150 unsigned int duration, gfp_t gfp)
12151{
12152 struct sk_buff *msg;
12153 void *hdr;
12154
12155 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12156 if (!msg)
12157 return;
12158
12159 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
12160 if (!hdr) {
12161 nlmsg_free(msg);
12162 return;
12163 }
12164
David S. Miller9360ffd2012-03-29 04:41:26 -040012165 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012166 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12167 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020012168 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012169 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012170 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12171 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012172 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
12173 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012174
David S. Miller9360ffd2012-03-29 04:41:26 -040012175 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12176 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12177 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012178
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012179 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012180
Johannes Berg68eb5502013-11-19 15:19:38 +010012181 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012182 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012183 return;
12184
12185 nla_put_failure:
12186 genlmsg_cancel(msg, hdr);
12187 nlmsg_free(msg);
12188}
12189
Johannes Berg947add32013-02-22 22:05:20 +010012190void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12191 struct ieee80211_channel *chan,
12192 unsigned int duration, 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(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012198 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012199 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012200 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012201}
Johannes Berg947add32013-02-22 22:05:20 +010012202EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012203
Johannes Berg947add32013-02-22 22:05:20 +010012204void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12205 struct ieee80211_channel *chan,
12206 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012207{
Johannes Berg947add32013-02-22 22:05:20 +010012208 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012209 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012210
12211 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012212 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012213 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012214}
Johannes Berg947add32013-02-22 22:05:20 +010012215EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012216
Johannes Berg947add32013-02-22 22:05:20 +010012217void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12218 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012219{
Johannes Berg947add32013-02-22 22:05:20 +010012220 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012221 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012222 struct sk_buff *msg;
12223
Johannes Berg947add32013-02-22 22:05:20 +010012224 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12225
Thomas Graf58050fc2012-06-28 03:57:45 +000012226 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012227 if (!msg)
12228 return;
12229
Johannes Bergcf5ead82014-11-14 17:14:00 +010012230 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012231 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012232 nlmsg_free(msg);
12233 return;
12234 }
12235
Johannes Berg68eb5502013-11-19 15:19:38 +010012236 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012237 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012238}
Johannes Berg947add32013-02-22 22:05:20 +010012239EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012240
Johannes Bergcf5ead82014-11-14 17:14:00 +010012241void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12242 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012243{
Johannes Berg947add32013-02-22 22:05:20 +010012244 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012245 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012246 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012247 struct station_info empty_sinfo = {};
12248
12249 if (!sinfo)
12250 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012251
Johannes Berg947add32013-02-22 22:05:20 +010012252 trace_cfg80211_del_sta(dev, mac_addr);
12253
Thomas Graf58050fc2012-06-28 03:57:45 +000012254 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012255 if (!msg)
12256 return;
12257
Johannes Bergcf5ead82014-11-14 17:14:00 +010012258 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012259 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012260 nlmsg_free(msg);
12261 return;
12262 }
12263
Johannes Berg68eb5502013-11-19 15:19:38 +010012264 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012265 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012266}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012267EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012268
Johannes Berg947add32013-02-22 22:05:20 +010012269void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12270 enum nl80211_connect_failed_reason reason,
12271 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012272{
Johannes Berg947add32013-02-22 22:05:20 +010012273 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012274 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012275 struct sk_buff *msg;
12276 void *hdr;
12277
12278 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12279 if (!msg)
12280 return;
12281
12282 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12283 if (!hdr) {
12284 nlmsg_free(msg);
12285 return;
12286 }
12287
12288 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12289 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12290 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12291 goto nla_put_failure;
12292
12293 genlmsg_end(msg, hdr);
12294
Johannes Berg68eb5502013-11-19 15:19:38 +010012295 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012296 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012297 return;
12298
12299 nla_put_failure:
12300 genlmsg_cancel(msg, hdr);
12301 nlmsg_free(msg);
12302}
Johannes Berg947add32013-02-22 22:05:20 +010012303EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012304
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012305static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12306 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012307{
12308 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012309 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012310 struct sk_buff *msg;
12311 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012312 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012313
Eric W. Biederman15e47302012-09-07 20:12:54 +000012314 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012315 return false;
12316
12317 msg = nlmsg_new(100, gfp);
12318 if (!msg)
12319 return true;
12320
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012321 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012322 if (!hdr) {
12323 nlmsg_free(msg);
12324 return true;
12325 }
12326
David S. Miller9360ffd2012-03-29 04:41:26 -040012327 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12328 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12329 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12330 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012331
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012332 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012333 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012334 return true;
12335
12336 nla_put_failure:
12337 genlmsg_cancel(msg, hdr);
12338 nlmsg_free(msg);
12339 return true;
12340}
12341
Johannes Berg947add32013-02-22 22:05:20 +010012342bool cfg80211_rx_spurious_frame(struct net_device *dev,
12343 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012344{
Johannes Berg947add32013-02-22 22:05:20 +010012345 struct wireless_dev *wdev = dev->ieee80211_ptr;
12346 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012347
Johannes Berg947add32013-02-22 22:05:20 +010012348 trace_cfg80211_rx_spurious_frame(dev, addr);
12349
12350 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12351 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12352 trace_cfg80211_return_bool(false);
12353 return false;
12354 }
12355 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12356 addr, gfp);
12357 trace_cfg80211_return_bool(ret);
12358 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012359}
Johannes Berg947add32013-02-22 22:05:20 +010012360EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12361
12362bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12363 const u8 *addr, gfp_t gfp)
12364{
12365 struct wireless_dev *wdev = dev->ieee80211_ptr;
12366 bool ret;
12367
12368 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12369
12370 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12371 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12372 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12373 trace_cfg80211_return_bool(false);
12374 return false;
12375 }
12376 ret = __nl80211_unexpected_frame(dev,
12377 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12378 addr, gfp);
12379 trace_cfg80211_return_bool(ret);
12380 return ret;
12381}
12382EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012383
Johannes Berg2e161f72010-08-12 15:38:38 +020012384int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012385 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012386 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012387 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012388{
Johannes Berg71bbc992012-06-15 15:30:18 +020012389 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012390 struct sk_buff *msg;
12391 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012392
12393 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12394 if (!msg)
12395 return -ENOMEM;
12396
Johannes Berg2e161f72010-08-12 15:38:38 +020012397 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012398 if (!hdr) {
12399 nlmsg_free(msg);
12400 return -ENOMEM;
12401 }
12402
David S. Miller9360ffd2012-03-29 04:41:26 -040012403 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012404 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12405 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012406 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012407 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12408 (sig_dbm &&
12409 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012410 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12411 (flags &&
12412 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012413 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012414
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012415 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012416
Eric W. Biederman15e47302012-09-07 20:12:54 +000012417 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012418
12419 nla_put_failure:
12420 genlmsg_cancel(msg, hdr);
12421 nlmsg_free(msg);
12422 return -ENOBUFS;
12423}
12424
Johannes Berg947add32013-02-22 22:05:20 +010012425void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12426 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012427{
Johannes Berg947add32013-02-22 22:05:20 +010012428 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012429 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012430 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012431 struct sk_buff *msg;
12432 void *hdr;
12433
Johannes Berg947add32013-02-22 22:05:20 +010012434 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12435
Jouni Malinen026331c2010-02-15 12:53:10 +020012436 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12437 if (!msg)
12438 return;
12439
Johannes Berg2e161f72010-08-12 15:38:38 +020012440 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012441 if (!hdr) {
12442 nlmsg_free(msg);
12443 return;
12444 }
12445
David S. Miller9360ffd2012-03-29 04:41:26 -040012446 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012447 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12448 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012449 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012450 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12451 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12452 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12453 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012454
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012455 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012456
Johannes Berg68eb5502013-11-19 15:19:38 +010012457 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012458 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012459 return;
12460
12461 nla_put_failure:
12462 genlmsg_cancel(msg, hdr);
12463 nlmsg_free(msg);
12464}
Johannes Berg947add32013-02-22 22:05:20 +010012465EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012466
Johannes Berg5b97f492014-11-26 12:37:43 +010012467static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12468 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012469{
Johannes Berg947add32013-02-22 22:05:20 +010012470 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012471 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12472 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12473 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012474
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012475 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012476 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012477
Johannes Berg5b97f492014-11-26 12:37:43 +010012478 cb = (void **)msg->cb;
12479
12480 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12481 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012482 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012483 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012484 }
12485
David S. Miller9360ffd2012-03-29 04:41:26 -040012486 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012487 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012488 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012489
Johannes Berg5b97f492014-11-26 12:37:43 +010012490 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012491 goto nla_put_failure;
12492
Johannes Berg5b97f492014-11-26 12:37:43 +010012493 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12494 if (!cb[1])
12495 goto nla_put_failure;
12496
12497 cb[2] = rdev;
12498
12499 return msg;
12500 nla_put_failure:
12501 nlmsg_free(msg);
12502 return NULL;
12503}
12504
12505static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12506{
12507 void **cb = (void **)msg->cb;
12508 struct cfg80211_registered_device *rdev = cb[2];
12509
12510 nla_nest_end(msg, cb[1]);
12511 genlmsg_end(msg, cb[0]);
12512
12513 memset(msg->cb, 0, sizeof(msg->cb));
12514
12515 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12516 NL80211_MCGRP_MLME, gfp);
12517}
12518
12519void cfg80211_cqm_rssi_notify(struct net_device *dev,
12520 enum nl80211_cqm_rssi_threshold_event rssi_event,
12521 gfp_t gfp)
12522{
12523 struct sk_buff *msg;
12524
12525 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12526
Johannes Berg98f03342014-11-26 12:42:02 +010012527 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12528 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12529 return;
12530
Johannes Berg5b97f492014-11-26 12:37:43 +010012531 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12532 if (!msg)
12533 return;
12534
David S. Miller9360ffd2012-03-29 04:41:26 -040012535 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12536 rssi_event))
12537 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012538
Johannes Berg5b97f492014-11-26 12:37:43 +010012539 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012540
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012541 return;
12542
12543 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012544 nlmsg_free(msg);
12545}
Johannes Berg947add32013-02-22 22:05:20 +010012546EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012547
Johannes Berg5b97f492014-11-26 12:37:43 +010012548void cfg80211_cqm_txe_notify(struct net_device *dev,
12549 const u8 *peer, u32 num_packets,
12550 u32 rate, u32 intvl, gfp_t gfp)
12551{
12552 struct sk_buff *msg;
12553
12554 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12555 if (!msg)
12556 return;
12557
12558 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12559 goto nla_put_failure;
12560
12561 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12562 goto nla_put_failure;
12563
12564 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12565 goto nla_put_failure;
12566
12567 cfg80211_send_cqm(msg, gfp);
12568 return;
12569
12570 nla_put_failure:
12571 nlmsg_free(msg);
12572}
12573EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12574
12575void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12576 const u8 *peer, u32 num_packets, gfp_t gfp)
12577{
12578 struct sk_buff *msg;
12579
12580 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12581
12582 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12583 if (!msg)
12584 return;
12585
12586 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12587 goto nla_put_failure;
12588
12589 cfg80211_send_cqm(msg, gfp);
12590 return;
12591
12592 nla_put_failure:
12593 nlmsg_free(msg);
12594}
12595EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12596
Johannes Berg98f03342014-11-26 12:42:02 +010012597void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12598{
12599 struct sk_buff *msg;
12600
12601 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12602 if (!msg)
12603 return;
12604
12605 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12606 goto nla_put_failure;
12607
12608 cfg80211_send_cqm(msg, gfp);
12609 return;
12610
12611 nla_put_failure:
12612 nlmsg_free(msg);
12613}
12614EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12615
Johannes Berg947add32013-02-22 22:05:20 +010012616static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12617 struct net_device *netdev, const u8 *bssid,
12618 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012619{
12620 struct sk_buff *msg;
12621 struct nlattr *rekey_attr;
12622 void *hdr;
12623
Thomas Graf58050fc2012-06-28 03:57:45 +000012624 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012625 if (!msg)
12626 return;
12627
12628 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12629 if (!hdr) {
12630 nlmsg_free(msg);
12631 return;
12632 }
12633
David S. Miller9360ffd2012-03-29 04:41:26 -040012634 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12635 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12636 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12637 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012638
12639 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12640 if (!rekey_attr)
12641 goto nla_put_failure;
12642
David S. Miller9360ffd2012-03-29 04:41:26 -040012643 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12644 NL80211_REPLAY_CTR_LEN, replay_ctr))
12645 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012646
12647 nla_nest_end(msg, rekey_attr);
12648
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012649 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012650
Johannes Berg68eb5502013-11-19 15:19:38 +010012651 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012652 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012653 return;
12654
12655 nla_put_failure:
12656 genlmsg_cancel(msg, hdr);
12657 nlmsg_free(msg);
12658}
12659
Johannes Berg947add32013-02-22 22:05:20 +010012660void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12661 const u8 *replay_ctr, gfp_t gfp)
12662{
12663 struct wireless_dev *wdev = dev->ieee80211_ptr;
12664 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012665 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012666
12667 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12668 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12669}
12670EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12671
12672static void
12673nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12674 struct net_device *netdev, int index,
12675 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012676{
12677 struct sk_buff *msg;
12678 struct nlattr *attr;
12679 void *hdr;
12680
Thomas Graf58050fc2012-06-28 03:57:45 +000012681 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012682 if (!msg)
12683 return;
12684
12685 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12686 if (!hdr) {
12687 nlmsg_free(msg);
12688 return;
12689 }
12690
David S. Miller9360ffd2012-03-29 04:41:26 -040012691 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12692 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12693 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012694
12695 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12696 if (!attr)
12697 goto nla_put_failure;
12698
David S. Miller9360ffd2012-03-29 04:41:26 -040012699 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12700 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12701 (preauth &&
12702 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12703 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012704
12705 nla_nest_end(msg, attr);
12706
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012707 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012708
Johannes Berg68eb5502013-11-19 15:19:38 +010012709 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012710 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012711 return;
12712
12713 nla_put_failure:
12714 genlmsg_cancel(msg, hdr);
12715 nlmsg_free(msg);
12716}
12717
Johannes Berg947add32013-02-22 22:05:20 +010012718void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12719 const u8 *bssid, bool preauth, gfp_t gfp)
12720{
12721 struct wireless_dev *wdev = dev->ieee80211_ptr;
12722 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012723 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012724
12725 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12726 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12727}
12728EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12729
12730static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12731 struct net_device *netdev,
12732 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012733 gfp_t gfp,
12734 enum nl80211_commands notif,
12735 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012736{
12737 struct sk_buff *msg;
12738 void *hdr;
12739
Thomas Graf58050fc2012-06-28 03:57:45 +000012740 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012741 if (!msg)
12742 return;
12743
Luciano Coelhof8d75522014-11-07 14:31:35 +020012744 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012745 if (!hdr) {
12746 nlmsg_free(msg);
12747 return;
12748 }
12749
Johannes Berg683b6d32012-11-08 21:25:48 +010012750 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12751 goto nla_put_failure;
12752
12753 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012754 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012755
Luciano Coelhof8d75522014-11-07 14:31:35 +020012756 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12757 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12758 goto nla_put_failure;
12759
Thomas Pedersen53145262012-04-06 13:35:47 -070012760 genlmsg_end(msg, hdr);
12761
Johannes Berg68eb5502013-11-19 15:19:38 +010012762 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012763 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012764 return;
12765
12766 nla_put_failure:
12767 genlmsg_cancel(msg, hdr);
12768 nlmsg_free(msg);
12769}
12770
Johannes Berg947add32013-02-22 22:05:20 +010012771void cfg80211_ch_switch_notify(struct net_device *dev,
12772 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012773{
Johannes Berg947add32013-02-22 22:05:20 +010012774 struct wireless_dev *wdev = dev->ieee80211_ptr;
12775 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012776 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012777
Simon Wunderliche487eae2013-11-21 18:19:51 +010012778 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012779
Simon Wunderliche487eae2013-11-21 18:19:51 +010012780 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012781
Michal Kazior9e0e2962014-01-29 14:22:27 +010012782 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012783 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012784 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12785 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012786}
12787EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12788
Luciano Coelhof8d75522014-11-07 14:31:35 +020012789void cfg80211_ch_switch_started_notify(struct net_device *dev,
12790 struct cfg80211_chan_def *chandef,
12791 u8 count)
12792{
12793 struct wireless_dev *wdev = dev->ieee80211_ptr;
12794 struct wiphy *wiphy = wdev->wiphy;
12795 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12796
12797 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12798
12799 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12800 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12801}
12802EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12803
Thomas Pedersen84f10702012-07-12 16:17:33 -070012804void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012805nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012806 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012807 enum nl80211_radar_event event,
12808 struct net_device *netdev, gfp_t gfp)
12809{
12810 struct sk_buff *msg;
12811 void *hdr;
12812
12813 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12814 if (!msg)
12815 return;
12816
12817 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12818 if (!hdr) {
12819 nlmsg_free(msg);
12820 return;
12821 }
12822
12823 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12824 goto nla_put_failure;
12825
12826 /* NOP and radar events don't need a netdev parameter */
12827 if (netdev) {
12828 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12829
12830 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12831 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12832 goto nla_put_failure;
12833 }
12834
12835 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12836 goto nla_put_failure;
12837
12838 if (nl80211_send_chandef(msg, chandef))
12839 goto nla_put_failure;
12840
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012841 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012842
Johannes Berg68eb5502013-11-19 15:19:38 +010012843 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012844 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012845 return;
12846
12847 nla_put_failure:
12848 genlmsg_cancel(msg, hdr);
12849 nlmsg_free(msg);
12850}
12851
Johannes Berg7f6cf312011-11-04 11:18:15 +010012852void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12853 u64 cookie, bool acked, gfp_t gfp)
12854{
12855 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012856 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012857 struct sk_buff *msg;
12858 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012859
Beni Lev4ee3e062012-08-27 12:49:39 +030012860 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12861
Thomas Graf58050fc2012-06-28 03:57:45 +000012862 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012863
Johannes Berg7f6cf312011-11-04 11:18:15 +010012864 if (!msg)
12865 return;
12866
12867 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12868 if (!hdr) {
12869 nlmsg_free(msg);
12870 return;
12871 }
12872
David S. Miller9360ffd2012-03-29 04:41:26 -040012873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12874 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12875 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12876 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12877 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12878 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012879
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012880 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012881
Johannes Berg68eb5502013-11-19 15:19:38 +010012882 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012883 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012884 return;
12885
12886 nla_put_failure:
12887 genlmsg_cancel(msg, hdr);
12888 nlmsg_free(msg);
12889}
12890EXPORT_SYMBOL(cfg80211_probe_status);
12891
Johannes Berg5e760232011-11-04 11:18:17 +010012892void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12893 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012894 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012895{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012896 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012897 struct sk_buff *msg;
12898 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012899 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012900
Beni Lev4ee3e062012-08-27 12:49:39 +030012901 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12902
Ben Greear37c73b52012-10-26 14:49:25 -070012903 spin_lock_bh(&rdev->beacon_registrations_lock);
12904 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12905 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12906 if (!msg) {
12907 spin_unlock_bh(&rdev->beacon_registrations_lock);
12908 return;
12909 }
Johannes Berg5e760232011-11-04 11:18:17 +010012910
Ben Greear37c73b52012-10-26 14:49:25 -070012911 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12912 if (!hdr)
12913 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012914
Ben Greear37c73b52012-10-26 14:49:25 -070012915 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12916 (freq &&
12917 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12918 (sig_dbm &&
12919 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12920 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12921 goto nla_put_failure;
12922
12923 genlmsg_end(msg, hdr);
12924
12925 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012926 }
Ben Greear37c73b52012-10-26 14:49:25 -070012927 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012928 return;
12929
12930 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012931 spin_unlock_bh(&rdev->beacon_registrations_lock);
12932 if (hdr)
12933 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012934 nlmsg_free(msg);
12935}
12936EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12937
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012938#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012939static int cfg80211_net_detect_results(struct sk_buff *msg,
12940 struct cfg80211_wowlan_wakeup *wakeup)
12941{
12942 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12943 struct nlattr *nl_results, *nl_match, *nl_freqs;
12944 int i, j;
12945
12946 nl_results = nla_nest_start(
12947 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12948 if (!nl_results)
12949 return -EMSGSIZE;
12950
12951 for (i = 0; i < nd->n_matches; i++) {
12952 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12953
12954 nl_match = nla_nest_start(msg, i);
12955 if (!nl_match)
12956 break;
12957
12958 /* The SSID attribute is optional in nl80211, but for
12959 * simplicity reasons it's always present in the
12960 * cfg80211 structure. If a driver can't pass the
12961 * SSID, that needs to be changed. A zero length SSID
12962 * is still a valid SSID (wildcard), so it cannot be
12963 * used for this purpose.
12964 */
12965 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12966 match->ssid.ssid)) {
12967 nla_nest_cancel(msg, nl_match);
12968 goto out;
12969 }
12970
12971 if (match->n_channels) {
12972 nl_freqs = nla_nest_start(
12973 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12974 if (!nl_freqs) {
12975 nla_nest_cancel(msg, nl_match);
12976 goto out;
12977 }
12978
12979 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020012980 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012981 nla_nest_cancel(msg, nl_freqs);
12982 nla_nest_cancel(msg, nl_match);
12983 goto out;
12984 }
12985 }
12986
12987 nla_nest_end(msg, nl_freqs);
12988 }
12989
12990 nla_nest_end(msg, nl_match);
12991 }
12992
12993out:
12994 nla_nest_end(msg, nl_results);
12995 return 0;
12996}
12997
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012998void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12999 struct cfg80211_wowlan_wakeup *wakeup,
13000 gfp_t gfp)
13001{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013002 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013003 struct sk_buff *msg;
13004 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013005 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013006
13007 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
13008
13009 if (wakeup)
13010 size += wakeup->packet_present_len;
13011
13012 msg = nlmsg_new(size, gfp);
13013 if (!msg)
13014 return;
13015
13016 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
13017 if (!hdr)
13018 goto free_msg;
13019
13020 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13021 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13022 goto free_msg;
13023
13024 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
13025 wdev->netdev->ifindex))
13026 goto free_msg;
13027
13028 if (wakeup) {
13029 struct nlattr *reasons;
13030
13031 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020013032 if (!reasons)
13033 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013034
13035 if (wakeup->disconnect &&
13036 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
13037 goto free_msg;
13038 if (wakeup->magic_pkt &&
13039 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
13040 goto free_msg;
13041 if (wakeup->gtk_rekey_failure &&
13042 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
13043 goto free_msg;
13044 if (wakeup->eap_identity_req &&
13045 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
13046 goto free_msg;
13047 if (wakeup->four_way_handshake &&
13048 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
13049 goto free_msg;
13050 if (wakeup->rfkill_release &&
13051 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
13052 goto free_msg;
13053
13054 if (wakeup->pattern_idx >= 0 &&
13055 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
13056 wakeup->pattern_idx))
13057 goto free_msg;
13058
Johannes Bergae917c92013-10-25 11:05:22 +020013059 if (wakeup->tcp_match &&
13060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
13061 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013062
Johannes Bergae917c92013-10-25 11:05:22 +020013063 if (wakeup->tcp_connlost &&
13064 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
13065 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013066
Johannes Bergae917c92013-10-25 11:05:22 +020013067 if (wakeup->tcp_nomoretokens &&
13068 nla_put_flag(msg,
13069 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
13070 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010013071
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013072 if (wakeup->packet) {
13073 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
13074 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
13075
13076 if (!wakeup->packet_80211) {
13077 pkt_attr =
13078 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
13079 len_attr =
13080 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
13081 }
13082
13083 if (wakeup->packet_len &&
13084 nla_put_u32(msg, len_attr, wakeup->packet_len))
13085 goto free_msg;
13086
13087 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
13088 wakeup->packet))
13089 goto free_msg;
13090 }
13091
Luciano Coelho8cd4d452014-09-17 11:55:28 +030013092 if (wakeup->net_detect &&
13093 cfg80211_net_detect_results(msg, wakeup))
13094 goto free_msg;
13095
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013096 nla_nest_end(msg, reasons);
13097 }
13098
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013099 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013100
Johannes Berg68eb5502013-11-19 15:19:38 +010013101 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013102 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010013103 return;
13104
13105 free_msg:
13106 nlmsg_free(msg);
13107}
13108EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
13109#endif
13110
Jouni Malinen3475b092012-11-16 22:49:57 +020013111void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
13112 enum nl80211_tdls_operation oper,
13113 u16 reason_code, gfp_t gfp)
13114{
13115 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013116 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020013117 struct sk_buff *msg;
13118 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020013119
13120 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
13121 reason_code);
13122
13123 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13124 if (!msg)
13125 return;
13126
13127 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
13128 if (!hdr) {
13129 nlmsg_free(msg);
13130 return;
13131 }
13132
13133 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13134 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
13135 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
13136 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
13137 (reason_code > 0 &&
13138 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
13139 goto nla_put_failure;
13140
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013141 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020013142
Johannes Berg68eb5502013-11-19 15:19:38 +010013143 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013144 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020013145 return;
13146
13147 nla_put_failure:
13148 genlmsg_cancel(msg, hdr);
13149 nlmsg_free(msg);
13150}
13151EXPORT_SYMBOL(cfg80211_tdls_oper_request);
13152
Jouni Malinen026331c2010-02-15 12:53:10 +020013153static int nl80211_netlink_notify(struct notifier_block * nb,
13154 unsigned long state,
13155 void *_notify)
13156{
13157 struct netlink_notify *notify = _notify;
13158 struct cfg80211_registered_device *rdev;
13159 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070013160 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020013161
13162 if (state != NETLINK_URELEASE)
13163 return NOTIFY_DONE;
13164
13165 rcu_read_lock();
13166
Johannes Berg5e760232011-11-04 11:18:17 +010013167 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013168 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013169 bool schedule_scan_stop = false;
13170 struct cfg80211_sched_scan_request *sched_scan_req =
13171 rcu_dereference(rdev->sched_scan_req);
13172
13173 if (sched_scan_req && notify->portid &&
13174 sched_scan_req->owner_nlportid == notify->portid)
13175 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013176
13177 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013178 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013179
Johannes Berg78f22b62014-03-24 17:57:27 +010013180 if (wdev->owner_nlportid == notify->portid)
13181 schedule_destroy_work = true;
13182 }
13183
Ben Greear37c73b52012-10-26 14:49:25 -070013184 spin_lock_bh(&rdev->beacon_registrations_lock);
13185 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13186 list) {
13187 if (reg->nlportid == notify->portid) {
13188 list_del(&reg->list);
13189 kfree(reg);
13190 break;
13191 }
13192 }
13193 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013194
13195 if (schedule_destroy_work) {
13196 struct cfg80211_iface_destroy *destroy;
13197
13198 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13199 if (destroy) {
13200 destroy->nlportid = notify->portid;
13201 spin_lock(&rdev->destroy_list_lock);
13202 list_add(&destroy->list, &rdev->destroy_list);
13203 spin_unlock(&rdev->destroy_list_lock);
13204 schedule_work(&rdev->destroy_work);
13205 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013206 } else if (schedule_scan_stop) {
13207 sched_scan_req->owner_nlportid = 0;
13208
13209 if (rdev->ops->sched_scan_stop &&
13210 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13211 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013212 }
Johannes Berg5e760232011-11-04 11:18:17 +010013213 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013214
13215 rcu_read_unlock();
13216
Ilan peer05050752015-03-04 00:32:06 -050013217 /*
13218 * It is possible that the user space process that is controlling the
13219 * indoor setting disappeared, so notify the regulatory core.
13220 */
13221 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013222 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013223}
13224
13225static struct notifier_block nl80211_netlink_notifier = {
13226 .notifier_call = nl80211_netlink_notify,
13227};
13228
Jouni Malinen355199e2013-02-27 17:14:27 +020013229void cfg80211_ft_event(struct net_device *netdev,
13230 struct cfg80211_ft_event_params *ft_event)
13231{
13232 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013233 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013234 struct sk_buff *msg;
13235 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013236
13237 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13238
13239 if (!ft_event->target_ap)
13240 return;
13241
13242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13243 if (!msg)
13244 return;
13245
13246 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013247 if (!hdr)
13248 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013249
Johannes Bergae917c92013-10-25 11:05:22 +020013250 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13251 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13252 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13253 goto out;
13254
13255 if (ft_event->ies &&
13256 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13257 goto out;
13258 if (ft_event->ric_ies &&
13259 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13260 ft_event->ric_ies))
13261 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013262
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013263 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013264
Johannes Berg68eb5502013-11-19 15:19:38 +010013265 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013266 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013267 return;
13268 out:
13269 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013270}
13271EXPORT_SYMBOL(cfg80211_ft_event);
13272
Arend van Spriel5de17982013-04-18 15:49:00 +020013273void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13274{
13275 struct cfg80211_registered_device *rdev;
13276 struct sk_buff *msg;
13277 void *hdr;
13278 u32 nlportid;
13279
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013280 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013281 if (!rdev->crit_proto_nlportid)
13282 return;
13283
13284 nlportid = rdev->crit_proto_nlportid;
13285 rdev->crit_proto_nlportid = 0;
13286
13287 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13288 if (!msg)
13289 return;
13290
13291 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13292 if (!hdr)
13293 goto nla_put_failure;
13294
13295 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13296 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13297 goto nla_put_failure;
13298
13299 genlmsg_end(msg, hdr);
13300
13301 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13302 return;
13303
13304 nla_put_failure:
13305 if (hdr)
13306 genlmsg_cancel(msg, hdr);
13307 nlmsg_free(msg);
13308
13309}
13310EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13311
Johannes Berg348baf02014-01-24 14:06:29 +010013312void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13313{
13314 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013315 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013316 struct sk_buff *msg;
13317 void *hdr;
13318
13319 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13320 if (!msg)
13321 return;
13322
13323 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13324 if (!hdr)
13325 goto out;
13326
13327 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13328 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
13329 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13330 goto out;
13331
13332 genlmsg_end(msg, hdr);
13333
13334 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13335 NL80211_MCGRP_MLME, GFP_KERNEL);
13336 return;
13337 out:
13338 nlmsg_free(msg);
13339}
13340
Johannes Berg55682962007-09-20 13:09:35 -040013341/* initialisation/exit functions */
13342
13343int nl80211_init(void)
13344{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013345 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013346
Johannes Berg2a94fe42013-11-19 15:19:39 +010013347 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13348 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013349 if (err)
13350 return err;
13351
Jouni Malinen026331c2010-02-15 12:53:10 +020013352 err = netlink_register_notifier(&nl80211_netlink_notifier);
13353 if (err)
13354 goto err_out;
13355
Johannes Berg55682962007-09-20 13:09:35 -040013356 return 0;
13357 err_out:
13358 genl_unregister_family(&nl80211_fam);
13359 return err;
13360}
13361
13362void nl80211_exit(void)
13363{
Jouni Malinen026331c2010-02-15 12:53:10 +020013364 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013365 genl_unregister_family(&nl80211_fam);
13366}