blob: fb0712b3d9cbfc97b7b3a3e6e936cb774d5e79d4 [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
Johannes Berg97990a02013-04-19 01:02:55 +0200482static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
483 struct netlink_callback *cb,
484 struct cfg80211_registered_device **rdev,
485 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100486{
Johannes Berg67748892010-10-04 21:14:06 +0200487 int err;
488
Johannes Berg67748892010-10-04 21:14:06 +0200489 rtnl_lock();
490
Johannes Berg97990a02013-04-19 01:02:55 +0200491 if (!cb->args[0]) {
492 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
493 nl80211_fam.attrbuf, nl80211_fam.maxattr,
494 nl80211_policy);
495 if (err)
496 goto out_unlock;
497
498 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
499 nl80211_fam.attrbuf);
500 if (IS_ERR(*wdev)) {
501 err = PTR_ERR(*wdev);
502 goto out_unlock;
503 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800504 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200505 /* 0 is the first index - add 1 to parse only once */
506 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200507 cb->args[1] = (*wdev)->identifier;
508 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200509 /* subtract the 1 again here */
510 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200511 struct wireless_dev *tmp;
512
513 if (!wiphy) {
514 err = -ENODEV;
515 goto out_unlock;
516 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800517 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200518 *wdev = NULL;
519
Johannes Berg97990a02013-04-19 01:02:55 +0200520 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
521 if (tmp->identifier == cb->args[1]) {
522 *wdev = tmp;
523 break;
524 }
525 }
Johannes Berg97990a02013-04-19 01:02:55 +0200526
527 if (!*wdev) {
528 err = -ENODEV;
529 goto out_unlock;
530 }
Johannes Berg67748892010-10-04 21:14:06 +0200531 }
532
Johannes Berg67748892010-10-04 21:14:06 +0200533 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200534 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200535 rtnl_unlock();
536 return err;
537}
538
Johannes Berg97990a02013-04-19 01:02:55 +0200539static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200540{
Johannes Berg67748892010-10-04 21:14:06 +0200541 rtnl_unlock();
542}
543
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100544/* IE validation */
545static bool is_valid_ie_attr(const struct nlattr *attr)
546{
547 const u8 *pos;
548 int len;
549
550 if (!attr)
551 return true;
552
553 pos = nla_data(attr);
554 len = nla_len(attr);
555
556 while (len) {
557 u8 elemlen;
558
559 if (len < 2)
560 return false;
561 len -= 2;
562
563 elemlen = pos[1];
564 if (elemlen > len)
565 return false;
566
567 len -= elemlen;
568 pos += 2 + elemlen;
569 }
570
571 return true;
572}
573
Johannes Berg55682962007-09-20 13:09:35 -0400574/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000575static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400576 int flags, u8 cmd)
577{
578 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000579 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400580}
581
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400582static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100583 struct ieee80211_channel *chan,
584 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400585{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200586 /* Some channels must be completely excluded from the
587 * list to protect old user-space tools from breaking
588 */
589 if (!large && chan->flags &
590 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
591 return 0;
592
David S. Miller9360ffd2012-03-29 04:41:26 -0400593 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
594 chan->center_freq))
595 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400596
David S. Miller9360ffd2012-03-29 04:41:26 -0400597 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
598 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
599 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200600 if (chan->flags & IEEE80211_CHAN_NO_IR) {
601 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
602 goto nla_put_failure;
603 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
604 goto nla_put_failure;
605 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100606 if (chan->flags & IEEE80211_CHAN_RADAR) {
607 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
608 goto nla_put_failure;
609 if (large) {
610 u32 time;
611
612 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
613
614 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
615 chan->dfs_state))
616 goto nla_put_failure;
617 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
618 time))
619 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100620 if (nla_put_u32(msg,
621 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
622 chan->dfs_cac_ms))
623 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100624 }
625 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400626
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100627 if (large) {
628 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
629 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
630 goto nla_put_failure;
631 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
632 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
633 goto nla_put_failure;
634 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
635 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
636 goto nla_put_failure;
637 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
638 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
639 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200640 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
641 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
642 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300643 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
644 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200645 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200646 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
647 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
648 goto nla_put_failure;
649 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
650 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
651 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100652 }
653
David S. Miller9360ffd2012-03-29 04:41:26 -0400654 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
655 DBM_TO_MBM(chan->max_power)))
656 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400657
658 return 0;
659
660 nla_put_failure:
661 return -ENOBUFS;
662}
663
Johannes Berg55682962007-09-20 13:09:35 -0400664/* netlink command implementations */
665
Johannes Bergb9454e82009-07-08 13:29:08 +0200666struct key_parse {
667 struct key_params p;
668 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200669 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200670 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100671 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200672};
673
674static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
675{
676 struct nlattr *tb[NL80211_KEY_MAX + 1];
677 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
678 nl80211_key_policy);
679 if (err)
680 return err;
681
682 k->def = !!tb[NL80211_KEY_DEFAULT];
683 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
684
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100685 if (k->def) {
686 k->def_uni = true;
687 k->def_multi = true;
688 }
689 if (k->defmgmt)
690 k->def_multi = true;
691
Johannes Bergb9454e82009-07-08 13:29:08 +0200692 if (tb[NL80211_KEY_IDX])
693 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
694
695 if (tb[NL80211_KEY_DATA]) {
696 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
697 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
698 }
699
700 if (tb[NL80211_KEY_SEQ]) {
701 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
702 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
703 }
704
705 if (tb[NL80211_KEY_CIPHER])
706 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
707
Johannes Berge31b8212010-10-05 19:39:30 +0200708 if (tb[NL80211_KEY_TYPE]) {
709 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
710 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
711 return -EINVAL;
712 }
713
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100714 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
715 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100716 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
717 tb[NL80211_KEY_DEFAULT_TYPES],
718 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100719 if (err)
720 return err;
721
722 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
723 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
724 }
725
Johannes Bergb9454e82009-07-08 13:29:08 +0200726 return 0;
727}
728
729static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
730{
731 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
732 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
733 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
734 }
735
736 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
737 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
738 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
739 }
740
741 if (info->attrs[NL80211_ATTR_KEY_IDX])
742 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
743
744 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
745 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
746
747 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
748 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
749
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100750 if (k->def) {
751 k->def_uni = true;
752 k->def_multi = true;
753 }
754 if (k->defmgmt)
755 k->def_multi = true;
756
Johannes Berge31b8212010-10-05 19:39:30 +0200757 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
758 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
759 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
760 return -EINVAL;
761 }
762
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100763 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
764 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
765 int err = nla_parse_nested(
766 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
767 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
768 nl80211_key_default_policy);
769 if (err)
770 return err;
771
772 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
773 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
774 }
775
Johannes Bergb9454e82009-07-08 13:29:08 +0200776 return 0;
777}
778
779static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
780{
781 int err;
782
783 memset(k, 0, sizeof(*k));
784 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200785 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200786
787 if (info->attrs[NL80211_ATTR_KEY])
788 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
789 else
790 err = nl80211_parse_key_old(info, k);
791
792 if (err)
793 return err;
794
795 if (k->def && k->defmgmt)
796 return -EINVAL;
797
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100798 if (k->defmgmt) {
799 if (k->def_uni || !k->def_multi)
800 return -EINVAL;
801 }
802
Johannes Bergb9454e82009-07-08 13:29:08 +0200803 if (k->idx != -1) {
804 if (k->defmgmt) {
805 if (k->idx < 4 || k->idx > 5)
806 return -EINVAL;
807 } else if (k->def) {
808 if (k->idx < 0 || k->idx > 3)
809 return -EINVAL;
810 } else {
811 if (k->idx < 0 || k->idx > 5)
812 return -EINVAL;
813 }
814 }
815
816 return 0;
817}
818
Johannes Bergfffd0932009-07-08 14:22:54 +0200819static struct cfg80211_cached_keys *
820nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530821 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200822{
823 struct key_parse parse;
824 struct nlattr *key;
825 struct cfg80211_cached_keys *result;
826 int rem, err, def = 0;
827
828 result = kzalloc(sizeof(*result), GFP_KERNEL);
829 if (!result)
830 return ERR_PTR(-ENOMEM);
831
832 result->def = -1;
833 result->defmgmt = -1;
834
835 nla_for_each_nested(key, keys, rem) {
836 memset(&parse, 0, sizeof(parse));
837 parse.idx = -1;
838
839 err = nl80211_parse_key_new(key, &parse);
840 if (err)
841 goto error;
842 err = -EINVAL;
843 if (!parse.p.key)
844 goto error;
845 if (parse.idx < 0 || parse.idx > 4)
846 goto error;
847 if (parse.def) {
848 if (def)
849 goto error;
850 def = 1;
851 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100852 if (!parse.def_uni || !parse.def_multi)
853 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200854 } else if (parse.defmgmt)
855 goto error;
856 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200857 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200858 if (err)
859 goto error;
860 result->params[parse.idx].cipher = parse.p.cipher;
861 result->params[parse.idx].key_len = parse.p.key_len;
862 result->params[parse.idx].key = result->data[parse.idx];
863 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530864
865 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
866 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
867 if (no_ht)
868 *no_ht = true;
869 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200870 }
871
872 return result;
873 error:
874 kfree(result);
875 return ERR_PTR(err);
876}
877
878static int nl80211_key_allowed(struct wireless_dev *wdev)
879{
880 ASSERT_WDEV_LOCK(wdev);
881
Johannes Bergfffd0932009-07-08 14:22:54 +0200882 switch (wdev->iftype) {
883 case NL80211_IFTYPE_AP:
884 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200885 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700886 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200887 break;
888 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200889 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200890 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200891 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200892 return -ENOLINK;
893 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100894 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100895 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100896 case NL80211_IFTYPE_MONITOR:
897 case NL80211_IFTYPE_P2P_DEVICE:
898 case NL80211_IFTYPE_WDS:
899 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200900 return -EINVAL;
901 }
902
903 return 0;
904}
905
Jouni Malinen664834d2014-01-15 00:01:44 +0200906static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
907 struct nlattr *tb)
908{
909 struct ieee80211_channel *chan;
910
911 if (tb == NULL)
912 return NULL;
913 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
914 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
915 return NULL;
916 return chan;
917}
918
Johannes Berg7527a782011-05-13 10:58:57 +0200919static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
920{
921 struct nlattr *nl_modes = nla_nest_start(msg, attr);
922 int i;
923
924 if (!nl_modes)
925 goto nla_put_failure;
926
927 i = 0;
928 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400929 if ((ifmodes & 1) && nla_put_flag(msg, i))
930 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200931 ifmodes >>= 1;
932 i++;
933 }
934
935 nla_nest_end(msg, nl_modes);
936 return 0;
937
938nla_put_failure:
939 return -ENOBUFS;
940}
941
942static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100943 struct sk_buff *msg,
944 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200945{
946 struct nlattr *nl_combis;
947 int i, j;
948
949 nl_combis = nla_nest_start(msg,
950 NL80211_ATTR_INTERFACE_COMBINATIONS);
951 if (!nl_combis)
952 goto nla_put_failure;
953
954 for (i = 0; i < wiphy->n_iface_combinations; i++) {
955 const struct ieee80211_iface_combination *c;
956 struct nlattr *nl_combi, *nl_limits;
957
958 c = &wiphy->iface_combinations[i];
959
960 nl_combi = nla_nest_start(msg, i + 1);
961 if (!nl_combi)
962 goto nla_put_failure;
963
964 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
965 if (!nl_limits)
966 goto nla_put_failure;
967
968 for (j = 0; j < c->n_limits; j++) {
969 struct nlattr *nl_limit;
970
971 nl_limit = nla_nest_start(msg, j + 1);
972 if (!nl_limit)
973 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400974 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
975 c->limits[j].max))
976 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200977 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
978 c->limits[j].types))
979 goto nla_put_failure;
980 nla_nest_end(msg, nl_limit);
981 }
982
983 nla_nest_end(msg, nl_limits);
984
David S. Miller9360ffd2012-03-29 04:41:26 -0400985 if (c->beacon_int_infra_match &&
986 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
987 goto nla_put_failure;
988 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
989 c->num_different_channels) ||
990 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
991 c->max_interfaces))
992 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100993 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200994 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
995 c->radar_detect_widths) ||
996 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
997 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100998 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200999
1000 nla_nest_end(msg, nl_combi);
1001 }
1002
1003 nla_nest_end(msg, nl_combis);
1004
1005 return 0;
1006nla_put_failure:
1007 return -ENOBUFS;
1008}
1009
Johannes Berg3713b4e2013-02-14 16:19:38 +01001010#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001011static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1012 struct sk_buff *msg)
1013{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001014 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001015 struct nlattr *nl_tcp;
1016
1017 if (!tcp)
1018 return 0;
1019
1020 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1021 if (!nl_tcp)
1022 return -ENOBUFS;
1023
1024 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1025 tcp->data_payload_max))
1026 return -ENOBUFS;
1027
1028 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1029 tcp->data_payload_max))
1030 return -ENOBUFS;
1031
1032 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1033 return -ENOBUFS;
1034
1035 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1036 sizeof(*tcp->tok), tcp->tok))
1037 return -ENOBUFS;
1038
1039 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1040 tcp->data_interval_max))
1041 return -ENOBUFS;
1042
1043 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1044 tcp->wake_payload_max))
1045 return -ENOBUFS;
1046
1047 nla_nest_end(msg, nl_tcp);
1048 return 0;
1049}
1050
Johannes Berg3713b4e2013-02-14 16:19:38 +01001051static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001052 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001053 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001054{
1055 struct nlattr *nl_wowlan;
1056
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001057 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001058 return 0;
1059
1060 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1061 if (!nl_wowlan)
1062 return -ENOBUFS;
1063
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001067 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001068 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001071 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001073 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001074 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001077 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001078 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001079 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1080 return -ENOBUFS;
1081
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001082 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001083 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001084 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1085 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1086 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1087 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001088 };
1089
1090 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1091 sizeof(pat), &pat))
1092 return -ENOBUFS;
1093 }
1094
Luciano Coelho75453cc2015-01-09 14:06:37 +02001095 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1096 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1097 rdev->wiphy.wowlan->max_nd_match_sets))
1098 return -ENOBUFS;
1099
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001100 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001101 return -ENOBUFS;
1102
Johannes Berg3713b4e2013-02-14 16:19:38 +01001103 nla_nest_end(msg, nl_wowlan);
1104
1105 return 0;
1106}
1107#endif
1108
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001109static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001110 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001111{
1112 struct nl80211_coalesce_rule_support rule;
1113
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001114 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001115 return 0;
1116
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001117 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1118 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1119 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1120 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1121 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1122 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001123
1124 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1125 return -ENOBUFS;
1126
1127 return 0;
1128}
1129
Johannes Berg3713b4e2013-02-14 16:19:38 +01001130static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1131 struct ieee80211_supported_band *sband)
1132{
1133 struct nlattr *nl_rates, *nl_rate;
1134 struct ieee80211_rate *rate;
1135 int i;
1136
1137 /* add HT info */
1138 if (sband->ht_cap.ht_supported &&
1139 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1140 sizeof(sband->ht_cap.mcs),
1141 &sband->ht_cap.mcs) ||
1142 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1143 sband->ht_cap.cap) ||
1144 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1145 sband->ht_cap.ampdu_factor) ||
1146 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1147 sband->ht_cap.ampdu_density)))
1148 return -ENOBUFS;
1149
1150 /* add VHT info */
1151 if (sband->vht_cap.vht_supported &&
1152 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1153 sizeof(sband->vht_cap.vht_mcs),
1154 &sband->vht_cap.vht_mcs) ||
1155 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1156 sband->vht_cap.cap)))
1157 return -ENOBUFS;
1158
1159 /* add bitrates */
1160 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1161 if (!nl_rates)
1162 return -ENOBUFS;
1163
1164 for (i = 0; i < sband->n_bitrates; i++) {
1165 nl_rate = nla_nest_start(msg, i);
1166 if (!nl_rate)
1167 return -ENOBUFS;
1168
1169 rate = &sband->bitrates[i];
1170 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1171 rate->bitrate))
1172 return -ENOBUFS;
1173 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1174 nla_put_flag(msg,
1175 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1176 return -ENOBUFS;
1177
1178 nla_nest_end(msg, nl_rate);
1179 }
1180
1181 nla_nest_end(msg, nl_rates);
1182
1183 return 0;
1184}
1185
1186static int
1187nl80211_send_mgmt_stypes(struct sk_buff *msg,
1188 const struct ieee80211_txrx_stypes *mgmt_stypes)
1189{
1190 u16 stypes;
1191 struct nlattr *nl_ftypes, *nl_ifs;
1192 enum nl80211_iftype ift;
1193 int i;
1194
1195 if (!mgmt_stypes)
1196 return 0;
1197
1198 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1199 if (!nl_ifs)
1200 return -ENOBUFS;
1201
1202 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1203 nl_ftypes = nla_nest_start(msg, ift);
1204 if (!nl_ftypes)
1205 return -ENOBUFS;
1206 i = 0;
1207 stypes = mgmt_stypes[ift].tx;
1208 while (stypes) {
1209 if ((stypes & 1) &&
1210 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1211 (i << 4) | IEEE80211_FTYPE_MGMT))
1212 return -ENOBUFS;
1213 stypes >>= 1;
1214 i++;
1215 }
1216 nla_nest_end(msg, nl_ftypes);
1217 }
1218
1219 nla_nest_end(msg, nl_ifs);
1220
1221 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1222 if (!nl_ifs)
1223 return -ENOBUFS;
1224
1225 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1226 nl_ftypes = nla_nest_start(msg, ift);
1227 if (!nl_ftypes)
1228 return -ENOBUFS;
1229 i = 0;
1230 stypes = mgmt_stypes[ift].rx;
1231 while (stypes) {
1232 if ((stypes & 1) &&
1233 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1234 (i << 4) | IEEE80211_FTYPE_MGMT))
1235 return -ENOBUFS;
1236 stypes >>= 1;
1237 i++;
1238 }
1239 nla_nest_end(msg, nl_ftypes);
1240 }
1241 nla_nest_end(msg, nl_ifs);
1242
1243 return 0;
1244}
1245
Johannes Berg86e8cf92013-06-19 10:57:22 +02001246struct nl80211_dump_wiphy_state {
1247 s64 filter_wiphy;
1248 long start;
1249 long split_start, band_start, chan_start;
1250 bool split;
1251};
1252
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001253static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001254 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001255 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001256 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001257{
1258 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001259 struct nlattr *nl_bands, *nl_band;
1260 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001261 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001262 enum ieee80211_band band;
1263 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001264 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001265 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001266 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001267 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001268
Johannes Berg3bb20552014-05-26 13:52:25 +02001269 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001270 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001271 return -ENOBUFS;
1272
Johannes Berg86e8cf92013-06-19 10:57:22 +02001273 if (WARN_ON(!state))
1274 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001275
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001276 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001277 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001278 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001279 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001280 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001281 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001282
Johannes Berg3bb20552014-05-26 13:52:25 +02001283 if (cmd != NL80211_CMD_NEW_WIPHY)
1284 goto finish;
1285
Johannes Berg86e8cf92013-06-19 10:57:22 +02001286 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001287 case 0:
1288 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001289 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001290 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001291 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001295 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001296 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001297 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001299 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001300 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001301 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001302 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001303 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001304 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001305 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001307 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001308 goto nla_put_failure;
1309
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001310 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001311 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1312 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001313 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001314 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1315 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001316 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001317 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1318 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001319 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001320 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1321 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001322 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001323 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1324 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001326 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001327 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001328 state->split_start++;
1329 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001330 break;
1331 case 1:
1332 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001333 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1334 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001335 goto nla_put_failure;
1336
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001338 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001339 goto nla_put_failure;
1340
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001341 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001342 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1343 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001344
Johannes Berg3713b4e2013-02-14 16:19:38 +01001345 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001346 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001347 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001348 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001349 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001350
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001351 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001352 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001353 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001355
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001356 if ((rdev->wiphy.available_antennas_tx ||
1357 rdev->wiphy.available_antennas_rx) &&
1358 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001359 u32 tx_ant = 0, rx_ant = 0;
1360 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001361 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001362 if (!res) {
1363 if (nla_put_u32(msg,
1364 NL80211_ATTR_WIPHY_ANTENNA_TX,
1365 tx_ant) ||
1366 nla_put_u32(msg,
1367 NL80211_ATTR_WIPHY_ANTENNA_RX,
1368 rx_ant))
1369 goto nla_put_failure;
1370 }
Johannes Bergee688b002008-01-24 19:38:39 +01001371 }
1372
Johannes Berg86e8cf92013-06-19 10:57:22 +02001373 state->split_start++;
1374 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001375 break;
1376 case 2:
1377 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001378 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001379 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001380 state->split_start++;
1381 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001382 break;
1383 case 3:
1384 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1385 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001386 goto nla_put_failure;
1387
Johannes Berg86e8cf92013-06-19 10:57:22 +02001388 for (band = state->band_start;
1389 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001390 struct ieee80211_supported_band *sband;
1391
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001392 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001393
1394 if (!sband)
1395 continue;
1396
1397 nl_band = nla_nest_start(msg, band);
1398 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001399 goto nla_put_failure;
1400
Johannes Berg86e8cf92013-06-19 10:57:22 +02001401 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001402 case 0:
1403 if (nl80211_send_band_rateinfo(msg, sband))
1404 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001405 state->chan_start++;
1406 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001407 break;
1408 default:
1409 /* add frequencies */
1410 nl_freqs = nla_nest_start(
1411 msg, NL80211_BAND_ATTR_FREQS);
1412 if (!nl_freqs)
1413 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001414
Johannes Berg86e8cf92013-06-19 10:57:22 +02001415 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001416 i < sband->n_channels;
1417 i++) {
1418 nl_freq = nla_nest_start(msg, i);
1419 if (!nl_freq)
1420 goto nla_put_failure;
1421
1422 chan = &sband->channels[i];
1423
Johannes Berg86e8cf92013-06-19 10:57:22 +02001424 if (nl80211_msg_put_channel(
1425 msg, chan,
1426 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 goto nla_put_failure;
1428
1429 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001430 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001431 break;
1432 }
1433 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001434 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001436 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 nla_nest_end(msg, nl_freqs);
1438 }
1439
1440 nla_nest_end(msg, nl_band);
1441
Johannes Berg86e8cf92013-06-19 10:57:22 +02001442 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001444 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 band--;
1446 break;
1447 }
Johannes Bergee688b002008-01-24 19:38:39 +01001448 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001449 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001450
Johannes Berg3713b4e2013-02-14 16:19:38 +01001451 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001452 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001453 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001454 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001455
Johannes Berg3713b4e2013-02-14 16:19:38 +01001456 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001457 if (state->band_start == 0 && state->chan_start == 0)
1458 state->split_start++;
1459 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001460 break;
1461 case 4:
1462 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1463 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001464 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001465
1466 i = 0;
1467#define CMD(op, n) \
1468 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001469 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001470 i++; \
1471 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1472 goto nla_put_failure; \
1473 } \
1474 } while (0)
1475
1476 CMD(add_virtual_intf, NEW_INTERFACE);
1477 CMD(change_virtual_intf, SET_INTERFACE);
1478 CMD(add_key, NEW_KEY);
1479 CMD(start_ap, START_AP);
1480 CMD(add_station, NEW_STATION);
1481 CMD(add_mpath, NEW_MPATH);
1482 CMD(update_mesh_config, SET_MESH_CONFIG);
1483 CMD(change_bss, SET_BSS);
1484 CMD(auth, AUTHENTICATE);
1485 CMD(assoc, ASSOCIATE);
1486 CMD(deauth, DEAUTHENTICATE);
1487 CMD(disassoc, DISASSOCIATE);
1488 CMD(join_ibss, JOIN_IBSS);
1489 CMD(join_mesh, JOIN_MESH);
1490 CMD(set_pmksa, SET_PMKSA);
1491 CMD(del_pmksa, DEL_PMKSA);
1492 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001493 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001494 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1495 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1496 CMD(mgmt_tx, FRAME);
1497 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001498 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001499 i++;
1500 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1501 goto nla_put_failure;
1502 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001503 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1504 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001505 i++;
1506 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1507 goto nla_put_failure;
1508 }
1509 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001510 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 CMD(tdls_mgmt, TDLS_MGMT);
1512 CMD(tdls_oper, TDLS_OPER);
1513 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001514 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001515 CMD(sched_scan_start, START_SCHED_SCAN);
1516 CMD(probe_client, PROBE_CLIENT);
1517 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001518 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001519 i++;
1520 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1521 goto nla_put_failure;
1522 }
1523 CMD(start_p2p_device, START_P2P_DEVICE);
1524 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001525#ifdef CONFIG_NL80211_TESTMODE
1526 CMD(testmode_cmd, TESTMODE);
1527#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001528 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001529 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1530 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001531 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001532 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001533 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001534 if (rdev->wiphy.features &
1535 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001536 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001537 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001538 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001539#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001540
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001541 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001542 i++;
1543 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001544 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001545 }
1546
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001547 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 i++;
1549 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1550 goto nla_put_failure;
1551 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001552
Johannes Berg3713b4e2013-02-14 16:19:38 +01001553 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001554 state->split_start++;
1555 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001556 break;
1557 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001558 if (rdev->ops->remain_on_channel &&
1559 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001560 nla_put_u32(msg,
1561 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001562 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001563 goto nla_put_failure;
1564
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001565 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001566 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1567 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001568
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1570 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001571 state->split_start++;
1572 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001573 break;
1574 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001575#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001576 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001577 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001578 state->split_start++;
1579 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001580 break;
1581#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001582 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583#endif
1584 case 7:
1585 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001586 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001587 goto nla_put_failure;
1588
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001590 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001591 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001592
Johannes Berg86e8cf92013-06-19 10:57:22 +02001593 state->split_start++;
1594 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001595 break;
1596 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001597 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001598 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001599 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001600 goto nla_put_failure;
1601
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001602 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001603 /*
1604 * We can only add the per-channel limit information if the
1605 * dump is split, otherwise it makes it too big. Therefore
1606 * only advertise it in that case.
1607 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001608 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001609 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1610 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001611 goto nla_put_failure;
1612
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001613 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001614 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001615 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1616 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001617 goto nla_put_failure;
1618
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001619 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1620 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001621 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001622 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001623 goto nla_put_failure;
1624
1625 /*
1626 * Any information below this point is only available to
1627 * applications that can deal with it being split. This
1628 * helps ensure that newly added capabilities don't break
1629 * older tools by overrunning their buffers.
1630 *
1631 * We still increment split_start so that in the split
1632 * case we'll continue with more data in the next round,
1633 * but break unconditionally so unsplit data stops here.
1634 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001635 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001636 break;
1637 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001638 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001639 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001640 rdev->wiphy.extended_capabilities_len,
1641 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001642 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001643 rdev->wiphy.extended_capabilities_len,
1644 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001645 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001646
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001647 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001648 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001649 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1650 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001651 goto nla_put_failure;
1652
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001653 state->split_start++;
1654 break;
1655 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001656 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001657 goto nla_put_failure;
1658
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001659 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001660 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1661 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1662 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001663
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001665 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001666 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001667 goto nla_put_failure;
1668
Johannes Bergad7e7182013-11-13 13:37:47 +01001669 state->split_start++;
1670 break;
1671 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001672 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001673 const struct nl80211_vendor_cmd_info *info;
1674 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001675
Johannes Berg567ffc32013-12-18 14:43:31 +01001676 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1677 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001678 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001679
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1681 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001682 if (nla_put(msg, i + 1, sizeof(*info), info))
1683 goto nla_put_failure;
1684 }
1685 nla_nest_end(msg, nested);
1686 }
1687
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001688 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001689 const struct nl80211_vendor_cmd_info *info;
1690 struct nlattr *nested;
1691
1692 nested = nla_nest_start(msg,
1693 NL80211_ATTR_VENDOR_EVENTS);
1694 if (!nested)
1695 goto nla_put_failure;
1696
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001697 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1698 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001699 if (nla_put(msg, i + 1, sizeof(*info), info))
1700 goto nla_put_failure;
1701 }
1702 nla_nest_end(msg, nested);
1703 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001704 state->split_start++;
1705 break;
1706 case 12:
1707 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1708 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1709 rdev->wiphy.max_num_csa_counters))
1710 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001711
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001712 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1713 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1714 goto nla_put_failure;
1715
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001716 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1717 sizeof(rdev->wiphy.ext_features),
1718 rdev->wiphy.ext_features))
1719 goto nla_put_failure;
1720
Johannes Berg3713b4e2013-02-14 16:19:38 +01001721 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001722 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001723 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001724 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001725 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001726 genlmsg_end(msg, hdr);
1727 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001728
1729 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001730 genlmsg_cancel(msg, hdr);
1731 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001732}
1733
Johannes Berg86e8cf92013-06-19 10:57:22 +02001734static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1735 struct netlink_callback *cb,
1736 struct nl80211_dump_wiphy_state *state)
1737{
1738 struct nlattr **tb = nl80211_fam.attrbuf;
1739 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1740 tb, nl80211_fam.maxattr, nl80211_policy);
1741 /* ignore parse errors for backward compatibility */
1742 if (ret)
1743 return 0;
1744
1745 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1746 if (tb[NL80211_ATTR_WIPHY])
1747 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1748 if (tb[NL80211_ATTR_WDEV])
1749 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1750 if (tb[NL80211_ATTR_IFINDEX]) {
1751 struct net_device *netdev;
1752 struct cfg80211_registered_device *rdev;
1753 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1754
Ying Xue7f2b8562014-01-15 10:23:45 +08001755 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001756 if (!netdev)
1757 return -ENODEV;
1758 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001759 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001760 netdev->ieee80211_ptr->wiphy);
1761 state->filter_wiphy = rdev->wiphy_idx;
1762 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001763 }
1764
1765 return 0;
1766}
1767
Johannes Berg55682962007-09-20 13:09:35 -04001768static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1769{
Johannes Berg645e77d2013-03-01 14:03:49 +01001770 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001771 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001772 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001773
Johannes Berg5fe231e2013-05-08 21:45:15 +02001774 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001775 if (!state) {
1776 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001777 if (!state) {
1778 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001779 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001780 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001781 state->filter_wiphy = -1;
1782 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1783 if (ret) {
1784 kfree(state);
1785 rtnl_unlock();
1786 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001787 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001788 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001789 }
1790
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001791 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1792 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001793 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001794 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001795 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001796 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001797 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001798 continue;
1799 /* attempt to fit multiple wiphy data chunks into the skb */
1800 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001801 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1802 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001803 NETLINK_CB(cb->skb).portid,
1804 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001805 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001806 if (ret < 0) {
1807 /*
1808 * If sending the wiphy data didn't fit (ENOBUFS
1809 * or EMSGSIZE returned), this SKB is still
1810 * empty (so it's not too big because another
1811 * wiphy dataset is already in the skb) and
1812 * we've not tried to adjust the dump allocation
1813 * yet ... then adjust the alloc size to be
1814 * bigger, and return 1 but with the empty skb.
1815 * This results in an empty message being RX'ed
1816 * in userspace, but that is ignored.
1817 *
1818 * We can then retry with the larger buffer.
1819 */
1820 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001821 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001822 cb->min_dump_alloc < 4096) {
1823 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001824 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001825 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001826 return 1;
1827 }
1828 idx--;
1829 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001830 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001831 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001832 break;
Johannes Berg55682962007-09-20 13:09:35 -04001833 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001834 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001835
Johannes Berg86e8cf92013-06-19 10:57:22 +02001836 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001837
1838 return skb->len;
1839}
1840
Johannes Berg86e8cf92013-06-19 10:57:22 +02001841static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1842{
1843 kfree((void *)cb->args[0]);
1844 return 0;
1845}
1846
Johannes Berg55682962007-09-20 13:09:35 -04001847static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1848{
1849 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001850 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001851 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001852
Johannes Berg645e77d2013-03-01 14:03:49 +01001853 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001854 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001855 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001856
Johannes Berg3bb20552014-05-26 13:52:25 +02001857 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1858 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001859 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001860 nlmsg_free(msg);
1861 return -ENOBUFS;
1862 }
Johannes Berg55682962007-09-20 13:09:35 -04001863
Johannes Berg134e6372009-07-10 09:51:34 +00001864 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001865}
1866
Jouni Malinen31888482008-10-30 16:59:24 +02001867static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1868 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1869 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1870 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1871 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1872 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1873};
1874
1875static int parse_txq_params(struct nlattr *tb[],
1876 struct ieee80211_txq_params *txq_params)
1877{
Johannes Berga3304b02012-03-28 11:04:24 +02001878 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001879 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1880 !tb[NL80211_TXQ_ATTR_AIFS])
1881 return -EINVAL;
1882
Johannes Berga3304b02012-03-28 11:04:24 +02001883 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001884 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1885 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1886 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1887 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1888
Johannes Berga3304b02012-03-28 11:04:24 +02001889 if (txq_params->ac >= NL80211_NUM_ACS)
1890 return -EINVAL;
1891
Jouni Malinen31888482008-10-30 16:59:24 +02001892 return 0;
1893}
1894
Johannes Bergf444de02010-05-05 15:25:02 +02001895static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1896{
1897 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001898 * You can only set the channel explicitly for WDS interfaces,
1899 * all others have their channel managed via their respective
1900 * "establish a connection" command (connect, join, ...)
1901 *
1902 * For AP/GO and mesh mode, the channel can be set with the
1903 * channel userspace API, but is only stored and passed to the
1904 * low-level driver when the AP starts or the mesh is joined.
1905 * This is for backward compatibility, userspace can also give
1906 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001907 *
1908 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001909 * whatever else is going on, so they have their own special
1910 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001911 */
1912 return !wdev ||
1913 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001914 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001915 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1916 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001917}
1918
Johannes Berg683b6d32012-11-08 21:25:48 +01001919static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1920 struct genl_info *info,
1921 struct cfg80211_chan_def *chandef)
1922{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301923 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001924
1925 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1926 return -EINVAL;
1927
1928 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1929
1930 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001931 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1932 chandef->center_freq1 = control_freq;
1933 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001934
1935 /* Primary channel not allowed */
1936 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1937 return -EINVAL;
1938
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001939 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1940 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001941
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001942 chantype = nla_get_u32(
1943 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1944
1945 switch (chantype) {
1946 case NL80211_CHAN_NO_HT:
1947 case NL80211_CHAN_HT20:
1948 case NL80211_CHAN_HT40PLUS:
1949 case NL80211_CHAN_HT40MINUS:
1950 cfg80211_chandef_create(chandef, chandef->chan,
1951 chantype);
1952 break;
1953 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001954 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001955 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001956 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1957 chandef->width =
1958 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1959 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1960 chandef->center_freq1 =
1961 nla_get_u32(
1962 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1963 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1964 chandef->center_freq2 =
1965 nla_get_u32(
1966 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1967 }
1968
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001969 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001970 return -EINVAL;
1971
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001972 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1973 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001974 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001975
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001976 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1977 chandef->width == NL80211_CHAN_WIDTH_10) &&
1978 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1979 return -EINVAL;
1980
Johannes Berg683b6d32012-11-08 21:25:48 +01001981 return 0;
1982}
1983
Johannes Bergf444de02010-05-05 15:25:02 +02001984static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001985 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001986 struct genl_info *info)
1987{
Johannes Berg683b6d32012-11-08 21:25:48 +01001988 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001989 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001990 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001991 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001992
Jouni Malinene16821b2014-04-28 11:22:08 +03001993 if (dev)
1994 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001995 if (!nl80211_can_set_dev_channel(wdev))
1996 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001997 if (wdev)
1998 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001999
Johannes Berg683b6d32012-11-08 21:25:48 +01002000 result = nl80211_parse_chandef(rdev, info, &chandef);
2001 if (result)
2002 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002003
Johannes Berge8c9bd52012-06-06 08:18:22 +02002004 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002005 case NL80211_IFTYPE_AP:
2006 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002007 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2008 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002009 result = -EINVAL;
2010 break;
2011 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002012 if (wdev->beacon_interval) {
2013 if (!dev || !rdev->ops->set_ap_chanwidth ||
2014 !(rdev->wiphy.features &
2015 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2016 result = -EBUSY;
2017 break;
2018 }
2019
2020 /* Only allow dynamic channel width changes */
2021 if (chandef.chan != wdev->preset_chandef.chan) {
2022 result = -EBUSY;
2023 break;
2024 }
2025 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2026 if (result)
2027 break;
2028 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002029 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002030 result = 0;
2031 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002032 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002033 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002034 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002035 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002036 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002037 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002038 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002039 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002040 }
Johannes Bergf444de02010-05-05 15:25:02 +02002041
2042 return result;
2043}
2044
2045static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2046{
Johannes Berg4c476992010-10-04 21:36:35 +02002047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2048 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002049
Jouni Malinene16821b2014-04-28 11:22:08 +03002050 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002051}
2052
Bill Jordane8347eb2010-10-01 13:54:28 -04002053static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2054{
Johannes Berg43b19952010-10-07 13:10:30 +02002055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2056 struct net_device *dev = info->user_ptr[1];
2057 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002058 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002059
2060 if (!info->attrs[NL80211_ATTR_MAC])
2061 return -EINVAL;
2062
Johannes Berg43b19952010-10-07 13:10:30 +02002063 if (netif_running(dev))
2064 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002065
Johannes Berg43b19952010-10-07 13:10:30 +02002066 if (!rdev->ops->set_wds_peer)
2067 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002068
Johannes Berg43b19952010-10-07 13:10:30 +02002069 if (wdev->iftype != NL80211_IFTYPE_WDS)
2070 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002071
2072 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002073 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002074}
2075
2076
Johannes Berg55682962007-09-20 13:09:35 -04002077static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2078{
2079 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002080 struct net_device *netdev = NULL;
2081 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002082 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002083 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002084 u32 changed;
2085 u8 retry_short = 0, retry_long = 0;
2086 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002087 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002088
Johannes Berg5fe231e2013-05-08 21:45:15 +02002089 ASSERT_RTNL();
2090
Johannes Bergf444de02010-05-05 15:25:02 +02002091 /*
2092 * Try to find the wiphy and netdev. Normally this
2093 * function shouldn't need the netdev, but this is
2094 * done for backward compatibility -- previously
2095 * setting the channel was done per wiphy, but now
2096 * it is per netdev. Previous userland like hostapd
2097 * also passed a netdev to set_wiphy, so that it is
2098 * possible to let that go to the right netdev!
2099 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002100
Johannes Bergf444de02010-05-05 15:25:02 +02002101 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2102 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2103
Ying Xue7f2b8562014-01-15 10:23:45 +08002104 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002105 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002106 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002107 else
Johannes Bergf444de02010-05-05 15:25:02 +02002108 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002109 }
2110
Johannes Bergf444de02010-05-05 15:25:02 +02002111 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002112 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2113 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002114 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002115 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002116 wdev = NULL;
2117 netdev = NULL;
2118 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002119 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002120 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002121
2122 /*
2123 * end workaround code, by now the rdev is available
2124 * and locked, and wdev may or may not be NULL.
2125 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002126
2127 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002128 result = cfg80211_dev_rename(
2129 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002130
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002131 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002132 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002133
Jouni Malinen31888482008-10-30 16:59:24 +02002134 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2135 struct ieee80211_txq_params txq_params;
2136 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2137
Ying Xue7f2b8562014-01-15 10:23:45 +08002138 if (!rdev->ops->set_txq_params)
2139 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002140
Ying Xue7f2b8562014-01-15 10:23:45 +08002141 if (!netdev)
2142 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002143
Johannes Berg133a3ff2011-11-03 14:50:13 +01002144 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002145 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2146 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002147
Ying Xue7f2b8562014-01-15 10:23:45 +08002148 if (!netif_running(netdev))
2149 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002150
Jouni Malinen31888482008-10-30 16:59:24 +02002151 nla_for_each_nested(nl_txq_params,
2152 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2153 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002154 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2155 nla_data(nl_txq_params),
2156 nla_len(nl_txq_params),
2157 txq_params_policy);
2158 if (result)
2159 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002160 result = parse_txq_params(tb, &txq_params);
2161 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002162 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002163
Hila Gonene35e4d22012-06-27 17:19:42 +03002164 result = rdev_set_txq_params(rdev, netdev,
2165 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002166 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002168 }
2169 }
2170
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002171 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002172 result = __nl80211_set_channel(
2173 rdev,
2174 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2175 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002176 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002177 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002178 }
2179
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002180 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002181 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002182 enum nl80211_tx_power_setting type;
2183 int idx, mbm = 0;
2184
Johannes Bergc8442112012-10-24 10:17:18 +02002185 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2186 txp_wdev = NULL;
2187
Ying Xue7f2b8562014-01-15 10:23:45 +08002188 if (!rdev->ops->set_tx_power)
2189 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002190
2191 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2192 type = nla_get_u32(info->attrs[idx]);
2193
2194 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002195 (type != NL80211_TX_POWER_AUTOMATIC))
2196 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002197
2198 if (type != NL80211_TX_POWER_AUTOMATIC) {
2199 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2200 mbm = nla_get_u32(info->attrs[idx]);
2201 }
2202
Johannes Bergc8442112012-10-24 10:17:18 +02002203 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002204 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002205 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002206 }
2207
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002208 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2209 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2210 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002211 if ((!rdev->wiphy.available_antennas_tx &&
2212 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002213 !rdev->ops->set_antenna)
2214 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002215
2216 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2217 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2218
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002219 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002220 * available antenna masks, except for the "all" mask */
2221 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002222 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2223 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002224
Bruno Randolf7f531e02010-12-16 11:30:22 +09002225 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2226 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002227
Hila Gonene35e4d22012-06-27 17:19:42 +03002228 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002229 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002230 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002231 }
2232
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002233 changed = 0;
2234
2235 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2236 retry_short = nla_get_u8(
2237 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 if (retry_short == 0)
2239 return -EINVAL;
2240
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002241 changed |= WIPHY_PARAM_RETRY_SHORT;
2242 }
2243
2244 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2245 retry_long = nla_get_u8(
2246 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002247 if (retry_long == 0)
2248 return -EINVAL;
2249
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002250 changed |= WIPHY_PARAM_RETRY_LONG;
2251 }
2252
2253 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2254 frag_threshold = nla_get_u32(
2255 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002256 if (frag_threshold < 256)
2257 return -EINVAL;
2258
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002259 if (frag_threshold != (u32) -1) {
2260 /*
2261 * Fragments (apart from the last one) are required to
2262 * have even length. Make the fragmentation code
2263 * simpler by stripping LSB should someone try to use
2264 * odd threshold value.
2265 */
2266 frag_threshold &= ~0x1;
2267 }
2268 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2269 }
2270
2271 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2272 rts_threshold = nla_get_u32(
2273 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2274 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2275 }
2276
Lukáš Turek81077e82009-12-21 22:50:47 +01002277 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002278 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2279 return -EINVAL;
2280
Lukáš Turek81077e82009-12-21 22:50:47 +01002281 coverage_class = nla_get_u8(
2282 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2283 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2284 }
2285
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002286 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2287 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2288 return -EOPNOTSUPP;
2289
2290 changed |= WIPHY_PARAM_DYN_ACK;
2291 }
2292
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002293 if (changed) {
2294 u8 old_retry_short, old_retry_long;
2295 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002296 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002297
Ying Xue7f2b8562014-01-15 10:23:45 +08002298 if (!rdev->ops->set_wiphy_params)
2299 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002300
2301 old_retry_short = rdev->wiphy.retry_short;
2302 old_retry_long = rdev->wiphy.retry_long;
2303 old_frag_threshold = rdev->wiphy.frag_threshold;
2304 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002305 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002306
2307 if (changed & WIPHY_PARAM_RETRY_SHORT)
2308 rdev->wiphy.retry_short = retry_short;
2309 if (changed & WIPHY_PARAM_RETRY_LONG)
2310 rdev->wiphy.retry_long = retry_long;
2311 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2312 rdev->wiphy.frag_threshold = frag_threshold;
2313 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2314 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002315 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2316 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002317
Hila Gonene35e4d22012-06-27 17:19:42 +03002318 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002319 if (result) {
2320 rdev->wiphy.retry_short = old_retry_short;
2321 rdev->wiphy.retry_long = old_retry_long;
2322 rdev->wiphy.frag_threshold = old_frag_threshold;
2323 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002324 rdev->wiphy.coverage_class = old_coverage_class;
Michal Kazior9189ee32015-08-03 10:55:24 +02002325 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002326 }
2327 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002328 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002329}
2330
Johannes Berg71bbc992012-06-15 15:30:18 +02002331static inline u64 wdev_id(struct wireless_dev *wdev)
2332{
2333 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002334 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002335}
Johannes Berg55682962007-09-20 13:09:35 -04002336
Johannes Berg683b6d32012-11-08 21:25:48 +01002337static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002338 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002339{
Johannes Berg601555c2014-11-27 17:26:56 +01002340 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2341 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002342
Johannes Berg683b6d32012-11-08 21:25:48 +01002343 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2344 chandef->chan->center_freq))
2345 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002346 switch (chandef->width) {
2347 case NL80211_CHAN_WIDTH_20_NOHT:
2348 case NL80211_CHAN_WIDTH_20:
2349 case NL80211_CHAN_WIDTH_40:
2350 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2351 cfg80211_get_chandef_type(chandef)))
2352 return -ENOBUFS;
2353 break;
2354 default:
2355 break;
2356 }
2357 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2358 return -ENOBUFS;
2359 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2360 return -ENOBUFS;
2361 if (chandef->center_freq2 &&
2362 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002363 return -ENOBUFS;
2364 return 0;
2365}
2366
Eric W. Biederman15e47302012-09-07 20:12:54 +00002367static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002368 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002369 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002370{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002371 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002372 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002373 void *hdr;
2374
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002375 if (removal)
2376 cmd = NL80211_CMD_DEL_INTERFACE;
2377
2378 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002379 if (!hdr)
2380 return -1;
2381
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002382 if (dev &&
2383 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002384 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002385 goto nla_put_failure;
2386
2387 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2388 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002389 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002390 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002391 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2392 rdev->devlist_generation ^
2393 (cfg80211_rdev_list_generation << 2)))
2394 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002395
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002396 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002397 int ret;
2398 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002399
Johannes Berg683b6d32012-11-08 21:25:48 +01002400 ret = rdev_get_channel(rdev, wdev, &chandef);
2401 if (ret == 0) {
2402 if (nl80211_send_chandef(msg, &chandef))
2403 goto nla_put_failure;
2404 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002405 }
2406
Rafał Miłeckid55d0d52015-08-31 22:59:38 +02002407 if (rdev->ops->get_tx_power) {
2408 int dbm, ret;
2409
2410 ret = rdev_get_tx_power(rdev, wdev, &dbm);
2411 if (ret == 0 &&
2412 nla_put_u32(msg, NL80211_ATTR_WIPHY_TX_POWER_LEVEL,
2413 DBM_TO_MBM(dbm)))
2414 goto nla_put_failure;
2415 }
2416
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002417 if (wdev->ssid_len) {
2418 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2419 goto nla_put_failure;
2420 }
2421
Johannes Berg053c0952015-01-16 22:09:00 +01002422 genlmsg_end(msg, hdr);
2423 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002424
2425 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002426 genlmsg_cancel(msg, hdr);
2427 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002428}
2429
2430static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2431{
2432 int wp_idx = 0;
2433 int if_idx = 0;
2434 int wp_start = cb->args[0];
2435 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002436 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002437 struct wireless_dev *wdev;
2438
Johannes Berg5fe231e2013-05-08 21:45:15 +02002439 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002440 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2441 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002442 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002443 if (wp_idx < wp_start) {
2444 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002445 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002446 }
Johannes Berg55682962007-09-20 13:09:35 -04002447 if_idx = 0;
2448
Johannes Berg89a54e42012-06-15 14:33:17 +02002449 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002450 if (if_idx < if_start) {
2451 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002452 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002453 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002454 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002455 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002456 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002457 goto out;
2458 }
2459 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002460 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002461
2462 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002463 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002464 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002465 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002466
2467 cb->args[0] = wp_idx;
2468 cb->args[1] = if_idx;
2469
2470 return skb->len;
2471}
2472
2473static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2474{
2475 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002477 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002478
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002479 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002480 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002481 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002482
Eric W. Biederman15e47302012-09-07 20:12:54 +00002483 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002484 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002485 nlmsg_free(msg);
2486 return -ENOBUFS;
2487 }
Johannes Berg55682962007-09-20 13:09:35 -04002488
Johannes Berg134e6372009-07-10 09:51:34 +00002489 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002490}
2491
Michael Wu66f7ac52008-01-31 19:48:22 +01002492static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2493 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2494 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2495 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2496 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2497 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002498 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002499};
2500
2501static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2502{
2503 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2504 int flag;
2505
2506 *mntrflags = 0;
2507
2508 if (!nla)
2509 return -EINVAL;
2510
2511 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2512 nla, mntr_flags_policy))
2513 return -EINVAL;
2514
2515 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2516 if (flags[flag])
2517 *mntrflags |= (1<<flag);
2518
2519 return 0;
2520}
2521
Johannes Berg9bc383d2009-11-19 11:55:19 +01002522static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002523 struct net_device *netdev, u8 use_4addr,
2524 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002525{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002526 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002527 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002528 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002529 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002530 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002531
2532 switch (iftype) {
2533 case NL80211_IFTYPE_AP_VLAN:
2534 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2535 return 0;
2536 break;
2537 case NL80211_IFTYPE_STATION:
2538 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2539 return 0;
2540 break;
2541 default:
2542 break;
2543 }
2544
2545 return -EOPNOTSUPP;
2546}
2547
Johannes Berg55682962007-09-20 13:09:35 -04002548static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2549{
Johannes Berg4c476992010-10-04 21:36:35 +02002550 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002551 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002552 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002553 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002554 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002555 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002556 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002557
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002558 memset(&params, 0, sizeof(params));
2559
Johannes Berg04a773a2009-04-19 21:24:32 +02002560 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002561
Johannes Berg723b0382008-09-16 20:22:09 +02002562 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002563 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002564 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002565 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002566 if (ntype > NL80211_IFTYPE_MAX)
2567 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002568 }
2569
Johannes Berg92ffe052008-09-16 20:39:36 +02002570 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002571 struct wireless_dev *wdev = dev->ieee80211_ptr;
2572
Johannes Berg4c476992010-10-04 21:36:35 +02002573 if (ntype != NL80211_IFTYPE_MESH_POINT)
2574 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002575 if (netif_running(dev))
2576 return -EBUSY;
2577
2578 wdev_lock(wdev);
2579 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2580 IEEE80211_MAX_MESH_ID_LEN);
2581 wdev->mesh_id_up_len =
2582 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2583 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2584 wdev->mesh_id_up_len);
2585 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002586 }
2587
Felix Fietkau8b787642009-11-10 18:53:10 +01002588 if (info->attrs[NL80211_ATTR_4ADDR]) {
2589 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2590 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002591 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002592 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002593 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002594 } else {
2595 params.use_4addr = -1;
2596 }
2597
Johannes Berg92ffe052008-09-16 20:39:36 +02002598 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002599 if (ntype != NL80211_IFTYPE_MONITOR)
2600 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002601 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2602 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002603 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002604 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002605
2606 flags = &_flags;
2607 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002608 }
Johannes Berg3b858752009-03-12 09:55:09 +01002609
Luciano Coelho18003292013-08-29 13:26:57 +03002610 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002611 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2612 return -EOPNOTSUPP;
2613
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002614 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002615 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002616 else
2617 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002618
Johannes Berg9bc383d2009-11-19 11:55:19 +01002619 if (!err && params.use_4addr != -1)
2620 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2621
Johannes Berg55682962007-09-20 13:09:35 -04002622 return err;
2623}
2624
2625static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2626{
Johannes Berg4c476992010-10-04 21:36:35 +02002627 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002628 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002629 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002630 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002631 int err;
2632 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002633 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002634
Johannes Berg78f22b62014-03-24 17:57:27 +01002635 /* to avoid failing a new interface creation due to pending removal */
2636 cfg80211_destroy_ifaces(rdev);
2637
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002638 memset(&params, 0, sizeof(params));
2639
Johannes Berg55682962007-09-20 13:09:35 -04002640 if (!info->attrs[NL80211_ATTR_IFNAME])
2641 return -EINVAL;
2642
2643 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2644 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2645 if (type > NL80211_IFTYPE_MAX)
2646 return -EINVAL;
2647 }
2648
Johannes Berg79c97e92009-07-07 03:56:12 +02002649 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002650 !(rdev->wiphy.interface_modes & (1 << type)))
2651 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002652
Ben Greeare8f479b2014-10-22 12:23:05 -07002653 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2654 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2655 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002656 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2657 ETH_ALEN);
2658 if (!is_valid_ether_addr(params.macaddr))
2659 return -EADDRNOTAVAIL;
2660 }
2661
Johannes Berg9bc383d2009-11-19 11:55:19 +01002662 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002663 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002664 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002665 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002666 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002667 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002668
Michael Wu66f7ac52008-01-31 19:48:22 +01002669 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2670 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2671 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002672
Luciano Coelho18003292013-08-29 13:26:57 +03002673 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002674 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2675 return -EOPNOTSUPP;
2676
Johannes Berga18c7192015-02-24 10:56:42 +01002677 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2678 if (!msg)
2679 return -ENOMEM;
2680
Hila Gonene35e4d22012-06-27 17:19:42 +03002681 wdev = rdev_add_virtual_intf(rdev,
2682 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002683 NET_NAME_USER, type, err ? NULL : &flags,
2684 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002685 if (WARN_ON(!wdev)) {
2686 nlmsg_free(msg);
2687 return -EPROTO;
2688 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002689 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002690 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002691 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002692
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002693 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002694 wdev->owner_nlportid = info->snd_portid;
2695
Johannes Berg98104fde2012-06-16 00:19:54 +02002696 switch (type) {
2697 case NL80211_IFTYPE_MESH_POINT:
2698 if (!info->attrs[NL80211_ATTR_MESH_ID])
2699 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002700 wdev_lock(wdev);
2701 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2702 IEEE80211_MAX_MESH_ID_LEN);
2703 wdev->mesh_id_up_len =
2704 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2705 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2706 wdev->mesh_id_up_len);
2707 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002708 break;
2709 case NL80211_IFTYPE_P2P_DEVICE:
2710 /*
2711 * P2P Device doesn't have a netdev, so doesn't go
2712 * through the netdev notifier and must be added here
2713 */
2714 mutex_init(&wdev->mtx);
2715 INIT_LIST_HEAD(&wdev->event_list);
2716 spin_lock_init(&wdev->event_lock);
2717 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2718 spin_lock_init(&wdev->mgmt_registrations_lock);
2719
Johannes Berg98104fde2012-06-16 00:19:54 +02002720 wdev->identifier = ++rdev->wdev_id;
2721 list_add_rcu(&wdev->list, &rdev->wdev_list);
2722 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002723 break;
2724 default:
2725 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002726 }
2727
Eric W. Biederman15e47302012-09-07 20:12:54 +00002728 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002729 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002730 nlmsg_free(msg);
2731 return -ENOBUFS;
2732 }
2733
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002734 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2735 if (event) {
2736 if (nl80211_send_iface(event, 0, 0, 0,
2737 rdev, wdev, false) < 0) {
2738 nlmsg_free(event);
2739 goto out;
2740 }
2741
2742 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2743 event, 0, NL80211_MCGRP_CONFIG,
2744 GFP_KERNEL);
2745 }
2746
2747out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002748 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002749}
2750
2751static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2752{
Johannes Berg4c476992010-10-04 21:36:35 +02002753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002754 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002755 struct sk_buff *msg;
2756 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002757
Johannes Berg4c476992010-10-04 21:36:35 +02002758 if (!rdev->ops->del_virtual_intf)
2759 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002760
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002761 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2762 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2763 nlmsg_free(msg);
2764 msg = NULL;
2765 }
2766
Johannes Berg84efbb82012-06-16 00:00:26 +02002767 /*
2768 * If we remove a wireless device without a netdev then clear
2769 * user_ptr[1] so that nl80211_post_doit won't dereference it
2770 * to check if it needs to do dev_put(). Otherwise it crashes
2771 * since the wdev has been freed, unlike with a netdev where
2772 * we need the dev_put() for the netdev to really be freed.
2773 */
2774 if (!wdev->netdev)
2775 info->user_ptr[1] = NULL;
2776
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002777 status = rdev_del_virtual_intf(rdev, wdev);
2778 if (status >= 0 && msg)
2779 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2780 msg, 0, NL80211_MCGRP_CONFIG,
2781 GFP_KERNEL);
2782 else
2783 nlmsg_free(msg);
2784
2785 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002786}
2787
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002788static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2789{
2790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2791 struct net_device *dev = info->user_ptr[1];
2792 u16 noack_map;
2793
2794 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2795 return -EINVAL;
2796
2797 if (!rdev->ops->set_noack_map)
2798 return -EOPNOTSUPP;
2799
2800 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2801
Hila Gonene35e4d22012-06-27 17:19:42 +03002802 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002803}
2804
Johannes Berg41ade002007-12-19 02:03:29 +01002805struct get_key_cookie {
2806 struct sk_buff *msg;
2807 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002808 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002809};
2810
2811static void get_key_callback(void *c, struct key_params *params)
2812{
Johannes Bergb9454e82009-07-08 13:29:08 +02002813 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002814 struct get_key_cookie *cookie = c;
2815
David S. Miller9360ffd2012-03-29 04:41:26 -04002816 if ((params->key &&
2817 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2818 params->key_len, params->key)) ||
2819 (params->seq &&
2820 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2821 params->seq_len, params->seq)) ||
2822 (params->cipher &&
2823 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2824 params->cipher)))
2825 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002826
Johannes Bergb9454e82009-07-08 13:29:08 +02002827 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2828 if (!key)
2829 goto nla_put_failure;
2830
David S. Miller9360ffd2012-03-29 04:41:26 -04002831 if ((params->key &&
2832 nla_put(cookie->msg, NL80211_KEY_DATA,
2833 params->key_len, params->key)) ||
2834 (params->seq &&
2835 nla_put(cookie->msg, NL80211_KEY_SEQ,
2836 params->seq_len, params->seq)) ||
2837 (params->cipher &&
2838 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2839 params->cipher)))
2840 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002841
David S. Miller9360ffd2012-03-29 04:41:26 -04002842 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2843 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002844
2845 nla_nest_end(cookie->msg, key);
2846
Johannes Berg41ade002007-12-19 02:03:29 +01002847 return;
2848 nla_put_failure:
2849 cookie->error = 1;
2850}
2851
2852static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2853{
Johannes Berg4c476992010-10-04 21:36:35 +02002854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002855 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002856 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002857 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002858 const u8 *mac_addr = NULL;
2859 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002860 struct get_key_cookie cookie = {
2861 .error = 0,
2862 };
2863 void *hdr;
2864 struct sk_buff *msg;
2865
2866 if (info->attrs[NL80211_ATTR_KEY_IDX])
2867 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2868
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002869 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002870 return -EINVAL;
2871
2872 if (info->attrs[NL80211_ATTR_MAC])
2873 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2874
Johannes Berge31b8212010-10-05 19:39:30 +02002875 pairwise = !!mac_addr;
2876 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2877 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2878 if (kt >= NUM_NL80211_KEYTYPES)
2879 return -EINVAL;
2880 if (kt != NL80211_KEYTYPE_GROUP &&
2881 kt != NL80211_KEYTYPE_PAIRWISE)
2882 return -EINVAL;
2883 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2884 }
2885
Johannes Berg4c476992010-10-04 21:36:35 +02002886 if (!rdev->ops->get_key)
2887 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002888
Johannes Berg0fa7b392015-01-23 11:10:12 +01002889 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2890 return -ENOENT;
2891
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002892 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002893 if (!msg)
2894 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002895
Eric W. Biederman15e47302012-09-07 20:12:54 +00002896 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002897 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002898 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002899 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002900
2901 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002902 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002903
David S. Miller9360ffd2012-03-29 04:41:26 -04002904 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2905 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2906 goto nla_put_failure;
2907 if (mac_addr &&
2908 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2909 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002910
Hila Gonene35e4d22012-06-27 17:19:42 +03002911 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2912 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002913
2914 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002915 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002916
2917 if (cookie.error)
2918 goto nla_put_failure;
2919
2920 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002921 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002922
2923 nla_put_failure:
2924 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002925 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002926 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002927 return err;
2928}
2929
2930static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2931{
Johannes Berg4c476992010-10-04 21:36:35 +02002932 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002933 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002934 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002935 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002936
Johannes Bergb9454e82009-07-08 13:29:08 +02002937 err = nl80211_parse_key(info, &key);
2938 if (err)
2939 return err;
2940
2941 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002942 return -EINVAL;
2943
Johannes Bergb9454e82009-07-08 13:29:08 +02002944 /* only support setting default key */
2945 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002946 return -EINVAL;
2947
Johannes Bergfffd0932009-07-08 14:22:54 +02002948 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002949
2950 if (key.def) {
2951 if (!rdev->ops->set_default_key) {
2952 err = -EOPNOTSUPP;
2953 goto out;
2954 }
2955
2956 err = nl80211_key_allowed(dev->ieee80211_ptr);
2957 if (err)
2958 goto out;
2959
Hila Gonene35e4d22012-06-27 17:19:42 +03002960 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002961 key.def_uni, key.def_multi);
2962
2963 if (err)
2964 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002965
Johannes Berg3d23e342009-09-29 23:27:28 +02002966#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002967 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002968#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002969 } else {
2970 if (key.def_uni || !key.def_multi) {
2971 err = -EINVAL;
2972 goto out;
2973 }
2974
2975 if (!rdev->ops->set_default_mgmt_key) {
2976 err = -EOPNOTSUPP;
2977 goto out;
2978 }
2979
2980 err = nl80211_key_allowed(dev->ieee80211_ptr);
2981 if (err)
2982 goto out;
2983
Hila Gonene35e4d22012-06-27 17:19:42 +03002984 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002985 if (err)
2986 goto out;
2987
2988#ifdef CONFIG_CFG80211_WEXT
2989 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2990#endif
2991 }
2992
2993 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002994 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002995
Johannes Berg41ade002007-12-19 02:03:29 +01002996 return err;
2997}
2998
2999static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
3000{
Johannes Berg4c476992010-10-04 21:36:35 +02003001 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02003002 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003003 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02003004 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02003005 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01003006
Johannes Bergb9454e82009-07-08 13:29:08 +02003007 err = nl80211_parse_key(info, &key);
3008 if (err)
3009 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003010
Johannes Bergb9454e82009-07-08 13:29:08 +02003011 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003012 return -EINVAL;
3013
Johannes Berg41ade002007-12-19 02:03:29 +01003014 if (info->attrs[NL80211_ATTR_MAC])
3015 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3016
Johannes Berge31b8212010-10-05 19:39:30 +02003017 if (key.type == -1) {
3018 if (mac_addr)
3019 key.type = NL80211_KEYTYPE_PAIRWISE;
3020 else
3021 key.type = NL80211_KEYTYPE_GROUP;
3022 }
3023
3024 /* for now */
3025 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3026 key.type != NL80211_KEYTYPE_GROUP)
3027 return -EINVAL;
3028
Johannes Berg4c476992010-10-04 21:36:35 +02003029 if (!rdev->ops->add_key)
3030 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003031
Johannes Berge31b8212010-10-05 19:39:30 +02003032 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3033 key.type == NL80211_KEYTYPE_PAIRWISE,
3034 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003035 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003036
3037 wdev_lock(dev->ieee80211_ptr);
3038 err = nl80211_key_allowed(dev->ieee80211_ptr);
3039 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003040 err = rdev_add_key(rdev, dev, key.idx,
3041 key.type == NL80211_KEYTYPE_PAIRWISE,
3042 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003043 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003044
Johannes Berg41ade002007-12-19 02:03:29 +01003045 return err;
3046}
3047
3048static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3049{
Johannes Berg4c476992010-10-04 21:36:35 +02003050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003051 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003052 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003053 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003054 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003055
Johannes Bergb9454e82009-07-08 13:29:08 +02003056 err = nl80211_parse_key(info, &key);
3057 if (err)
3058 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003059
3060 if (info->attrs[NL80211_ATTR_MAC])
3061 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3062
Johannes Berge31b8212010-10-05 19:39:30 +02003063 if (key.type == -1) {
3064 if (mac_addr)
3065 key.type = NL80211_KEYTYPE_PAIRWISE;
3066 else
3067 key.type = NL80211_KEYTYPE_GROUP;
3068 }
3069
3070 /* for now */
3071 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3072 key.type != NL80211_KEYTYPE_GROUP)
3073 return -EINVAL;
3074
Johannes Berg4c476992010-10-04 21:36:35 +02003075 if (!rdev->ops->del_key)
3076 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003077
Johannes Bergfffd0932009-07-08 14:22:54 +02003078 wdev_lock(dev->ieee80211_ptr);
3079 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003080
Johannes Berg0fa7b392015-01-23 11:10:12 +01003081 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003082 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3083 err = -ENOENT;
3084
Johannes Bergfffd0932009-07-08 14:22:54 +02003085 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003086 err = rdev_del_key(rdev, dev, key.idx,
3087 key.type == NL80211_KEYTYPE_PAIRWISE,
3088 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003089
Johannes Berg3d23e342009-09-29 23:27:28 +02003090#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003091 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003092 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003093 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003094 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003095 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3096 }
3097#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003098 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003099
Johannes Berg41ade002007-12-19 02:03:29 +01003100 return err;
3101}
3102
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303103/* This function returns an error or the number of nested attributes */
3104static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3105{
3106 struct nlattr *attr;
3107 int n_entries = 0, tmp;
3108
3109 nla_for_each_nested(attr, nl_attr, tmp) {
3110 if (nla_len(attr) != ETH_ALEN)
3111 return -EINVAL;
3112
3113 n_entries++;
3114 }
3115
3116 return n_entries;
3117}
3118
3119/*
3120 * This function parses ACL information and allocates memory for ACL data.
3121 * On successful return, the calling function is responsible to free the
3122 * ACL buffer returned by this function.
3123 */
3124static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3125 struct genl_info *info)
3126{
3127 enum nl80211_acl_policy acl_policy;
3128 struct nlattr *attr;
3129 struct cfg80211_acl_data *acl;
3130 int i = 0, n_entries, tmp;
3131
3132 if (!wiphy->max_acl_mac_addrs)
3133 return ERR_PTR(-EOPNOTSUPP);
3134
3135 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3136 return ERR_PTR(-EINVAL);
3137
3138 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3139 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3140 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3141 return ERR_PTR(-EINVAL);
3142
3143 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3144 return ERR_PTR(-EINVAL);
3145
3146 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3147 if (n_entries < 0)
3148 return ERR_PTR(n_entries);
3149
3150 if (n_entries > wiphy->max_acl_mac_addrs)
3151 return ERR_PTR(-ENOTSUPP);
3152
3153 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3154 GFP_KERNEL);
3155 if (!acl)
3156 return ERR_PTR(-ENOMEM);
3157
3158 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3159 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3160 i++;
3161 }
3162
3163 acl->n_acl_entries = n_entries;
3164 acl->acl_policy = acl_policy;
3165
3166 return acl;
3167}
3168
3169static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3170{
3171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3172 struct net_device *dev = info->user_ptr[1];
3173 struct cfg80211_acl_data *acl;
3174 int err;
3175
3176 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3177 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3178 return -EOPNOTSUPP;
3179
3180 if (!dev->ieee80211_ptr->beacon_interval)
3181 return -EINVAL;
3182
3183 acl = parse_acl_data(&rdev->wiphy, info);
3184 if (IS_ERR(acl))
3185 return PTR_ERR(acl);
3186
3187 err = rdev_set_mac_acl(rdev, dev, acl);
3188
3189 kfree(acl);
3190
3191 return err;
3192}
3193
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003194static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003195 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003196{
Johannes Berg88600202012-02-13 15:17:18 +01003197 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003198
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003199 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3200 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3201 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3202 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003203 return -EINVAL;
3204
Johannes Berg88600202012-02-13 15:17:18 +01003205 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003206
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003207 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3208 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3209 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003210 if (!bcn->head_len)
3211 return -EINVAL;
3212 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003213 }
3214
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003215 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3216 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3217 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003218 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003219 }
3220
Johannes Berg4c476992010-10-04 21:36:35 +02003221 if (!haveinfo)
3222 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003223
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003224 if (attrs[NL80211_ATTR_IE]) {
3225 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3226 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003227 }
3228
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003229 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003230 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003231 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003232 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003233 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003234 }
3235
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003236 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003237 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003238 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003239 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003240 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003241 }
3242
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003243 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3244 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3245 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003246 }
3247
Johannes Berg88600202012-02-13 15:17:18 +01003248 return 0;
3249}
3250
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003251static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3252 struct cfg80211_ap_settings *params)
3253{
3254 struct wireless_dev *wdev;
3255 bool ret = false;
3256
Johannes Berg89a54e42012-06-15 14:33:17 +02003257 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003258 if (wdev->iftype != NL80211_IFTYPE_AP &&
3259 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3260 continue;
3261
Johannes Berg683b6d32012-11-08 21:25:48 +01003262 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003263 continue;
3264
Johannes Berg683b6d32012-11-08 21:25:48 +01003265 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003266 ret = true;
3267 break;
3268 }
3269
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003270 return ret;
3271}
3272
Jouni Malinene39e5b52012-09-30 19:29:39 +03003273static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3274 enum nl80211_auth_type auth_type,
3275 enum nl80211_commands cmd)
3276{
3277 if (auth_type > NL80211_AUTHTYPE_MAX)
3278 return false;
3279
3280 switch (cmd) {
3281 case NL80211_CMD_AUTHENTICATE:
3282 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3283 auth_type == NL80211_AUTHTYPE_SAE)
3284 return false;
3285 return true;
3286 case NL80211_CMD_CONNECT:
3287 case NL80211_CMD_START_AP:
3288 /* SAE not supported yet */
3289 if (auth_type == NL80211_AUTHTYPE_SAE)
3290 return false;
3291 return true;
3292 default:
3293 return false;
3294 }
3295}
3296
Johannes Berg88600202012-02-13 15:17:18 +01003297static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3298{
3299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3300 struct net_device *dev = info->user_ptr[1];
3301 struct wireless_dev *wdev = dev->ieee80211_ptr;
3302 struct cfg80211_ap_settings params;
3303 int err;
3304
3305 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3306 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3307 return -EOPNOTSUPP;
3308
3309 if (!rdev->ops->start_ap)
3310 return -EOPNOTSUPP;
3311
3312 if (wdev->beacon_interval)
3313 return -EALREADY;
3314
3315 memset(&params, 0, sizeof(params));
3316
3317 /* these are required for START_AP */
3318 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3319 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3320 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3321 return -EINVAL;
3322
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003323 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003324 if (err)
3325 return err;
3326
3327 params.beacon_interval =
3328 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3329 params.dtim_period =
3330 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3331
3332 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3333 if (err)
3334 return err;
3335
3336 /*
3337 * In theory, some of these attributes should be required here
3338 * but since they were not used when the command was originally
3339 * added, keep them optional for old user space programs to let
3340 * them continue to work with drivers that do not need the
3341 * additional information -- drivers must check!
3342 */
3343 if (info->attrs[NL80211_ATTR_SSID]) {
3344 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3345 params.ssid_len =
3346 nla_len(info->attrs[NL80211_ATTR_SSID]);
3347 if (params.ssid_len == 0 ||
3348 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3349 return -EINVAL;
3350 }
3351
3352 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3353 params.hidden_ssid = nla_get_u32(
3354 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3355 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3356 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3357 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3358 return -EINVAL;
3359 }
3360
3361 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3362
3363 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3364 params.auth_type = nla_get_u32(
3365 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003366 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3367 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003368 return -EINVAL;
3369 } else
3370 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3371
3372 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3373 NL80211_MAX_NR_CIPHER_SUITES);
3374 if (err)
3375 return err;
3376
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303377 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3378 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3379 return -EOPNOTSUPP;
3380 params.inactivity_timeout = nla_get_u16(
3381 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3382 }
3383
Johannes Berg53cabad2012-11-14 15:17:28 +01003384 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3385 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3386 return -EINVAL;
3387 params.p2p_ctwindow =
3388 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3389 if (params.p2p_ctwindow > 127)
3390 return -EINVAL;
3391 if (params.p2p_ctwindow != 0 &&
3392 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3393 return -EINVAL;
3394 }
3395
3396 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3397 u8 tmp;
3398
3399 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3400 return -EINVAL;
3401 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3402 if (tmp > 1)
3403 return -EINVAL;
3404 params.p2p_opp_ps = tmp;
3405 if (params.p2p_opp_ps != 0 &&
3406 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3407 return -EINVAL;
3408 }
3409
Johannes Bergaa430da2012-05-16 23:50:18 +02003410 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003411 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3412 if (err)
3413 return err;
3414 } else if (wdev->preset_chandef.chan) {
3415 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003416 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003417 return -EINVAL;
3418
Arik Nemtsov923b3522015-07-08 15:41:44 +03003419 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3420 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003421 return -EINVAL;
3422
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303423 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3424 params.acl = parse_acl_data(&rdev->wiphy, info);
3425 if (IS_ERR(params.acl))
3426 return PTR_ERR(params.acl);
3427 }
3428
Eliad Peller18998c32014-09-10 14:07:34 +03003429 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3430 params.smps_mode =
3431 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3432 switch (params.smps_mode) {
3433 case NL80211_SMPS_OFF:
3434 break;
3435 case NL80211_SMPS_STATIC:
3436 if (!(rdev->wiphy.features &
3437 NL80211_FEATURE_STATIC_SMPS))
3438 return -EINVAL;
3439 break;
3440 case NL80211_SMPS_DYNAMIC:
3441 if (!(rdev->wiphy.features &
3442 NL80211_FEATURE_DYNAMIC_SMPS))
3443 return -EINVAL;
3444 break;
3445 default:
3446 return -EINVAL;
3447 }
3448 } else {
3449 params.smps_mode = NL80211_SMPS_OFF;
3450 }
3451
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003452 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003453 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003454 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003455 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003456 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003457 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003458 wdev->ssid_len = params.ssid_len;
3459 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003460 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003461 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303462
3463 kfree(params.acl);
3464
Johannes Berg56d18932011-05-09 18:41:15 +02003465 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003466}
3467
Johannes Berg88600202012-02-13 15:17:18 +01003468static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3469{
3470 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3471 struct net_device *dev = info->user_ptr[1];
3472 struct wireless_dev *wdev = dev->ieee80211_ptr;
3473 struct cfg80211_beacon_data params;
3474 int err;
3475
3476 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3477 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3478 return -EOPNOTSUPP;
3479
3480 if (!rdev->ops->change_beacon)
3481 return -EOPNOTSUPP;
3482
3483 if (!wdev->beacon_interval)
3484 return -EINVAL;
3485
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003486 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003487 if (err)
3488 return err;
3489
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003490 wdev_lock(wdev);
3491 err = rdev_change_beacon(rdev, dev, &params);
3492 wdev_unlock(wdev);
3493
3494 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003495}
3496
3497static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003498{
Johannes Berg4c476992010-10-04 21:36:35 +02003499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3500 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003501
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003502 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003503}
3504
Johannes Berg5727ef12007-12-19 02:03:34 +01003505static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3506 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3507 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3508 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003509 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003510 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003511 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003512};
3513
Johannes Bergeccb8e82009-05-11 21:57:56 +03003514static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003515 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003516 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003517{
3518 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003519 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003520 int flag;
3521
Johannes Bergeccb8e82009-05-11 21:57:56 +03003522 /*
3523 * Try parsing the new attribute first so userspace
3524 * can specify both for older kernels.
3525 */
3526 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3527 if (nla) {
3528 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003529
Johannes Bergeccb8e82009-05-11 21:57:56 +03003530 sta_flags = nla_data(nla);
3531 params->sta_flags_mask = sta_flags->mask;
3532 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003533 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003534 if ((params->sta_flags_mask |
3535 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3536 return -EINVAL;
3537 return 0;
3538 }
3539
3540 /* if present, parse the old attribute */
3541
3542 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003543 if (!nla)
3544 return 0;
3545
3546 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3547 nla, sta_flags_policy))
3548 return -EINVAL;
3549
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003550 /*
3551 * Only allow certain flags for interface types so that
3552 * other attributes are silently ignored. Remember that
3553 * this is backward compatibility code with old userspace
3554 * and shouldn't be hit in other cases anyway.
3555 */
3556 switch (iftype) {
3557 case NL80211_IFTYPE_AP:
3558 case NL80211_IFTYPE_AP_VLAN:
3559 case NL80211_IFTYPE_P2P_GO:
3560 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3561 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3562 BIT(NL80211_STA_FLAG_WME) |
3563 BIT(NL80211_STA_FLAG_MFP);
3564 break;
3565 case NL80211_IFTYPE_P2P_CLIENT:
3566 case NL80211_IFTYPE_STATION:
3567 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3568 BIT(NL80211_STA_FLAG_TDLS_PEER);
3569 break;
3570 case NL80211_IFTYPE_MESH_POINT:
3571 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3572 BIT(NL80211_STA_FLAG_MFP) |
3573 BIT(NL80211_STA_FLAG_AUTHORIZED);
3574 default:
3575 return -EINVAL;
3576 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003577
Johannes Berg3383b5a2012-05-10 20:14:43 +02003578 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3579 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003580 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003581
Johannes Berg3383b5a2012-05-10 20:14:43 +02003582 /* no longer support new API additions in old API */
3583 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3584 return -EINVAL;
3585 }
3586 }
3587
Johannes Berg5727ef12007-12-19 02:03:34 +01003588 return 0;
3589}
3590
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003591static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3592 int attr)
3593{
3594 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003595 u32 bitrate;
3596 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003597 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003598
3599 rate = nla_nest_start(msg, attr);
3600 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003601 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003602
3603 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3604 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003605 /* report 16-bit bitrate only if we can */
3606 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003607 if (bitrate > 0 &&
3608 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3609 return false;
3610 if (bitrate_compat > 0 &&
3611 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3612 return false;
3613
Johannes Bergb51f3be2015-01-15 16:14:02 +01003614 switch (info->bw) {
3615 case RATE_INFO_BW_5:
3616 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3617 break;
3618 case RATE_INFO_BW_10:
3619 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3620 break;
3621 default:
3622 WARN_ON(1);
3623 /* fall through */
3624 case RATE_INFO_BW_20:
3625 rate_flg = 0;
3626 break;
3627 case RATE_INFO_BW_40:
3628 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3629 break;
3630 case RATE_INFO_BW_80:
3631 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3632 break;
3633 case RATE_INFO_BW_160:
3634 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3635 break;
3636 }
3637
3638 if (rate_flg && nla_put_flag(msg, rate_flg))
3639 return false;
3640
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003641 if (info->flags & RATE_INFO_FLAGS_MCS) {
3642 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3643 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003644 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3645 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3646 return false;
3647 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3648 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3649 return false;
3650 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3651 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003652 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3653 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3654 return false;
3655 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003656
3657 nla_nest_end(msg, rate);
3658 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003659}
3660
Felix Fietkau119363c2013-04-22 16:29:30 +02003661static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3662 int id)
3663{
3664 void *attr;
3665 int i = 0;
3666
3667 if (!mask)
3668 return true;
3669
3670 attr = nla_nest_start(msg, id);
3671 if (!attr)
3672 return false;
3673
3674 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3675 if (!(mask & BIT(i)))
3676 continue;
3677
3678 if (nla_put_u8(msg, i, signal[i]))
3679 return false;
3680 }
3681
3682 nla_nest_end(msg, attr);
3683
3684 return true;
3685}
3686
Johannes Bergcf5ead82014-11-14 17:14:00 +01003687static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3688 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003689 struct cfg80211_registered_device *rdev,
3690 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003691 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003692{
3693 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003694 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003695
Johannes Bergcf5ead82014-11-14 17:14:00 +01003696 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003697 if (!hdr)
3698 return -1;
3699
David S. Miller9360ffd2012-03-29 04:41:26 -04003700 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3701 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3702 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3703 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003704
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003705 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3706 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003707 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003708
3709#define PUT_SINFO(attr, memb, type) do { \
3710 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3711 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3712 sinfo->memb)) \
3713 goto nla_put_failure; \
3714 } while (0)
3715
3716 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3717 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3718
3719 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3720 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003721 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003722 (u32)sinfo->rx_bytes))
3723 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003724
3725 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3726 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003727 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3728 (u32)sinfo->tx_bytes))
3729 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003730
3731 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3732 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3733 PUT_SINFO(LLID, llid, u16);
3734 PUT_SINFO(PLID, plid, u16);
3735 PUT_SINFO(PLINK_STATE, plink_state, u8);
3736
John W. Linville66266b32012-03-15 13:25:41 -04003737 switch (rdev->wiphy.signal_type) {
3738 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003739 PUT_SINFO(SIGNAL, signal, u8);
3740 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003741 break;
3742 default:
3743 break;
3744 }
Johannes Berg319090b2014-11-17 14:08:11 +01003745 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003746 if (!nl80211_put_signal(msg, sinfo->chains,
3747 sinfo->chain_signal,
3748 NL80211_STA_INFO_CHAIN_SIGNAL))
3749 goto nla_put_failure;
3750 }
Johannes Berg319090b2014-11-17 14:08:11 +01003751 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003752 if (!nl80211_put_signal(msg, sinfo->chains,
3753 sinfo->chain_signal_avg,
3754 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3755 goto nla_put_failure;
3756 }
Johannes Berg319090b2014-11-17 14:08:11 +01003757 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003758 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3759 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003760 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003761 }
Johannes Berg319090b2014-11-17 14:08:11 +01003762 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003763 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3764 NL80211_STA_INFO_RX_BITRATE))
3765 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003766 }
Johannes Berg319090b2014-11-17 14:08:11 +01003767
3768 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3769 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3770 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3771 PUT_SINFO(TX_FAILED, tx_failed, u32);
3772 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3773 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3774 PUT_SINFO(LOCAL_PM, local_pm, u32);
3775 PUT_SINFO(PEER_PM, peer_pm, u32);
3776 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3777
3778 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003779 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3780 if (!bss_param)
3781 goto nla_put_failure;
3782
David S. Miller9360ffd2012-03-29 04:41:26 -04003783 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3784 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3785 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3786 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3787 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3788 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3789 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3790 sinfo->bss_param.dtim_period) ||
3791 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3792 sinfo->bss_param.beacon_interval))
3793 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003794
3795 nla_nest_end(msg, bss_param);
3796 }
Johannes Berg319090b2014-11-17 14:08:11 +01003797 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003798 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3799 sizeof(struct nl80211_sta_flag_update),
3800 &sinfo->sta_flags))
3801 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003802
3803 PUT_SINFO(T_OFFSET, t_offset, u64);
3804 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003805 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3806 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003807
3808#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003809
3810 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3811 struct nlattr *tidsattr;
3812 int tid;
3813
3814 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3815 if (!tidsattr)
3816 goto nla_put_failure;
3817
3818 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3819 struct cfg80211_tid_stats *tidstats;
3820 struct nlattr *tidattr;
3821
3822 tidstats = &sinfo->pertid[tid];
3823
3824 if (!tidstats->filled)
3825 continue;
3826
3827 tidattr = nla_nest_start(msg, tid + 1);
3828 if (!tidattr)
3829 goto nla_put_failure;
3830
3831#define PUT_TIDVAL(attr, memb, type) do { \
3832 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3833 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3834 tidstats->memb)) \
3835 goto nla_put_failure; \
3836 } while (0)
3837
3838 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3839 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3840 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3841 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3842
3843#undef PUT_TIDVAL
3844 nla_nest_end(msg, tidattr);
3845 }
3846
3847 nla_nest_end(msg, tidsattr);
3848 }
3849
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003850 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003851
Johannes Berg319090b2014-11-17 14:08:11 +01003852 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003853 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3854 sinfo->assoc_req_ies))
3855 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003856
Johannes Berg053c0952015-01-16 22:09:00 +01003857 genlmsg_end(msg, hdr);
3858 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003859
3860 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003861 genlmsg_cancel(msg, hdr);
3862 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003863}
3864
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003865static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003866 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003867{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003868 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003869 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003870 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003871 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003872 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003873 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003874
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003875 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003876 if (err)
3877 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003878
Johannes Berg97990a02013-04-19 01:02:55 +02003879 if (!wdev->netdev) {
3880 err = -EINVAL;
3881 goto out_err;
3882 }
3883
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003884 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003885 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003886 goto out_err;
3887 }
3888
Johannes Bergbba95fe2008-07-29 13:22:51 +02003889 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003890 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003891 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003892 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003893 if (err == -ENOENT)
3894 break;
3895 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003896 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003897
Johannes Bergcf5ead82014-11-14 17:14:00 +01003898 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003899 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003900 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003901 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003902 &sinfo) < 0)
3903 goto out;
3904
3905 sta_idx++;
3906 }
3907
3908
3909 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003910 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003911 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003912 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003913 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003914
3915 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003916}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003917
Johannes Berg5727ef12007-12-19 02:03:34 +01003918static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3919{
Johannes Berg4c476992010-10-04 21:36:35 +02003920 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3921 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003922 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003923 struct sk_buff *msg;
3924 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003925 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003926
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003927 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003928
3929 if (!info->attrs[NL80211_ATTR_MAC])
3930 return -EINVAL;
3931
3932 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3933
Johannes Berg4c476992010-10-04 21:36:35 +02003934 if (!rdev->ops->get_station)
3935 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003936
Hila Gonene35e4d22012-06-27 17:19:42 +03003937 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003938 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003939 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003940
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003941 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003942 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003943 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003944
Johannes Bergcf5ead82014-11-14 17:14:00 +01003945 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3946 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003947 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003948 nlmsg_free(msg);
3949 return -ENOBUFS;
3950 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003951
Johannes Berg4c476992010-10-04 21:36:35 +02003952 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003953}
3954
Johannes Berg77ee7c82013-02-15 00:48:33 +01003955int cfg80211_check_station_change(struct wiphy *wiphy,
3956 struct station_parameters *params,
3957 enum cfg80211_station_type statype)
3958{
3959 if (params->listen_interval != -1)
3960 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003961 if (params->aid &&
3962 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003963 return -EINVAL;
3964
3965 /* When you run into this, adjust the code below for the new flag */
3966 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3967
3968 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003969 case CFG80211_STA_MESH_PEER_KERNEL:
3970 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003971 /*
3972 * No ignoring the TDLS flag here -- the userspace mesh
3973 * code doesn't have the bug of including TDLS in the
3974 * mask everywhere.
3975 */
3976 if (params->sta_flags_mask &
3977 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3978 BIT(NL80211_STA_FLAG_MFP) |
3979 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3980 return -EINVAL;
3981 break;
3982 case CFG80211_STA_TDLS_PEER_SETUP:
3983 case CFG80211_STA_TDLS_PEER_ACTIVE:
3984 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3985 return -EINVAL;
3986 /* ignore since it can't change */
3987 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3988 break;
3989 default:
3990 /* disallow mesh-specific things */
3991 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3992 return -EINVAL;
3993 if (params->local_pm)
3994 return -EINVAL;
3995 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3996 return -EINVAL;
3997 }
3998
3999 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4000 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
4001 /* TDLS can't be set, ... */
4002 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
4003 return -EINVAL;
4004 /*
4005 * ... but don't bother the driver with it. This works around
4006 * a hostapd/wpa_supplicant issue -- it always includes the
4007 * TLDS_PEER flag in the mask even for AP mode.
4008 */
4009 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
4010 }
4011
Ayala Beker47edb112015-09-21 15:49:53 +03004012 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
4013 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004014 /* reject other things that can't change */
4015 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4016 return -EINVAL;
4017 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4018 return -EINVAL;
4019 if (params->supported_rates)
4020 return -EINVAL;
4021 if (params->ext_capab || params->ht_capa || params->vht_capa)
4022 return -EINVAL;
4023 }
4024
Ayala Beker47edb112015-09-21 15:49:53 +03004025 if (statype != CFG80211_STA_AP_CLIENT &&
4026 statype != CFG80211_STA_AP_CLIENT_UNASSOC) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01004027 if (params->vlan)
4028 return -EINVAL;
4029 }
4030
4031 switch (statype) {
4032 case CFG80211_STA_AP_MLME_CLIENT:
4033 /* Use this only for authorizing/unauthorizing a station */
4034 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4035 return -EOPNOTSUPP;
4036 break;
4037 case CFG80211_STA_AP_CLIENT:
Ayala Beker47edb112015-09-21 15:49:53 +03004038 case CFG80211_STA_AP_CLIENT_UNASSOC:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004039 /* accept only the listed bits */
4040 if (params->sta_flags_mask &
4041 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4042 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4043 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4044 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4045 BIT(NL80211_STA_FLAG_WME) |
4046 BIT(NL80211_STA_FLAG_MFP)))
4047 return -EINVAL;
4048
4049 /* but authenticated/associated only if driver handles it */
4050 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4051 params->sta_flags_mask &
4052 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4053 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4054 return -EINVAL;
4055 break;
4056 case CFG80211_STA_IBSS:
4057 case CFG80211_STA_AP_STA:
4058 /* reject any changes other than AUTHORIZED */
4059 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4060 return -EINVAL;
4061 break;
4062 case CFG80211_STA_TDLS_PEER_SETUP:
4063 /* reject any changes other than AUTHORIZED or WME */
4064 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4065 BIT(NL80211_STA_FLAG_WME)))
4066 return -EINVAL;
4067 /* force (at least) rates when authorizing */
4068 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4069 !params->supported_rates)
4070 return -EINVAL;
4071 break;
4072 case CFG80211_STA_TDLS_PEER_ACTIVE:
4073 /* reject any changes */
4074 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004075 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004076 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4077 return -EINVAL;
4078 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004079 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004080 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4081 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004082 return -EINVAL;
4083 break;
4084 }
4085
4086 return 0;
4087}
4088EXPORT_SYMBOL(cfg80211_check_station_change);
4089
Johannes Berg5727ef12007-12-19 02:03:34 +01004090/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004091 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004092 */
Johannes Berg80b99892011-11-18 16:23:01 +01004093static struct net_device *get_vlan(struct genl_info *info,
4094 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004095{
Johannes Berg463d0182009-07-14 00:33:35 +02004096 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004097 struct net_device *v;
4098 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004099
Johannes Berg80b99892011-11-18 16:23:01 +01004100 if (!vlanattr)
4101 return NULL;
4102
4103 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4104 if (!v)
4105 return ERR_PTR(-ENODEV);
4106
4107 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4108 ret = -EINVAL;
4109 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004110 }
Johannes Berg80b99892011-11-18 16:23:01 +01004111
Johannes Berg77ee7c82013-02-15 00:48:33 +01004112 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4113 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4114 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4115 ret = -EINVAL;
4116 goto error;
4117 }
4118
Johannes Berg80b99892011-11-18 16:23:01 +01004119 if (!netif_running(v)) {
4120 ret = -ENETDOWN;
4121 goto error;
4122 }
4123
4124 return v;
4125 error:
4126 dev_put(v);
4127 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004128}
4129
Johannes Berg94e860f2014-01-20 23:58:15 +01004130static const struct nla_policy
4131nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004132 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4133 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4134};
4135
Johannes Bergff276692013-02-15 00:09:01 +01004136static int nl80211_parse_sta_wme(struct genl_info *info,
4137 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004138{
Jouni Malinendf881292013-02-14 21:10:54 +02004139 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4140 struct nlattr *nla;
4141 int err;
4142
Jouni Malinendf881292013-02-14 21:10:54 +02004143 /* parse WME attributes if present */
4144 if (!info->attrs[NL80211_ATTR_STA_WME])
4145 return 0;
4146
4147 nla = info->attrs[NL80211_ATTR_STA_WME];
4148 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4149 nl80211_sta_wme_policy);
4150 if (err)
4151 return err;
4152
4153 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4154 params->uapsd_queues = nla_get_u8(
4155 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4156 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4157 return -EINVAL;
4158
4159 if (tb[NL80211_STA_WME_MAX_SP])
4160 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4161
4162 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4163 return -EINVAL;
4164
4165 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4166
4167 return 0;
4168}
4169
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304170static int nl80211_parse_sta_channel_info(struct genl_info *info,
4171 struct station_parameters *params)
4172{
4173 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4174 params->supported_channels =
4175 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4176 params->supported_channels_len =
4177 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4178 /*
4179 * Need to include at least one (first channel, number of
4180 * channels) tuple for each subband, and must have proper
4181 * tuples for the rest of the data as well.
4182 */
4183 if (params->supported_channels_len < 2)
4184 return -EINVAL;
4185 if (params->supported_channels_len % 2)
4186 return -EINVAL;
4187 }
4188
4189 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4190 params->supported_oper_classes =
4191 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4192 params->supported_oper_classes_len =
4193 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4194 /*
4195 * The value of the Length field of the Supported Operating
4196 * Classes element is between 2 and 253.
4197 */
4198 if (params->supported_oper_classes_len < 2 ||
4199 params->supported_oper_classes_len > 253)
4200 return -EINVAL;
4201 }
4202 return 0;
4203}
4204
Johannes Bergff276692013-02-15 00:09:01 +01004205static int nl80211_set_station_tdls(struct genl_info *info,
4206 struct station_parameters *params)
4207{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304208 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004209 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004210 if (info->attrs[NL80211_ATTR_PEER_AID])
4211 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004212 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4213 params->ht_capa =
4214 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4215 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4216 params->vht_capa =
4217 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4218
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304219 err = nl80211_parse_sta_channel_info(info, params);
4220 if (err)
4221 return err;
4222
Johannes Bergff276692013-02-15 00:09:01 +01004223 return nl80211_parse_sta_wme(info, params);
4224}
4225
Johannes Berg5727ef12007-12-19 02:03:34 +01004226static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4227{
Johannes Berg4c476992010-10-04 21:36:35 +02004228 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004229 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004230 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004231 u8 *mac_addr;
4232 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004233
4234 memset(&params, 0, sizeof(params));
4235
4236 params.listen_interval = -1;
4237
Johannes Berg77ee7c82013-02-15 00:48:33 +01004238 if (!rdev->ops->change_station)
4239 return -EOPNOTSUPP;
4240
Johannes Berg5727ef12007-12-19 02:03:34 +01004241 if (info->attrs[NL80211_ATTR_STA_AID])
4242 return -EINVAL;
4243
4244 if (!info->attrs[NL80211_ATTR_MAC])
4245 return -EINVAL;
4246
4247 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4248
4249 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4250 params.supported_rates =
4251 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4252 params.supported_rates_len =
4253 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4254 }
4255
Jouni Malinen9d62a982013-02-14 21:10:13 +02004256 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4257 params.capability =
4258 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4259 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4260 }
4261
4262 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4263 params.ext_capab =
4264 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4265 params.ext_capab_len =
4266 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4267 }
4268
Jouni Malinendf881292013-02-14 21:10:54 +02004269 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004270 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004271
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004272 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004273 return -EINVAL;
4274
Johannes Bergf8bacc22013-02-14 23:27:01 +01004275 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004276 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004277 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4278 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4279 return -EINVAL;
4280 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004281
Johannes Bergf8bacc22013-02-14 23:27:01 +01004282 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004283 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004284 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4285 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4286 return -EINVAL;
4287 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4288 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004289
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004290 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4291 enum nl80211_mesh_power_mode pm = nla_get_u32(
4292 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4293
4294 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4295 pm > NL80211_MESH_POWER_MAX)
4296 return -EINVAL;
4297
4298 params.local_pm = pm;
4299 }
4300
Johannes Berg77ee7c82013-02-15 00:48:33 +01004301 /* Include parameters for TDLS peer (will check later) */
4302 err = nl80211_set_station_tdls(info, &params);
4303 if (err)
4304 return err;
4305
4306 params.vlan = get_vlan(info, rdev);
4307 if (IS_ERR(params.vlan))
4308 return PTR_ERR(params.vlan);
4309
Johannes Berga97f4422009-06-18 17:23:43 +02004310 switch (dev->ieee80211_ptr->iftype) {
4311 case NL80211_IFTYPE_AP:
4312 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004313 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004314 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004315 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004316 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004317 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004318 break;
4319 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004320 err = -EOPNOTSUPP;
4321 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004322 }
4323
Johannes Berg77ee7c82013-02-15 00:48:33 +01004324 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004325 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004326
Johannes Berg77ee7c82013-02-15 00:48:33 +01004327 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004328 if (params.vlan)
4329 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004330
Johannes Berg5727ef12007-12-19 02:03:34 +01004331 return err;
4332}
4333
4334static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4335{
Johannes Berg4c476992010-10-04 21:36:35 +02004336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004337 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004338 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004339 struct station_parameters params;
4340 u8 *mac_addr = NULL;
4341
4342 memset(&params, 0, sizeof(params));
4343
Johannes Berg984c3112013-02-14 23:43:25 +01004344 if (!rdev->ops->add_station)
4345 return -EOPNOTSUPP;
4346
Johannes Berg5727ef12007-12-19 02:03:34 +01004347 if (!info->attrs[NL80211_ATTR_MAC])
4348 return -EINVAL;
4349
Johannes Berg5727ef12007-12-19 02:03:34 +01004350 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4351 return -EINVAL;
4352
4353 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4354 return -EINVAL;
4355
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004356 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4357 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004358 return -EINVAL;
4359
Johannes Berg5727ef12007-12-19 02:03:34 +01004360 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4361 params.supported_rates =
4362 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4363 params.supported_rates_len =
4364 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4365 params.listen_interval =
4366 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004367
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004368 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004369 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004370 else
4371 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004372 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4373 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004374
Jouni Malinen9d62a982013-02-14 21:10:13 +02004375 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4376 params.capability =
4377 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4378 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4379 }
4380
4381 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4382 params.ext_capab =
4383 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4384 params.ext_capab_len =
4385 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4386 }
4387
Jouni Malinen36aedc92008-08-25 11:58:58 +03004388 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4389 params.ht_capa =
4390 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004391
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004392 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4393 params.vht_capa =
4394 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4395
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004396 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4397 params.opmode_notif_used = true;
4398 params.opmode_notif =
4399 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4400 }
4401
Johannes Bergf8bacc22013-02-14 23:27:01 +01004402 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004403 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004404 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4405 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4406 return -EINVAL;
4407 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004408
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304409 err = nl80211_parse_sta_channel_info(info, &params);
4410 if (err)
4411 return err;
4412
Johannes Bergff276692013-02-15 00:09:01 +01004413 err = nl80211_parse_sta_wme(info, &params);
4414 if (err)
4415 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004416
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004417 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004418 return -EINVAL;
4419
Johannes Berg496fcc22015-03-12 08:53:27 +02004420 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4421 * as userspace might just pass through the capabilities from the IEs
4422 * directly, rather than enforcing this restriction and returning an
4423 * error in this case.
4424 */
4425 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4426 params.ht_capa = NULL;
4427 params.vht_capa = NULL;
4428 }
4429
Johannes Berg77ee7c82013-02-15 00:48:33 +01004430 /* When you run into this, adjust the code below for the new flag */
4431 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4432
Johannes Bergbdd90d52011-12-14 12:20:27 +01004433 switch (dev->ieee80211_ptr->iftype) {
4434 case NL80211_IFTYPE_AP:
4435 case NL80211_IFTYPE_AP_VLAN:
4436 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004437 /* ignore WME attributes if iface/sta is not capable */
4438 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4439 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4440 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004441
Johannes Bergbdd90d52011-12-14 12:20:27 +01004442 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004443 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4444 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004445 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004446 /* but don't bother the driver with it */
4447 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004448
Johannes Bergd582cff2012-10-26 17:53:44 +02004449 /* allow authenticated/associated only if driver handles it */
4450 if (!(rdev->wiphy.features &
4451 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4452 params.sta_flags_mask &
4453 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4454 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4455 return -EINVAL;
4456
Johannes Bergbdd90d52011-12-14 12:20:27 +01004457 /* must be last in here for error handling */
4458 params.vlan = get_vlan(info, rdev);
4459 if (IS_ERR(params.vlan))
4460 return PTR_ERR(params.vlan);
4461 break;
4462 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004463 /* ignore uAPSD data */
4464 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4465
Johannes Bergd582cff2012-10-26 17:53:44 +02004466 /* associated is disallowed */
4467 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4468 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004469 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004470 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4471 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004472 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004473 break;
4474 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004475 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004476 /* ignore uAPSD data */
4477 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4478
Johannes Berg77ee7c82013-02-15 00:48:33 +01004479 /* these are disallowed */
4480 if (params.sta_flags_mask &
4481 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4482 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004483 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004484 /* Only TDLS peers can be added */
4485 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4486 return -EINVAL;
4487 /* Can only add if TDLS ... */
4488 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4489 return -EOPNOTSUPP;
4490 /* ... with external setup is supported */
4491 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4492 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004493 /*
4494 * Older wpa_supplicant versions always mark the TDLS peer
4495 * as authorized, but it shouldn't yet be.
4496 */
4497 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004498 break;
4499 default:
4500 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004501 }
4502
Johannes Bergbdd90d52011-12-14 12:20:27 +01004503 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004504
Hila Gonene35e4d22012-06-27 17:19:42 +03004505 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004506
Johannes Berg5727ef12007-12-19 02:03:34 +01004507 if (params.vlan)
4508 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004509 return err;
4510}
4511
4512static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4513{
Johannes Berg4c476992010-10-04 21:36:35 +02004514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4515 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004516 struct station_del_parameters params;
4517
4518 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004519
4520 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004521 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004522
Johannes Berge80cf852009-05-11 14:43:13 +02004523 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004524 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004525 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004526 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4527 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004528
Johannes Berg4c476992010-10-04 21:36:35 +02004529 if (!rdev->ops->del_station)
4530 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004531
Jouni Malinen98856862014-10-20 13:20:45 +03004532 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4533 params.subtype =
4534 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4535 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4536 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4537 return -EINVAL;
4538 } else {
4539 /* Default to Deauthentication frame */
4540 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4541 }
4542
4543 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4544 params.reason_code =
4545 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4546 if (params.reason_code == 0)
4547 return -EINVAL; /* 0 is reserved */
4548 } else {
4549 /* Default to reason code 2 */
4550 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4551 }
4552
Jouni Malinen89c771e2014-10-10 20:52:40 +03004553 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004554}
4555
Eric W. Biederman15e47302012-09-07 20:12:54 +00004556static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004557 int flags, struct net_device *dev,
4558 u8 *dst, u8 *next_hop,
4559 struct mpath_info *pinfo)
4560{
4561 void *hdr;
4562 struct nlattr *pinfoattr;
4563
Henning Rogge1ef4c852014-11-04 16:14:58 +01004564 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004565 if (!hdr)
4566 return -1;
4567
David S. Miller9360ffd2012-03-29 04:41:26 -04004568 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4569 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4570 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4571 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4572 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004573
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004574 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4575 if (!pinfoattr)
4576 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004577 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4578 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4579 pinfo->frame_qlen))
4580 goto nla_put_failure;
4581 if (((pinfo->filled & MPATH_INFO_SN) &&
4582 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4583 ((pinfo->filled & MPATH_INFO_METRIC) &&
4584 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4585 pinfo->metric)) ||
4586 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4587 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4588 pinfo->exptime)) ||
4589 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4590 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4591 pinfo->flags)) ||
4592 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4593 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4594 pinfo->discovery_timeout)) ||
4595 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4596 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4597 pinfo->discovery_retries)))
4598 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004599
4600 nla_nest_end(msg, pinfoattr);
4601
Johannes Berg053c0952015-01-16 22:09:00 +01004602 genlmsg_end(msg, hdr);
4603 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004604
4605 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004606 genlmsg_cancel(msg, hdr);
4607 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004608}
4609
4610static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004611 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004612{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004613 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004614 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004615 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004616 u8 dst[ETH_ALEN];
4617 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004618 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004619 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004620
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004621 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004622 if (err)
4623 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004624
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004625 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004626 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004627 goto out_err;
4628 }
4629
Johannes Berg97990a02013-04-19 01:02:55 +02004630 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004631 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004632 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004633 }
4634
Johannes Bergbba95fe2008-07-29 13:22:51 +02004635 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004636 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004637 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004638 if (err == -ENOENT)
4639 break;
4640 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004641 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004642
Eric W. Biederman15e47302012-09-07 20:12:54 +00004643 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004644 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004645 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004646 &pinfo) < 0)
4647 goto out;
4648
4649 path_idx++;
4650 }
4651
4652
4653 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004654 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004655 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004656 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004657 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004658 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004659}
4660
4661static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4662{
Johannes Berg4c476992010-10-04 21:36:35 +02004663 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004664 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004665 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004666 struct mpath_info pinfo;
4667 struct sk_buff *msg;
4668 u8 *dst = NULL;
4669 u8 next_hop[ETH_ALEN];
4670
4671 memset(&pinfo, 0, sizeof(pinfo));
4672
4673 if (!info->attrs[NL80211_ATTR_MAC])
4674 return -EINVAL;
4675
4676 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4677
Johannes Berg4c476992010-10-04 21:36:35 +02004678 if (!rdev->ops->get_mpath)
4679 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004680
Johannes Berg4c476992010-10-04 21:36:35 +02004681 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4682 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004683
Hila Gonene35e4d22012-06-27 17:19:42 +03004684 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004685 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004686 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004687
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004688 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004689 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004690 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004691
Eric W. Biederman15e47302012-09-07 20:12:54 +00004692 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004693 dev, dst, next_hop, &pinfo) < 0) {
4694 nlmsg_free(msg);
4695 return -ENOBUFS;
4696 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004697
Johannes Berg4c476992010-10-04 21:36:35 +02004698 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004699}
4700
4701static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4702{
Johannes Berg4c476992010-10-04 21:36:35 +02004703 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4704 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004705 u8 *dst = NULL;
4706 u8 *next_hop = NULL;
4707
4708 if (!info->attrs[NL80211_ATTR_MAC])
4709 return -EINVAL;
4710
4711 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4712 return -EINVAL;
4713
4714 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4715 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4716
Johannes Berg4c476992010-10-04 21:36:35 +02004717 if (!rdev->ops->change_mpath)
4718 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004719
Johannes Berg4c476992010-10-04 21:36:35 +02004720 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4721 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004722
Hila Gonene35e4d22012-06-27 17:19:42 +03004723 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004724}
Johannes Berg4c476992010-10-04 21:36:35 +02004725
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004726static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4727{
Johannes Berg4c476992010-10-04 21:36:35 +02004728 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4729 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004730 u8 *dst = NULL;
4731 u8 *next_hop = NULL;
4732
4733 if (!info->attrs[NL80211_ATTR_MAC])
4734 return -EINVAL;
4735
4736 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4737 return -EINVAL;
4738
4739 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4740 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4741
Johannes Berg4c476992010-10-04 21:36:35 +02004742 if (!rdev->ops->add_mpath)
4743 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004744
Johannes Berg4c476992010-10-04 21:36:35 +02004745 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4746 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004747
Hila Gonene35e4d22012-06-27 17:19:42 +03004748 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004749}
4750
4751static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4752{
Johannes Berg4c476992010-10-04 21:36:35 +02004753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4754 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004755 u8 *dst = NULL;
4756
4757 if (info->attrs[NL80211_ATTR_MAC])
4758 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4759
Johannes Berg4c476992010-10-04 21:36:35 +02004760 if (!rdev->ops->del_mpath)
4761 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004762
Hila Gonene35e4d22012-06-27 17:19:42 +03004763 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004764}
4765
Henning Rogge66be7d22014-09-12 08:58:49 +02004766static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4767{
4768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4769 int err;
4770 struct net_device *dev = info->user_ptr[1];
4771 struct mpath_info pinfo;
4772 struct sk_buff *msg;
4773 u8 *dst = NULL;
4774 u8 mpp[ETH_ALEN];
4775
4776 memset(&pinfo, 0, sizeof(pinfo));
4777
4778 if (!info->attrs[NL80211_ATTR_MAC])
4779 return -EINVAL;
4780
4781 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4782
4783 if (!rdev->ops->get_mpp)
4784 return -EOPNOTSUPP;
4785
4786 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4787 return -EOPNOTSUPP;
4788
4789 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4790 if (err)
4791 return err;
4792
4793 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4794 if (!msg)
4795 return -ENOMEM;
4796
4797 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4798 dev, dst, mpp, &pinfo) < 0) {
4799 nlmsg_free(msg);
4800 return -ENOBUFS;
4801 }
4802
4803 return genlmsg_reply(msg, info);
4804}
4805
4806static int nl80211_dump_mpp(struct sk_buff *skb,
4807 struct netlink_callback *cb)
4808{
4809 struct mpath_info pinfo;
4810 struct cfg80211_registered_device *rdev;
4811 struct wireless_dev *wdev;
4812 u8 dst[ETH_ALEN];
4813 u8 mpp[ETH_ALEN];
4814 int path_idx = cb->args[2];
4815 int err;
4816
4817 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4818 if (err)
4819 return err;
4820
4821 if (!rdev->ops->dump_mpp) {
4822 err = -EOPNOTSUPP;
4823 goto out_err;
4824 }
4825
4826 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4827 err = -EOPNOTSUPP;
4828 goto out_err;
4829 }
4830
4831 while (1) {
4832 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4833 mpp, &pinfo);
4834 if (err == -ENOENT)
4835 break;
4836 if (err)
4837 goto out_err;
4838
4839 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4840 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4841 wdev->netdev, dst, mpp,
4842 &pinfo) < 0)
4843 goto out;
4844
4845 path_idx++;
4846 }
4847
4848 out:
4849 cb->args[2] = path_idx;
4850 err = skb->len;
4851 out_err:
4852 nl80211_finish_wdev_dump(rdev);
4853 return err;
4854}
4855
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004856static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4857{
Johannes Berg4c476992010-10-04 21:36:35 +02004858 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4859 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004860 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004861 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004862 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004863
4864 memset(&params, 0, sizeof(params));
4865 /* default to not changing parameters */
4866 params.use_cts_prot = -1;
4867 params.use_short_preamble = -1;
4868 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004869 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004870 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004871 params.p2p_ctwindow = -1;
4872 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004873
4874 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4875 params.use_cts_prot =
4876 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4877 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4878 params.use_short_preamble =
4879 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4880 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4881 params.use_short_slot_time =
4882 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004883 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4884 params.basic_rates =
4885 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4886 params.basic_rates_len =
4887 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4888 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004889 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4890 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004891 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4892 params.ht_opmode =
4893 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004894
Johannes Berg53cabad2012-11-14 15:17:28 +01004895 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4896 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4897 return -EINVAL;
4898 params.p2p_ctwindow =
4899 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4900 if (params.p2p_ctwindow < 0)
4901 return -EINVAL;
4902 if (params.p2p_ctwindow != 0 &&
4903 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4904 return -EINVAL;
4905 }
4906
4907 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4908 u8 tmp;
4909
4910 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4911 return -EINVAL;
4912 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4913 if (tmp > 1)
4914 return -EINVAL;
4915 params.p2p_opp_ps = tmp;
4916 if (params.p2p_opp_ps &&
4917 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4918 return -EINVAL;
4919 }
4920
Johannes Berg4c476992010-10-04 21:36:35 +02004921 if (!rdev->ops->change_bss)
4922 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004923
Johannes Berg074ac8d2010-09-16 14:58:22 +02004924 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004925 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4926 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004927
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004928 wdev_lock(wdev);
4929 err = rdev_change_bss(rdev, dev, &params);
4930 wdev_unlock(wdev);
4931
4932 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004933}
4934
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004935static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004936 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4937 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4938 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4939 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4940 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4941 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004942 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004943};
4944
4945static int parse_reg_rule(struct nlattr *tb[],
4946 struct ieee80211_reg_rule *reg_rule)
4947{
4948 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4949 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4950
4951 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4952 return -EINVAL;
4953 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4954 return -EINVAL;
4955 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4956 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004957 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4958 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004959 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4960 return -EINVAL;
4961
4962 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4963
4964 freq_range->start_freq_khz =
4965 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4966 freq_range->end_freq_khz =
4967 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004968 freq_range->max_bandwidth_khz =
4969 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004970
4971 power_rule->max_eirp =
4972 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4973
4974 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4975 power_rule->max_antenna_gain =
4976 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4977
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004978 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4979 reg_rule->dfs_cac_ms =
4980 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4981
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004982 return 0;
4983}
4984
4985static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4986{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004987 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05004988 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004989 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05004990 u32 owner_nlportid;
4991
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004992
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004993 /*
4994 * You should only get this when cfg80211 hasn't yet initialized
4995 * completely when built-in to the kernel right between the time
4996 * window between nl80211_init() and regulatory_init(), if that is
4997 * even possible.
4998 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004999 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05005000 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05005001
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005002 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
5003 user_reg_hint_type =
5004 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
5005 else
5006 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
5007
5008 switch (user_reg_hint_type) {
5009 case NL80211_USER_REG_HINT_USER:
5010 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02005011 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5012 return -EINVAL;
5013
5014 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5015 return regulatory_hint_user(data, user_reg_hint_type);
5016 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005017 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5018 owner_nlportid = info->snd_portid;
5019 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5020 } else {
5021 owner_nlportid = 0;
5022 is_indoor = true;
5023 }
5024
5025 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005026 default:
5027 return -EINVAL;
5028 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005029}
5030
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005031static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005032 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005033{
Johannes Berg4c476992010-10-04 21:36:35 +02005034 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005035 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005036 struct wireless_dev *wdev = dev->ieee80211_ptr;
5037 struct mesh_config cur_params;
5038 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005039 void *hdr;
5040 struct nlattr *pinfoattr;
5041 struct sk_buff *msg;
5042
Johannes Berg29cbe682010-12-03 09:20:44 +01005043 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5044 return -EOPNOTSUPP;
5045
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005046 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005047 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005048
Johannes Berg29cbe682010-12-03 09:20:44 +01005049 wdev_lock(wdev);
5050 /* If not connected, get default parameters */
5051 if (!wdev->mesh_id_len)
5052 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5053 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005054 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005055 wdev_unlock(wdev);
5056
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005057 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005058 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005059
5060 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005061 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005062 if (!msg)
5063 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005064 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005065 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005066 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005067 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005068 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005069 if (!pinfoattr)
5070 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005071 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5072 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5073 cur_params.dot11MeshRetryTimeout) ||
5074 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5075 cur_params.dot11MeshConfirmTimeout) ||
5076 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5077 cur_params.dot11MeshHoldingTimeout) ||
5078 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5079 cur_params.dot11MeshMaxPeerLinks) ||
5080 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5081 cur_params.dot11MeshMaxRetries) ||
5082 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5083 cur_params.dot11MeshTTL) ||
5084 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5085 cur_params.element_ttl) ||
5086 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5087 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005088 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5089 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005090 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5091 cur_params.dot11MeshHWMPmaxPREQretries) ||
5092 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5093 cur_params.path_refresh_time) ||
5094 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5095 cur_params.min_discovery_timeout) ||
5096 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5097 cur_params.dot11MeshHWMPactivePathTimeout) ||
5098 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5099 cur_params.dot11MeshHWMPpreqMinInterval) ||
5100 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5101 cur_params.dot11MeshHWMPperrMinInterval) ||
5102 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5103 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5104 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5105 cur_params.dot11MeshHWMPRootMode) ||
5106 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5107 cur_params.dot11MeshHWMPRannInterval) ||
5108 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5109 cur_params.dot11MeshGateAnnouncementProtocol) ||
5110 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5111 cur_params.dot11MeshForwarding) ||
5112 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005113 cur_params.rssi_threshold) ||
5114 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005115 cur_params.ht_opmode) ||
5116 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5117 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5118 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005119 cur_params.dot11MeshHWMProotInterval) ||
5120 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005121 cur_params.dot11MeshHWMPconfirmationInterval) ||
5122 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5123 cur_params.power_mode) ||
5124 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005125 cur_params.dot11MeshAwakeWindowDuration) ||
5126 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5127 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005128 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005129 nla_nest_end(msg, pinfoattr);
5130 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005131 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005132
Johannes Berg3b858752009-03-12 09:55:09 +01005133 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005134 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005135 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005136 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005137 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005138}
5139
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005140static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005141 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5142 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5143 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5144 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5145 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5146 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005147 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005148 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005149 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005150 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5151 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5152 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5153 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5154 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005155 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005156 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005157 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005158 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005159 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005160 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005161 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5162 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005163 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5164 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005165 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005166 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5167 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005168 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005169};
5170
Javier Cardonac80d5452010-12-16 17:37:49 -08005171static const struct nla_policy
5172 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005173 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005174 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5175 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005176 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005177 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005178 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005179 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005180 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005181 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005182};
5183
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005184static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005185 struct mesh_config *cfg,
5186 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005187{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005188 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005189 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005190
Marco Porschea54fba2013-01-07 16:04:48 +01005191#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5192do { \
5193 if (tb[attr]) { \
5194 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5195 return -EINVAL; \
5196 cfg->param = fn(tb[attr]); \
5197 mask |= (1 << (attr - 1)); \
5198 } \
5199} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005200
5201
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005202 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005203 return -EINVAL;
5204 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005205 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005206 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005207 return -EINVAL;
5208
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005209 /* This makes sure that there aren't more than 32 mesh config
5210 * parameters (otherwise our bitfield scheme would not work.) */
5211 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5212
5213 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005214 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005215 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5216 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005217 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005218 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5219 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005220 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005221 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5222 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005223 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005224 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5225 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005227 mask, NL80211_MESHCONF_MAX_RETRIES,
5228 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005229 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005230 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005231 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005232 mask, NL80211_MESHCONF_ELEMENT_TTL,
5233 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005234 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005235 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5236 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005237 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5238 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005239 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5240 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005241 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005242 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5243 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005244 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005245 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5246 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005247 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005248 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5249 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005250 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5251 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005252 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5253 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005254 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005255 1, 65535, mask,
5256 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005257 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005258 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005259 1, 65535, mask,
5260 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005261 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005262 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005263 dot11MeshHWMPnetDiameterTraversalTime,
5264 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005265 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5266 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005267 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5268 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5269 nla_get_u8);
5270 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5271 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005272 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005273 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005274 dot11MeshGateAnnouncementProtocol, 0, 1,
5275 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005276 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005277 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005278 mask, NL80211_MESHCONF_FORWARDING,
5279 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005280 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005281 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005282 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005283 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005284 mask, NL80211_MESHCONF_HT_OPMODE,
5285 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005286 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005287 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005288 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5289 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005290 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005291 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5292 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005293 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005294 dot11MeshHWMPconfirmationInterval,
5295 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005296 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5297 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005298 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5299 NL80211_MESH_POWER_ACTIVE,
5300 NL80211_MESH_POWER_MAX,
5301 mask, NL80211_MESHCONF_POWER_MODE,
5302 nla_get_u32);
5303 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5304 0, 65535, mask,
5305 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005306 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005307 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5308 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005309 if (mask_out)
5310 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005311
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005312 return 0;
5313
5314#undef FILL_IN_MESH_PARAM_IF_SET
5315}
5316
Javier Cardonac80d5452010-12-16 17:37:49 -08005317static int nl80211_parse_mesh_setup(struct genl_info *info,
5318 struct mesh_setup *setup)
5319{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005321 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5322
5323 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5324 return -EINVAL;
5325 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5326 info->attrs[NL80211_ATTR_MESH_SETUP],
5327 nl80211_mesh_setup_params_policy))
5328 return -EINVAL;
5329
Javier Cardonad299a1f2012-03-31 11:31:33 -07005330 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5331 setup->sync_method =
5332 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5333 IEEE80211_SYNC_METHOD_VENDOR :
5334 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5335
Javier Cardonac80d5452010-12-16 17:37:49 -08005336 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5337 setup->path_sel_proto =
5338 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5339 IEEE80211_PATH_PROTOCOL_VENDOR :
5340 IEEE80211_PATH_PROTOCOL_HWMP;
5341
5342 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5343 setup->path_metric =
5344 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5345 IEEE80211_PATH_METRIC_VENDOR :
5346 IEEE80211_PATH_METRIC_AIRTIME;
5347
Javier Cardona581a8b02011-04-07 15:08:27 -07005348
5349 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005350 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005351 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005352 if (!is_valid_ie_attr(ieattr))
5353 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005354 setup->ie = nla_data(ieattr);
5355 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005356 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005357 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5358 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5359 return -EINVAL;
5360 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005361 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5362 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005363 if (setup->is_secure)
5364 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005365
Colleen Twitty6e16d902013-05-08 11:45:59 -07005366 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5367 if (!setup->user_mpm)
5368 return -EINVAL;
5369 setup->auth_id =
5370 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5371 }
5372
Javier Cardonac80d5452010-12-16 17:37:49 -08005373 return 0;
5374}
5375
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005376static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005377 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005378{
5379 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5380 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005381 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005382 struct mesh_config cfg;
5383 u32 mask;
5384 int err;
5385
Johannes Berg29cbe682010-12-03 09:20:44 +01005386 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5387 return -EOPNOTSUPP;
5388
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005389 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005390 return -EOPNOTSUPP;
5391
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005392 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005393 if (err)
5394 return err;
5395
Johannes Berg29cbe682010-12-03 09:20:44 +01005396 wdev_lock(wdev);
5397 if (!wdev->mesh_id_len)
5398 err = -ENOLINK;
5399
5400 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005401 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005402
5403 wdev_unlock(wdev);
5404
5405 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005406}
5407
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005408static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5409 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005410{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005411 struct nlattr *nl_reg_rules;
5412 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005413
Johannes Berg458f4f92012-12-06 15:47:38 +01005414 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5415 (regdom->dfs_region &&
5416 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005417 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005418
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005419 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5420 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005421 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005422
Johannes Berg458f4f92012-12-06 15:47:38 +01005423 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005424 struct nlattr *nl_reg_rule;
5425 const struct ieee80211_reg_rule *reg_rule;
5426 const struct ieee80211_freq_range *freq_range;
5427 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005428 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005429
Johannes Berg458f4f92012-12-06 15:47:38 +01005430 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005431 freq_range = &reg_rule->freq_range;
5432 power_rule = &reg_rule->power_rule;
5433
5434 nl_reg_rule = nla_nest_start(msg, i);
5435 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005436 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005437
Janusz Dziedzic97524822014-01-30 09:52:20 +01005438 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5439 if (!max_bandwidth_khz)
5440 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5441 reg_rule);
5442
David S. Miller9360ffd2012-03-29 04:41:26 -04005443 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5444 reg_rule->flags) ||
5445 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5446 freq_range->start_freq_khz) ||
5447 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5448 freq_range->end_freq_khz) ||
5449 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005450 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005451 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5452 power_rule->max_antenna_gain) ||
5453 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005454 power_rule->max_eirp) ||
5455 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5456 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005457 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005458
5459 nla_nest_end(msg, nl_reg_rule);
5460 }
5461
5462 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005463 return 0;
5464
5465nla_put_failure:
5466 return -EMSGSIZE;
5467}
5468
5469static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5470{
5471 const struct ieee80211_regdomain *regdom = NULL;
5472 struct cfg80211_registered_device *rdev;
5473 struct wiphy *wiphy = NULL;
5474 struct sk_buff *msg;
5475 void *hdr;
5476
5477 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5478 if (!msg)
5479 return -ENOBUFS;
5480
5481 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5482 NL80211_CMD_GET_REG);
5483 if (!hdr)
5484 goto put_failure;
5485
5486 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005487 bool self_managed;
5488
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005489 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5490 if (IS_ERR(rdev)) {
5491 nlmsg_free(msg);
5492 return PTR_ERR(rdev);
5493 }
5494
5495 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005496 self_managed = wiphy->regulatory_flags &
5497 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005498 regdom = get_wiphy_regdom(wiphy);
5499
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005500 /* a self-managed-reg device must have a private regdom */
5501 if (WARN_ON(!regdom && self_managed)) {
5502 nlmsg_free(msg);
5503 return -EINVAL;
5504 }
5505
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005506 if (regdom &&
5507 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5508 goto nla_put_failure;
5509 }
5510
5511 if (!wiphy && reg_last_request_cell_base() &&
5512 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5513 NL80211_USER_REG_HINT_CELL_BASE))
5514 goto nla_put_failure;
5515
5516 rcu_read_lock();
5517
5518 if (!regdom)
5519 regdom = rcu_dereference(cfg80211_regdomain);
5520
5521 if (nl80211_put_regdom(regdom, msg))
5522 goto nla_put_failure_rcu;
5523
5524 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005525
5526 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005527 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005528
Johannes Berg458f4f92012-12-06 15:47:38 +01005529nla_put_failure_rcu:
5530 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005531nla_put_failure:
5532 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005533put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005534 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005535 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005536}
5537
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005538static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5539 u32 seq, int flags, struct wiphy *wiphy,
5540 const struct ieee80211_regdomain *regdom)
5541{
5542 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5543 NL80211_CMD_GET_REG);
5544
5545 if (!hdr)
5546 return -1;
5547
5548 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5549
5550 if (nl80211_put_regdom(regdom, msg))
5551 goto nla_put_failure;
5552
5553 if (!wiphy && reg_last_request_cell_base() &&
5554 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5555 NL80211_USER_REG_HINT_CELL_BASE))
5556 goto nla_put_failure;
5557
5558 if (wiphy &&
5559 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5560 goto nla_put_failure;
5561
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005562 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5563 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5564 goto nla_put_failure;
5565
Johannes Berg053c0952015-01-16 22:09:00 +01005566 genlmsg_end(msg, hdr);
5567 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005568
5569nla_put_failure:
5570 genlmsg_cancel(msg, hdr);
5571 return -EMSGSIZE;
5572}
5573
5574static int nl80211_get_reg_dump(struct sk_buff *skb,
5575 struct netlink_callback *cb)
5576{
5577 const struct ieee80211_regdomain *regdom = NULL;
5578 struct cfg80211_registered_device *rdev;
5579 int err, reg_idx, start = cb->args[2];
5580
5581 rtnl_lock();
5582
5583 if (cfg80211_regdomain && start == 0) {
5584 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5585 NLM_F_MULTI, NULL,
5586 rtnl_dereference(cfg80211_regdomain));
5587 if (err < 0)
5588 goto out_err;
5589 }
5590
5591 /* the global regdom is idx 0 */
5592 reg_idx = 1;
5593 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5594 regdom = get_wiphy_regdom(&rdev->wiphy);
5595 if (!regdom)
5596 continue;
5597
5598 if (++reg_idx <= start)
5599 continue;
5600
5601 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5602 NLM_F_MULTI, &rdev->wiphy, regdom);
5603 if (err < 0) {
5604 reg_idx--;
5605 break;
5606 }
5607 }
5608
5609 cb->args[2] = reg_idx;
5610 err = skb->len;
5611out_err:
5612 rtnl_unlock();
5613 return err;
5614}
5615
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005616static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5617{
5618 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5619 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005620 char *alpha2;
5621 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005622 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005623 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005624 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005625
5626 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5627 return -EINVAL;
5628
5629 if (!info->attrs[NL80211_ATTR_REG_RULES])
5630 return -EINVAL;
5631
5632 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5633
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005634 if (info->attrs[NL80211_ATTR_DFS_REGION])
5635 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5636
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005637 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005638 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005639 num_rules++;
5640 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005641 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005642 }
5643
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005644 if (!reg_is_valid_request(alpha2))
5645 return -EINVAL;
5646
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005647 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005648 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005649
5650 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005651 if (!rd)
5652 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005653
5654 rd->n_reg_rules = num_rules;
5655 rd->alpha2[0] = alpha2[0];
5656 rd->alpha2[1] = alpha2[1];
5657
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005658 /*
5659 * Disable DFS master mode if the DFS region was
5660 * not supported or known on this kernel.
5661 */
5662 if (reg_supported_dfs_region(dfs_region))
5663 rd->dfs_region = dfs_region;
5664
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005665 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005666 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005667 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5668 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5669 reg_rule_policy);
5670 if (r)
5671 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005672 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5673 if (r)
5674 goto bad_reg;
5675
5676 rule_idx++;
5677
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005678 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5679 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005680 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005681 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005682 }
5683
Ilan peerc37722b2015-03-30 15:15:49 +03005684 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005685 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005686 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005687
Johannes Bergd2372b32008-10-24 20:32:20 +02005688 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005689 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005690 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005691}
5692
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005693static int validate_scan_freqs(struct nlattr *freqs)
5694{
5695 struct nlattr *attr1, *attr2;
5696 int n_channels = 0, tmp1, tmp2;
5697
5698 nla_for_each_nested(attr1, freqs, tmp1) {
5699 n_channels++;
5700 /*
5701 * Some hardware has a limited channel list for
5702 * scanning, and it is pretty much nonsensical
5703 * to scan for a channel twice, so disallow that
5704 * and don't require drivers to check that the
5705 * channel list they get isn't longer than what
5706 * they can scan, as long as they can scan all
5707 * the channels they registered at once.
5708 */
5709 nla_for_each_nested(attr2, freqs, tmp2)
5710 if (attr1 != attr2 &&
5711 nla_get_u32(attr1) == nla_get_u32(attr2))
5712 return 0;
5713 }
5714
5715 return n_channels;
5716}
5717
Johannes Bergad2b26a2014-06-12 21:39:05 +02005718static int nl80211_parse_random_mac(struct nlattr **attrs,
5719 u8 *mac_addr, u8 *mac_addr_mask)
5720{
5721 int i;
5722
5723 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005724 eth_zero_addr(mac_addr);
5725 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005726 mac_addr[0] = 0x2;
5727 mac_addr_mask[0] = 0x3;
5728
5729 return 0;
5730 }
5731
5732 /* need both or none */
5733 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5734 return -EINVAL;
5735
5736 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5737 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5738
5739 /* don't allow or configure an mcast address */
5740 if (!is_multicast_ether_addr(mac_addr_mask) ||
5741 is_multicast_ether_addr(mac_addr))
5742 return -EINVAL;
5743
5744 /*
5745 * allow users to pass a MAC address that has bits set outside
5746 * of the mask, but don't bother drivers with having to deal
5747 * with such bits
5748 */
5749 for (i = 0; i < ETH_ALEN; i++)
5750 mac_addr[i] &= mac_addr_mask[i];
5751
5752 return 0;
5753}
5754
Johannes Berg2a519312009-02-10 21:25:55 +01005755static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5756{
Johannes Berg4c476992010-10-04 21:36:35 +02005757 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005758 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005759 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005760 struct nlattr *attr;
5761 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005762 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005763 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005764
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005765 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5766 return -EINVAL;
5767
Johannes Berg79c97e92009-07-07 03:56:12 +02005768 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005769
Johannes Berg4c476992010-10-04 21:36:35 +02005770 if (!rdev->ops->scan)
5771 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005772
Johannes Bergf9d15d12014-01-22 11:14:19 +02005773 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005774 err = -EBUSY;
5775 goto unlock;
5776 }
Johannes Berg2a519312009-02-10 21:25:55 +01005777
5778 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005779 n_channels = validate_scan_freqs(
5780 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005781 if (!n_channels) {
5782 err = -EINVAL;
5783 goto unlock;
5784 }
Johannes Berg2a519312009-02-10 21:25:55 +01005785 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005786 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005787 }
5788
5789 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5790 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5791 n_ssids++;
5792
Johannes Bergf9f47522013-03-19 15:04:07 +01005793 if (n_ssids > wiphy->max_scan_ssids) {
5794 err = -EINVAL;
5795 goto unlock;
5796 }
Johannes Berg2a519312009-02-10 21:25:55 +01005797
Jouni Malinen70692ad2009-02-16 19:39:13 +02005798 if (info->attrs[NL80211_ATTR_IE])
5799 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5800 else
5801 ie_len = 0;
5802
Johannes Bergf9f47522013-03-19 15:04:07 +01005803 if (ie_len > wiphy->max_scan_ie_len) {
5804 err = -EINVAL;
5805 goto unlock;
5806 }
Johannes Berg18a83652009-03-31 12:12:05 +02005807
Johannes Berg2a519312009-02-10 21:25:55 +01005808 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005809 + sizeof(*request->ssids) * n_ssids
5810 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005811 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005812 if (!request) {
5813 err = -ENOMEM;
5814 goto unlock;
5815 }
Johannes Berg2a519312009-02-10 21:25:55 +01005816
Johannes Berg2a519312009-02-10 21:25:55 +01005817 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005818 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005819 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005820 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005821 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005822 request->ie = (void *)(request->ssids + n_ssids);
5823 else
5824 request->ie = (void *)(request->channels + n_channels);
5825 }
Johannes Berg2a519312009-02-10 21:25:55 +01005826
Johannes Berg584991d2009-11-02 13:32:03 +01005827 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005828 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5829 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005830 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005831 struct ieee80211_channel *chan;
5832
5833 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5834
5835 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005836 err = -EINVAL;
5837 goto out_free;
5838 }
Johannes Berg584991d2009-11-02 13:32:03 +01005839
5840 /* ignore disabled channels */
5841 if (chan->flags & IEEE80211_CHAN_DISABLED)
5842 continue;
5843
5844 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005845 i++;
5846 }
5847 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005848 enum ieee80211_band band;
5849
Johannes Berg2a519312009-02-10 21:25:55 +01005850 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005851 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5852 int j;
5853 if (!wiphy->bands[band])
5854 continue;
5855 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005856 struct ieee80211_channel *chan;
5857
5858 chan = &wiphy->bands[band]->channels[j];
5859
5860 if (chan->flags & IEEE80211_CHAN_DISABLED)
5861 continue;
5862
5863 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005864 i++;
5865 }
5866 }
5867 }
5868
Johannes Berg584991d2009-11-02 13:32:03 +01005869 if (!i) {
5870 err = -EINVAL;
5871 goto out_free;
5872 }
5873
5874 request->n_channels = i;
5875
Johannes Berg2a519312009-02-10 21:25:55 +01005876 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005877 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005878 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005879 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005880 err = -EINVAL;
5881 goto out_free;
5882 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005883 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005884 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005885 i++;
5886 }
5887 }
5888
Jouni Malinen70692ad2009-02-16 19:39:13 +02005889 if (info->attrs[NL80211_ATTR_IE]) {
5890 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005891 memcpy((void *)request->ie,
5892 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005893 request->ie_len);
5894 }
5895
Johannes Berg34850ab2011-07-18 18:08:35 +02005896 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005897 if (wiphy->bands[i])
5898 request->rates[i] =
5899 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005900
5901 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5902 nla_for_each_nested(attr,
5903 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5904 tmp) {
5905 enum ieee80211_band band = nla_type(attr);
5906
Dan Carpenter84404622011-07-29 11:52:18 +03005907 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005908 err = -EINVAL;
5909 goto out_free;
5910 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005911
5912 if (!wiphy->bands[band])
5913 continue;
5914
Johannes Berg34850ab2011-07-18 18:08:35 +02005915 err = ieee80211_get_ratemask(wiphy->bands[band],
5916 nla_data(attr),
5917 nla_len(attr),
5918 &request->rates[band]);
5919 if (err)
5920 goto out_free;
5921 }
5922 }
5923
Sam Leffler46856bb2012-10-11 21:03:32 -07005924 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005925 request->flags = nla_get_u32(
5926 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005927 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5928 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005929 err = -EOPNOTSUPP;
5930 goto out_free;
5931 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005932
5933 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5934 if (!(wiphy->features &
5935 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5936 err = -EOPNOTSUPP;
5937 goto out_free;
5938 }
5939
5940 if (wdev->current_bss) {
5941 err = -EOPNOTSUPP;
5942 goto out_free;
5943 }
5944
5945 err = nl80211_parse_random_mac(info->attrs,
5946 request->mac_addr,
5947 request->mac_addr_mask);
5948 if (err)
5949 goto out_free;
5950 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005951 }
Sam Lefflered4737712012-10-11 21:03:31 -07005952
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305953 request->no_cck =
5954 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5955
Johannes Bergfd014282012-06-18 19:17:03 +02005956 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005957 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005958 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005959
Johannes Berg79c97e92009-07-07 03:56:12 +02005960 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005961 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005962
Johannes Berg463d0182009-07-14 00:33:35 +02005963 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005964 nl80211_send_scan_start(rdev, wdev);
5965 if (wdev->netdev)
5966 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005967 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005968 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005969 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005970 kfree(request);
5971 }
Johannes Berg3b858752009-03-12 09:55:09 +01005972
Johannes Bergf9f47522013-03-19 15:04:07 +01005973 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005974 return err;
5975}
5976
Luciano Coelho256da022014-11-10 16:13:46 +02005977static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005978nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005979 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005980{
5981 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005982 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005983 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005984 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005985 enum ieee80211_band band;
5986 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005987 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005988 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005989
Luciano Coelho256da022014-11-10 16:13:46 +02005990 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5991 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005992
Luciano Coelho256da022014-11-10 16:13:46 +02005993 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5994 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005995
Luciano Coelho256da022014-11-10 16:13:46 +02005996 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005997 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005998 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005999
Luciano Coelho256da022014-11-10 16:13:46 +02006000 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006001 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02006002 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006003 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02006004 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006005 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02006006 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006007 }
6008
Luciano Coelho256da022014-11-10 16:13:46 +02006009 if (attrs[NL80211_ATTR_SCAN_SSIDS])
6010 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006011 tmp)
6012 n_ssids++;
6013
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006014 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006015 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006016
Johannes Bergea73cbc2014-01-24 10:53:53 +01006017 /*
6018 * First, count the number of 'real' matchsets. Due to an issue with
6019 * the old implementation, matchsets containing only the RSSI attribute
6020 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6021 * RSSI for all matchsets, rather than their own matchset for reporting
6022 * all APs with a strong RSSI. This is needed to be compatible with
6023 * older userspace that treated a matchset with only the RSSI as the
6024 * global RSSI for all other matchsets - if there are other matchsets.
6025 */
Luciano Coelho256da022014-11-10 16:13:46 +02006026 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006027 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006028 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006029 tmp) {
6030 struct nlattr *rssi;
6031
6032 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6033 nla_data(attr), nla_len(attr),
6034 nl80211_match_policy);
6035 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006036 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006037 /* add other standalone attributes here */
6038 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6039 n_match_sets++;
6040 continue;
6041 }
6042 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6043 if (rssi)
6044 default_match_rssi = nla_get_s32(rssi);
6045 }
6046 }
6047
6048 /* However, if there's no other matchset, add the RSSI one */
6049 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6050 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006051
6052 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006053 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006054
Luciano Coelho256da022014-11-10 16:13:46 +02006055 if (attrs[NL80211_ATTR_IE])
6056 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006057 else
6058 ie_len = 0;
6059
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006060 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006061 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006062
Luciano Coelho807f8a82011-05-11 17:09:35 +03006063 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006064 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006065 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006066 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006067 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006068 if (!request)
6069 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006070
6071 if (n_ssids)
6072 request->ssids = (void *)&request->channels[n_channels];
6073 request->n_ssids = n_ssids;
6074 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006075 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006076 request->ie = (void *)(request->ssids + n_ssids);
6077 else
6078 request->ie = (void *)(request->channels + n_channels);
6079 }
6080
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006081 if (n_match_sets) {
6082 if (request->ie)
6083 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006084 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006085 request->match_sets =
6086 (void *)(request->ssids + n_ssids);
6087 else
6088 request->match_sets =
6089 (void *)(request->channels + n_channels);
6090 }
6091 request->n_match_sets = n_match_sets;
6092
Luciano Coelho807f8a82011-05-11 17:09:35 +03006093 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006094 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006095 /* user specified, bail out if channel not found */
6096 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006097 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006098 tmp) {
6099 struct ieee80211_channel *chan;
6100
6101 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6102
6103 if (!chan) {
6104 err = -EINVAL;
6105 goto out_free;
6106 }
6107
6108 /* ignore disabled channels */
6109 if (chan->flags & IEEE80211_CHAN_DISABLED)
6110 continue;
6111
6112 request->channels[i] = chan;
6113 i++;
6114 }
6115 } else {
6116 /* all channels */
6117 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6118 int j;
6119 if (!wiphy->bands[band])
6120 continue;
6121 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6122 struct ieee80211_channel *chan;
6123
6124 chan = &wiphy->bands[band]->channels[j];
6125
6126 if (chan->flags & IEEE80211_CHAN_DISABLED)
6127 continue;
6128
6129 request->channels[i] = chan;
6130 i++;
6131 }
6132 }
6133 }
6134
6135 if (!i) {
6136 err = -EINVAL;
6137 goto out_free;
6138 }
6139
6140 request->n_channels = i;
6141
6142 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006143 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006144 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006145 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006146 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006147 err = -EINVAL;
6148 goto out_free;
6149 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006150 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006151 memcpy(request->ssids[i].ssid, nla_data(attr),
6152 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006153 i++;
6154 }
6155 }
6156
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006157 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006158 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006159 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006160 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006161 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006162 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006163
Johannes Bergae811e22014-01-24 10:17:47 +01006164 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6165 nla_data(attr), nla_len(attr),
6166 nl80211_match_policy);
6167 if (err)
6168 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006169 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006170 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006171 if (WARN_ON(i >= n_match_sets)) {
6172 /* this indicates a programming error,
6173 * the loop above should have verified
6174 * things properly
6175 */
6176 err = -EINVAL;
6177 goto out_free;
6178 }
6179
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006180 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6181 err = -EINVAL;
6182 goto out_free;
6183 }
6184 memcpy(request->match_sets[i].ssid.ssid,
6185 nla_data(ssid), nla_len(ssid));
6186 request->match_sets[i].ssid.ssid_len =
6187 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006188 /* special attribute - old implemenation w/a */
6189 request->match_sets[i].rssi_thold =
6190 default_match_rssi;
6191 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6192 if (rssi)
6193 request->match_sets[i].rssi_thold =
6194 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006195 }
6196 i++;
6197 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006198
6199 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006200 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006201 request->match_sets[0].rssi_thold = default_match_rssi;
6202
6203 request->min_rssi_thold = INT_MAX;
6204 for (i = 0; i < n_match_sets; i++)
6205 request->min_rssi_thold =
6206 min(request->match_sets[i].rssi_thold,
6207 request->min_rssi_thold);
6208 } else {
6209 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006210 }
6211
Johannes Berg9900e482014-02-04 21:01:25 +01006212 if (ie_len) {
6213 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006214 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006215 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006216 request->ie_len);
6217 }
6218
Luciano Coelho256da022014-11-10 16:13:46 +02006219 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006220 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006221 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006222 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6223 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006224 err = -EOPNOTSUPP;
6225 goto out_free;
6226 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006227
6228 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6229 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6230
6231 if (!wdev) /* must be net-detect */
6232 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6233
6234 if (!(wiphy->features & flg)) {
6235 err = -EOPNOTSUPP;
6236 goto out_free;
6237 }
6238
6239 if (wdev && wdev->current_bss) {
6240 err = -EOPNOTSUPP;
6241 goto out_free;
6242 }
6243
6244 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6245 request->mac_addr_mask);
6246 if (err)
6247 goto out_free;
6248 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006249 }
Sam Lefflered4737712012-10-11 21:03:31 -07006250
Luciano Coelho9c748932015-01-16 16:04:09 +02006251 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6252 request->delay =
6253 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6254
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006255 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006256 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006257
Luciano Coelho256da022014-11-10 16:13:46 +02006258 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006259
6260out_free:
6261 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006262 return ERR_PTR(err);
6263}
6264
6265static int nl80211_start_sched_scan(struct sk_buff *skb,
6266 struct genl_info *info)
6267{
6268 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6269 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006270 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006271 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006272 int err;
6273
6274 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6275 !rdev->ops->sched_scan_start)
6276 return -EOPNOTSUPP;
6277
6278 if (rdev->sched_scan_req)
6279 return -EINPROGRESS;
6280
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006281 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6282 info->attrs);
6283
6284 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006285 if (err)
6286 goto out_err;
6287
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006288 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006289 if (err)
6290 goto out_free;
6291
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006292 sched_scan_req->dev = dev;
6293 sched_scan_req->wiphy = &rdev->wiphy;
6294
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006295 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6296 sched_scan_req->owner_nlportid = info->snd_portid;
6297
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006298 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006299
6300 nl80211_send_sched_scan(rdev, dev,
6301 NL80211_CMD_START_SCHED_SCAN);
6302 return 0;
6303
6304out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006305 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006306out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006307 return err;
6308}
6309
6310static int nl80211_stop_sched_scan(struct sk_buff *skb,
6311 struct genl_info *info)
6312{
6313 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6314
6315 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6316 !rdev->ops->sched_scan_stop)
6317 return -EOPNOTSUPP;
6318
Johannes Berg5fe231e2013-05-08 21:45:15 +02006319 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006320}
6321
Simon Wunderlich04f39042013-02-08 18:16:19 +01006322static int nl80211_start_radar_detection(struct sk_buff *skb,
6323 struct genl_info *info)
6324{
6325 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6326 struct net_device *dev = info->user_ptr[1];
6327 struct wireless_dev *wdev = dev->ieee80211_ptr;
6328 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006329 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006330 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006331 int err;
6332
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006333 dfs_region = reg_get_dfs_region(wdev->wiphy);
6334 if (dfs_region == NL80211_DFS_UNSET)
6335 return -EINVAL;
6336
Simon Wunderlich04f39042013-02-08 18:16:19 +01006337 err = nl80211_parse_chandef(rdev, info, &chandef);
6338 if (err)
6339 return err;
6340
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006341 if (netif_carrier_ok(dev))
6342 return -EBUSY;
6343
Simon Wunderlich04f39042013-02-08 18:16:19 +01006344 if (wdev->cac_started)
6345 return -EBUSY;
6346
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006347 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006348 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006349 if (err < 0)
6350 return err;
6351
6352 if (err == 0)
6353 return -EINVAL;
6354
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006355 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006356 return -EINVAL;
6357
6358 if (!rdev->ops->start_radar_detection)
6359 return -EOPNOTSUPP;
6360
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006361 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6362 if (WARN_ON(!cac_time_ms))
6363 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6364
6365 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6366 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006367 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006368 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006369 wdev->cac_started = true;
6370 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006371 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006372 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006373 return err;
6374}
6375
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006376static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6377{
6378 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6379 struct net_device *dev = info->user_ptr[1];
6380 struct wireless_dev *wdev = dev->ieee80211_ptr;
6381 struct cfg80211_csa_settings params;
6382 /* csa_attrs is defined static to avoid waste of stack size - this
6383 * function is called under RTNL lock, so this should not be a problem.
6384 */
6385 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006386 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006387 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006388 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006389 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006390
6391 if (!rdev->ops->channel_switch ||
6392 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6393 return -EOPNOTSUPP;
6394
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006395 switch (dev->ieee80211_ptr->iftype) {
6396 case NL80211_IFTYPE_AP:
6397 case NL80211_IFTYPE_P2P_GO:
6398 need_new_beacon = true;
6399
6400 /* useless if AP is not running */
6401 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006402 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006403 break;
6404 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006405 if (!wdev->ssid_len)
6406 return -ENOTCONN;
6407 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006408 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006409 if (!wdev->mesh_id_len)
6410 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006411 break;
6412 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006413 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006414 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006415
6416 memset(&params, 0, sizeof(params));
6417
6418 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6419 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6420 return -EINVAL;
6421
6422 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006423 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006424 return -EINVAL;
6425
Luciano Coelho252e07c2014-10-08 09:48:34 +03006426 /* Even though the attribute is u32, the specification says
6427 * u8, so let's make sure we don't overflow.
6428 */
6429 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6430 if (cs_count > 255)
6431 return -EINVAL;
6432
6433 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006434
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006435 if (!need_new_beacon)
6436 goto skip_beacons;
6437
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006438 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6439 if (err)
6440 return err;
6441
6442 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6443 info->attrs[NL80211_ATTR_CSA_IES],
6444 nl80211_policy);
6445 if (err)
6446 return err;
6447
6448 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6449 if (err)
6450 return err;
6451
6452 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6453 return -EINVAL;
6454
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006455 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6456 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006457 return -EINVAL;
6458
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006459 params.n_counter_offsets_beacon = len / sizeof(u16);
6460 if (rdev->wiphy.max_num_csa_counters &&
6461 (params.n_counter_offsets_beacon >
6462 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006463 return -EINVAL;
6464
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006465 params.counter_offsets_beacon =
6466 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6467
6468 /* sanity checks - counters should fit and be the same */
6469 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6470 u16 offset = params.counter_offsets_beacon[i];
6471
6472 if (offset >= params.beacon_csa.tail_len)
6473 return -EINVAL;
6474
6475 if (params.beacon_csa.tail[offset] != params.count)
6476 return -EINVAL;
6477 }
6478
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006479 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006480 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6481 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006482 return -EINVAL;
6483
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006484 params.n_counter_offsets_presp = len / sizeof(u16);
6485 if (rdev->wiphy.max_num_csa_counters &&
6486 (params.n_counter_offsets_beacon >
6487 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006488 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006489
6490 params.counter_offsets_presp =
6491 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6492
6493 /* sanity checks - counters should fit and be the same */
6494 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6495 u16 offset = params.counter_offsets_presp[i];
6496
6497 if (offset >= params.beacon_csa.probe_resp_len)
6498 return -EINVAL;
6499
6500 if (params.beacon_csa.probe_resp[offset] !=
6501 params.count)
6502 return -EINVAL;
6503 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006504 }
6505
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006506skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006507 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6508 if (err)
6509 return err;
6510
Arik Nemtsov923b3522015-07-08 15:41:44 +03006511 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6512 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006513 return -EINVAL;
6514
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006515 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6516 &params.chandef,
6517 wdev->iftype);
6518 if (err < 0)
6519 return err;
6520
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006521 if (err > 0)
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006522 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006523
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006524 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6525 params.block_tx = true;
6526
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006527 wdev_lock(wdev);
6528 err = rdev_channel_switch(rdev, dev, &params);
6529 wdev_unlock(wdev);
6530
6531 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006532}
6533
Johannes Berg9720bb32011-06-21 09:45:33 +02006534static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6535 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006536 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006537 struct wireless_dev *wdev,
6538 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006539{
Johannes Berg48ab9052009-07-10 18:42:31 +02006540 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006541 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006542 void *hdr;
6543 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006544
6545 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006546
Eric W. Biederman15e47302012-09-07 20:12:54 +00006547 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006548 NL80211_CMD_NEW_SCAN_RESULTS);
6549 if (!hdr)
6550 return -1;
6551
Johannes Berg9720bb32011-06-21 09:45:33 +02006552 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6553
Johannes Berg97990a02013-04-19 01:02:55 +02006554 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6555 goto nla_put_failure;
6556 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006557 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6558 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006559 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6560 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006561
6562 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6563 if (!bss)
6564 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006565 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006566 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006567 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006568
6569 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006570 /* indicate whether we have probe response data or not */
6571 if (rcu_access_pointer(res->proberesp_ies) &&
6572 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6573 goto fail_unlock_rcu;
6574
6575 /* this pointer prefers to be pointed to probe response data
6576 * but is always valid
6577 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006578 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006579 if (ies) {
6580 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6581 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006582 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6583 ies->len, ies->data))
6584 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006585 }
Johannes Berg0e227082014-08-12 20:34:30 +02006586
6587 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006588 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006589 if (ies && ies->from_beacon) {
6590 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006591 goto fail_unlock_rcu;
6592 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6593 ies->len, ies->data))
6594 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006595 }
6596 rcu_read_unlock();
6597
David S. Miller9360ffd2012-03-29 04:41:26 -04006598 if (res->beacon_interval &&
6599 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6600 goto nla_put_failure;
6601 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6602 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006603 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006604 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6605 jiffies_to_msecs(jiffies - intbss->ts)))
6606 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006607
Dmitry Shmidt6e19bc42015-10-07 11:32:53 +02006608 if (intbss->ts_boottime &&
6609 nla_put_u64(msg, NL80211_BSS_LAST_SEEN_BOOTTIME,
6610 intbss->ts_boottime))
6611 goto nla_put_failure;
6612
Johannes Berg77965c92009-02-18 18:45:06 +01006613 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006614 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006615 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6616 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006617 break;
6618 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006619 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6620 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006621 break;
6622 default:
6623 break;
6624 }
6625
Johannes Berg48ab9052009-07-10 18:42:31 +02006626 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006627 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006628 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006629 if (intbss == wdev->current_bss &&
6630 nla_put_u32(msg, NL80211_BSS_STATUS,
6631 NL80211_BSS_STATUS_ASSOCIATED))
6632 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006633 break;
6634 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006635 if (intbss == wdev->current_bss &&
6636 nla_put_u32(msg, NL80211_BSS_STATUS,
6637 NL80211_BSS_STATUS_IBSS_JOINED))
6638 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006639 break;
6640 default:
6641 break;
6642 }
6643
Johannes Berg2a519312009-02-10 21:25:55 +01006644 nla_nest_end(msg, bss);
6645
Johannes Berg053c0952015-01-16 22:09:00 +01006646 genlmsg_end(msg, hdr);
6647 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006648
Johannes Berg8cef2c92013-02-05 16:54:31 +01006649 fail_unlock_rcu:
6650 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006651 nla_put_failure:
6652 genlmsg_cancel(msg, hdr);
6653 return -EMSGSIZE;
6654}
6655
Johannes Berg97990a02013-04-19 01:02:55 +02006656static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006657{
Johannes Berg48ab9052009-07-10 18:42:31 +02006658 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006659 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006660 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006661 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006662 int err;
6663
Johannes Berg97990a02013-04-19 01:02:55 +02006664 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006665 if (err)
6666 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006667
Johannes Berg48ab9052009-07-10 18:42:31 +02006668 wdev_lock(wdev);
6669 spin_lock_bh(&rdev->bss_lock);
6670 cfg80211_bss_expire(rdev);
6671
Johannes Berg9720bb32011-06-21 09:45:33 +02006672 cb->seq = rdev->bss_generation;
6673
Johannes Berg48ab9052009-07-10 18:42:31 +02006674 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006675 if (++idx <= start)
6676 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006677 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006678 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006679 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006680 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006681 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006682 }
6683 }
6684
Johannes Berg48ab9052009-07-10 18:42:31 +02006685 spin_unlock_bh(&rdev->bss_lock);
6686 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006687
Johannes Berg97990a02013-04-19 01:02:55 +02006688 cb->args[2] = idx;
6689 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006690
Johannes Berg67748892010-10-04 21:14:06 +02006691 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006692}
6693
Eric W. Biederman15e47302012-09-07 20:12:54 +00006694static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006695 int flags, struct net_device *dev,
6696 bool allow_radio_stats,
6697 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006698{
6699 void *hdr;
6700 struct nlattr *infoattr;
6701
Johannes Berg11f78ac2014-11-14 16:43:50 +01006702 /* skip radio stats if userspace didn't request them */
6703 if (!survey->channel && !allow_radio_stats)
6704 return 0;
6705
Eric W. Biederman15e47302012-09-07 20:12:54 +00006706 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006707 NL80211_CMD_NEW_SURVEY_RESULTS);
6708 if (!hdr)
6709 return -ENOMEM;
6710
David S. Miller9360ffd2012-03-29 04:41:26 -04006711 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6712 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006713
6714 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6715 if (!infoattr)
6716 goto nla_put_failure;
6717
Johannes Berg11f78ac2014-11-14 16:43:50 +01006718 if (survey->channel &&
6719 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006720 survey->channel->center_freq))
6721 goto nla_put_failure;
6722
6723 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6724 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6725 goto nla_put_failure;
6726 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6727 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6728 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006729 if ((survey->filled & SURVEY_INFO_TIME) &&
6730 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6731 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006732 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006733 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6734 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6735 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006736 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006737 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6738 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6739 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006740 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006741 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6742 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6743 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006744 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006745 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6746 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6747 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006748 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006749 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6750 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6751 survey->time_scan))
6752 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006753
6754 nla_nest_end(msg, infoattr);
6755
Johannes Berg053c0952015-01-16 22:09:00 +01006756 genlmsg_end(msg, hdr);
6757 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006758
6759 nla_put_failure:
6760 genlmsg_cancel(msg, hdr);
6761 return -EMSGSIZE;
6762}
6763
Johannes Berg11f78ac2014-11-14 16:43:50 +01006764static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006765{
6766 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006767 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006768 struct wireless_dev *wdev;
6769 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006770 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006771 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006772
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006773 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006774 if (res)
6775 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006776
Johannes Berg11f78ac2014-11-14 16:43:50 +01006777 /* prepare_wdev_dump parsed the attributes */
6778 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6779
Johannes Berg97990a02013-04-19 01:02:55 +02006780 if (!wdev->netdev) {
6781 res = -EINVAL;
6782 goto out_err;
6783 }
6784
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006785 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006786 res = -EOPNOTSUPP;
6787 goto out_err;
6788 }
6789
6790 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006791 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006792 if (res == -ENOENT)
6793 break;
6794 if (res)
6795 goto out_err;
6796
Johannes Berg11f78ac2014-11-14 16:43:50 +01006797 /* don't send disabled channels, but do send non-channel data */
6798 if (survey.channel &&
6799 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006800 survey_idx++;
6801 continue;
6802 }
6803
Holger Schurig61fa7132009-11-11 12:25:40 +01006804 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006805 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006806 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006807 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006808 goto out;
6809 survey_idx++;
6810 }
6811
6812 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006813 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006814 res = skb->len;
6815 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006816 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006817 return res;
6818}
6819
Samuel Ortizb23aa672009-07-01 21:26:54 +02006820static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6821{
6822 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6823 NL80211_WPA_VERSION_2));
6824}
6825
Jouni Malinen636a5d32009-03-19 13:39:22 +02006826static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6827{
Johannes Berg4c476992010-10-04 21:36:35 +02006828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6829 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006830 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006831 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6832 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006833 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006834 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006835 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006836
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006837 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6838 return -EINVAL;
6839
6840 if (!info->attrs[NL80211_ATTR_MAC])
6841 return -EINVAL;
6842
Jouni Malinen17780922009-03-27 20:52:47 +02006843 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6844 return -EINVAL;
6845
Johannes Berg19957bb2009-07-02 17:20:43 +02006846 if (!info->attrs[NL80211_ATTR_SSID])
6847 return -EINVAL;
6848
6849 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6850 return -EINVAL;
6851
Johannes Bergfffd0932009-07-08 14:22:54 +02006852 err = nl80211_parse_key(info, &key);
6853 if (err)
6854 return err;
6855
6856 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006857 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6858 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006859 if (!key.p.key || !key.p.key_len)
6860 return -EINVAL;
6861 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6862 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6863 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6864 key.p.key_len != WLAN_KEY_LEN_WEP104))
6865 return -EINVAL;
6866 if (key.idx > 4)
6867 return -EINVAL;
6868 } else {
6869 key.p.key_len = 0;
6870 key.p.key = NULL;
6871 }
6872
Johannes Bergafea0b72010-08-10 09:46:42 +02006873 if (key.idx >= 0) {
6874 int i;
6875 bool ok = false;
6876 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6877 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6878 ok = true;
6879 break;
6880 }
6881 }
Johannes Berg4c476992010-10-04 21:36:35 +02006882 if (!ok)
6883 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006884 }
6885
Johannes Berg4c476992010-10-04 21:36:35 +02006886 if (!rdev->ops->auth)
6887 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006888
Johannes Berg074ac8d2010-09-16 14:58:22 +02006889 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006890 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6891 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006892
Johannes Berg19957bb2009-07-02 17:20:43 +02006893 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006894 chan = nl80211_get_valid_chan(&rdev->wiphy,
6895 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6896 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006897 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006898
Johannes Berg19957bb2009-07-02 17:20:43 +02006899 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6900 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6901
6902 if (info->attrs[NL80211_ATTR_IE]) {
6903 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6904 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6905 }
6906
6907 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006908 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006909 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006910
Jouni Malinene39e5b52012-09-30 19:29:39 +03006911 if (auth_type == NL80211_AUTHTYPE_SAE &&
6912 !info->attrs[NL80211_ATTR_SAE_DATA])
6913 return -EINVAL;
6914
6915 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6916 if (auth_type != NL80211_AUTHTYPE_SAE)
6917 return -EINVAL;
6918 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6919 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6920 /* need to include at least Auth Transaction and Status Code */
6921 if (sae_data_len < 4)
6922 return -EINVAL;
6923 }
6924
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006925 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6926
Johannes Berg95de8172012-01-20 13:55:25 +01006927 /*
6928 * Since we no longer track auth state, ignore
6929 * requests to only change local state.
6930 */
6931 if (local_state_change)
6932 return 0;
6933
Johannes Berg91bf9b22013-05-15 17:44:01 +02006934 wdev_lock(dev->ieee80211_ptr);
6935 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6936 ssid, ssid_len, ie, ie_len,
6937 key.p.key, key.p.key_len, key.idx,
6938 sae_data, sae_data_len);
6939 wdev_unlock(dev->ieee80211_ptr);
6940 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006941}
6942
Johannes Bergc0692b82010-08-27 14:26:53 +03006943static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6944 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006945 struct cfg80211_crypto_settings *settings,
6946 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006947{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006948 memset(settings, 0, sizeof(*settings));
6949
Samuel Ortizb23aa672009-07-01 21:26:54 +02006950 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6951
Johannes Bergc0692b82010-08-27 14:26:53 +03006952 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6953 u16 proto;
6954 proto = nla_get_u16(
6955 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6956 settings->control_port_ethertype = cpu_to_be16(proto);
6957 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6958 proto != ETH_P_PAE)
6959 return -EINVAL;
6960 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6961 settings->control_port_no_encrypt = true;
6962 } else
6963 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6964
Samuel Ortizb23aa672009-07-01 21:26:54 +02006965 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6966 void *data;
6967 int len, i;
6968
6969 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6970 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6971 settings->n_ciphers_pairwise = len / sizeof(u32);
6972
6973 if (len % sizeof(u32))
6974 return -EINVAL;
6975
Johannes Berg3dc27d22009-07-02 21:36:37 +02006976 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006977 return -EINVAL;
6978
6979 memcpy(settings->ciphers_pairwise, data, len);
6980
6981 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006982 if (!cfg80211_supported_cipher_suite(
6983 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006984 settings->ciphers_pairwise[i]))
6985 return -EINVAL;
6986 }
6987
6988 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6989 settings->cipher_group =
6990 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006991 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6992 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006993 return -EINVAL;
6994 }
6995
6996 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6997 settings->wpa_versions =
6998 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6999 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
7000 return -EINVAL;
7001 }
7002
7003 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
7004 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03007005 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007006
7007 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
7008 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
7009 settings->n_akm_suites = len / sizeof(u32);
7010
7011 if (len % sizeof(u32))
7012 return -EINVAL;
7013
Jouni Malinen1b9ca022011-09-21 16:13:07 +03007014 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
7015 return -EINVAL;
7016
Samuel Ortizb23aa672009-07-01 21:26:54 +02007017 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007018 }
7019
7020 return 0;
7021}
7022
Jouni Malinen636a5d32009-03-19 13:39:22 +02007023static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7024{
Johannes Berg4c476992010-10-04 21:36:35 +02007025 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7026 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007027 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007028 struct cfg80211_assoc_request req = {};
7029 const u8 *bssid, *ssid;
7030 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007031
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007032 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7033 return -EINVAL;
7034
7035 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007036 !info->attrs[NL80211_ATTR_SSID] ||
7037 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007038 return -EINVAL;
7039
Johannes Berg4c476992010-10-04 21:36:35 +02007040 if (!rdev->ops->assoc)
7041 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007042
Johannes Berg074ac8d2010-09-16 14:58:22 +02007043 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007044 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7045 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007046
Johannes Berg19957bb2009-07-02 17:20:43 +02007047 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007048
Jouni Malinen664834d2014-01-15 00:01:44 +02007049 chan = nl80211_get_valid_chan(&rdev->wiphy,
7050 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7051 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007052 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007053
Johannes Berg19957bb2009-07-02 17:20:43 +02007054 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7055 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007056
7057 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007058 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7059 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007060 }
7061
Jouni Malinendc6382c2009-05-06 22:09:37 +03007062 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007063 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007064 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007065 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007066 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007067 else if (mfp != NL80211_MFP_NO)
7068 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007069 }
7070
Johannes Berg3e5d7642009-07-07 14:37:26 +02007071 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007072 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007073
Ben Greear7e7c8922011-11-18 11:31:59 -08007074 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007075 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007076
7077 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007078 memcpy(&req.ht_capa_mask,
7079 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7080 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007081
7082 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007083 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007084 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007085 memcpy(&req.ht_capa,
7086 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7087 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007088 }
7089
Johannes Bergee2aca32013-02-21 17:36:01 +01007090 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007091 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007092
7093 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007094 memcpy(&req.vht_capa_mask,
7095 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7096 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007097
7098 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007099 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007100 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007101 memcpy(&req.vht_capa,
7102 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7103 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007104 }
7105
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007106 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7107 if (!(rdev->wiphy.features &
7108 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7109 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7110 return -EINVAL;
7111 req.flags |= ASSOC_REQ_USE_RRM;
7112 }
7113
Johannes Bergf62fab72013-02-21 20:09:09 +01007114 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007115 if (!err) {
7116 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007117 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7118 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007119 wdev_unlock(dev->ieee80211_ptr);
7120 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007121
Jouni Malinen636a5d32009-03-19 13:39:22 +02007122 return err;
7123}
7124
7125static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7126{
Johannes Berg4c476992010-10-04 21:36:35 +02007127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7128 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007129 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007130 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007131 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007132 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007133
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007134 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7135 return -EINVAL;
7136
7137 if (!info->attrs[NL80211_ATTR_MAC])
7138 return -EINVAL;
7139
7140 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7141 return -EINVAL;
7142
Johannes Berg4c476992010-10-04 21:36:35 +02007143 if (!rdev->ops->deauth)
7144 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007145
Johannes Berg074ac8d2010-09-16 14:58:22 +02007146 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007147 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7148 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007149
Johannes Berg19957bb2009-07-02 17:20:43 +02007150 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007151
Johannes Berg19957bb2009-07-02 17:20:43 +02007152 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7153 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007154 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007155 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007156 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007157
7158 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007159 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7160 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007161 }
7162
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007163 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7164
Johannes Berg91bf9b22013-05-15 17:44:01 +02007165 wdev_lock(dev->ieee80211_ptr);
7166 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7167 local_state_change);
7168 wdev_unlock(dev->ieee80211_ptr);
7169 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007170}
7171
7172static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7173{
Johannes Berg4c476992010-10-04 21:36:35 +02007174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7175 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007176 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007177 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007178 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007179 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007180
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007181 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7182 return -EINVAL;
7183
7184 if (!info->attrs[NL80211_ATTR_MAC])
7185 return -EINVAL;
7186
7187 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7188 return -EINVAL;
7189
Johannes Berg4c476992010-10-04 21:36:35 +02007190 if (!rdev->ops->disassoc)
7191 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007192
Johannes Berg074ac8d2010-09-16 14:58:22 +02007193 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007194 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7195 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007196
Johannes Berg19957bb2009-07-02 17:20:43 +02007197 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007198
Johannes Berg19957bb2009-07-02 17:20:43 +02007199 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7200 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007201 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007202 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007203 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007204
7205 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007206 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7207 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007208 }
7209
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007210 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7211
Johannes Berg91bf9b22013-05-15 17:44:01 +02007212 wdev_lock(dev->ieee80211_ptr);
7213 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7214 local_state_change);
7215 wdev_unlock(dev->ieee80211_ptr);
7216 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007217}
7218
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007219static bool
7220nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7221 int mcast_rate[IEEE80211_NUM_BANDS],
7222 int rateval)
7223{
7224 struct wiphy *wiphy = &rdev->wiphy;
7225 bool found = false;
7226 int band, i;
7227
7228 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7229 struct ieee80211_supported_band *sband;
7230
7231 sband = wiphy->bands[band];
7232 if (!sband)
7233 continue;
7234
7235 for (i = 0; i < sband->n_bitrates; i++) {
7236 if (sband->bitrates[i].bitrate == rateval) {
7237 mcast_rate[band] = i + 1;
7238 found = true;
7239 break;
7240 }
7241 }
7242 }
7243
7244 return found;
7245}
7246
Johannes Berg04a773a2009-04-19 21:24:32 +02007247static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7248{
Johannes Berg4c476992010-10-04 21:36:35 +02007249 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7250 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007251 struct cfg80211_ibss_params ibss;
7252 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007253 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007254 int err;
7255
Johannes Berg8e30bc52009-04-22 17:45:38 +02007256 memset(&ibss, 0, sizeof(ibss));
7257
Johannes Berg04a773a2009-04-19 21:24:32 +02007258 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7259 return -EINVAL;
7260
Johannes Berg683b6d32012-11-08 21:25:48 +01007261 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007262 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7263 return -EINVAL;
7264
Johannes Berg8e30bc52009-04-22 17:45:38 +02007265 ibss.beacon_interval = 100;
7266
7267 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7268 ibss.beacon_interval =
7269 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7270 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7271 return -EINVAL;
7272 }
7273
Johannes Berg4c476992010-10-04 21:36:35 +02007274 if (!rdev->ops->join_ibss)
7275 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007276
Johannes Berg4c476992010-10-04 21:36:35 +02007277 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7278 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007279
Johannes Berg79c97e92009-07-07 03:56:12 +02007280 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007281
Johannes Berg39193492011-09-16 13:45:25 +02007282 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007283 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007284
7285 if (!is_valid_ether_addr(ibss.bssid))
7286 return -EINVAL;
7287 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007288 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7289 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7290
7291 if (info->attrs[NL80211_ATTR_IE]) {
7292 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7293 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7294 }
7295
Johannes Berg683b6d32012-11-08 21:25:48 +01007296 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7297 if (err)
7298 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007299
Ilan Peer174e0cd2014-02-23 09:13:01 +02007300 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7301 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007302 return -EINVAL;
7303
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007304 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007305 case NL80211_CHAN_WIDTH_5:
7306 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007307 case NL80211_CHAN_WIDTH_20_NOHT:
7308 break;
7309 case NL80211_CHAN_WIDTH_20:
7310 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007311 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7312 return -EINVAL;
7313 break;
7314 case NL80211_CHAN_WIDTH_80:
7315 case NL80211_CHAN_WIDTH_80P80:
7316 case NL80211_CHAN_WIDTH_160:
7317 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7318 return -EINVAL;
7319 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7320 NL80211_EXT_FEATURE_VHT_IBSS))
7321 return -EINVAL;
7322 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007323 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007324 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007325 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007326
Johannes Berg04a773a2009-04-19 21:24:32 +02007327 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007328 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007329
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007330 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7331 u8 *rates =
7332 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7333 int n_rates =
7334 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7335 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007336 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007337
Johannes Berg34850ab2011-07-18 18:08:35 +02007338 err = ieee80211_get_ratemask(sband, rates, n_rates,
7339 &ibss.basic_rates);
7340 if (err)
7341 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007342 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007343
Simon Wunderlich803768f2013-06-28 10:39:58 +02007344 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7345 memcpy(&ibss.ht_capa_mask,
7346 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7347 sizeof(ibss.ht_capa_mask));
7348
7349 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7350 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7351 return -EINVAL;
7352 memcpy(&ibss.ht_capa,
7353 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7354 sizeof(ibss.ht_capa));
7355 }
7356
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007357 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7358 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7359 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7360 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007361
Johannes Berg4c476992010-10-04 21:36:35 +02007362 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307363 bool no_ht = false;
7364
Johannes Berg4c476992010-10-04 21:36:35 +02007365 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307366 info->attrs[NL80211_ATTR_KEYS],
7367 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007368 if (IS_ERR(connkeys))
7369 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307370
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007371 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7372 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307373 kfree(connkeys);
7374 return -EINVAL;
7375 }
Johannes Berg4c476992010-10-04 21:36:35 +02007376 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007377
Antonio Quartulli267335d2012-01-31 20:25:47 +01007378 ibss.control_port =
7379 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7380
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007381 ibss.userspace_handles_dfs =
7382 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7383
Johannes Berg4c476992010-10-04 21:36:35 +02007384 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007385 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007386 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007387 return err;
7388}
7389
7390static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7391{
Johannes Berg4c476992010-10-04 21:36:35 +02007392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7393 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007394
Johannes Berg4c476992010-10-04 21:36:35 +02007395 if (!rdev->ops->leave_ibss)
7396 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007397
Johannes Berg4c476992010-10-04 21:36:35 +02007398 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7399 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007400
Johannes Berg4c476992010-10-04 21:36:35 +02007401 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007402}
7403
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007404static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7405{
7406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7407 struct net_device *dev = info->user_ptr[1];
7408 int mcast_rate[IEEE80211_NUM_BANDS];
7409 u32 nla_rate;
7410 int err;
7411
7412 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007413 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7414 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007415 return -EOPNOTSUPP;
7416
7417 if (!rdev->ops->set_mcast_rate)
7418 return -EOPNOTSUPP;
7419
7420 memset(mcast_rate, 0, sizeof(mcast_rate));
7421
7422 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7423 return -EINVAL;
7424
7425 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7426 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7427 return -EINVAL;
7428
7429 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7430
7431 return err;
7432}
7433
Johannes Bergad7e7182013-11-13 13:37:47 +01007434static struct sk_buff *
7435__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007436 struct wireless_dev *wdev, int approxlen,
7437 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007438 enum nl80211_attrs attr,
7439 const struct nl80211_vendor_cmd_info *info,
7440 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007441{
7442 struct sk_buff *skb;
7443 void *hdr;
7444 struct nlattr *data;
7445
7446 skb = nlmsg_new(approxlen + 100, gfp);
7447 if (!skb)
7448 return NULL;
7449
7450 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7451 if (!hdr) {
7452 kfree_skb(skb);
7453 return NULL;
7454 }
7455
7456 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7457 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007458
7459 if (info) {
7460 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7461 info->vendor_id))
7462 goto nla_put_failure;
7463 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7464 info->subcmd))
7465 goto nla_put_failure;
7466 }
7467
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007468 if (wdev) {
7469 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7470 wdev_id(wdev)))
7471 goto nla_put_failure;
7472 if (wdev->netdev &&
7473 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7474 wdev->netdev->ifindex))
7475 goto nla_put_failure;
7476 }
7477
Johannes Bergad7e7182013-11-13 13:37:47 +01007478 data = nla_nest_start(skb, attr);
7479
7480 ((void **)skb->cb)[0] = rdev;
7481 ((void **)skb->cb)[1] = hdr;
7482 ((void **)skb->cb)[2] = data;
7483
7484 return skb;
7485
7486 nla_put_failure:
7487 kfree_skb(skb);
7488 return NULL;
7489}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007490
Johannes Berge03ad6e2014-01-01 17:22:30 +01007491struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007492 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007493 enum nl80211_commands cmd,
7494 enum nl80211_attrs attr,
7495 int vendor_event_idx,
7496 int approxlen, gfp_t gfp)
7497{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007498 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007499 const struct nl80211_vendor_cmd_info *info;
7500
7501 switch (cmd) {
7502 case NL80211_CMD_TESTMODE:
7503 if (WARN_ON(vendor_event_idx != -1))
7504 return NULL;
7505 info = NULL;
7506 break;
7507 case NL80211_CMD_VENDOR:
7508 if (WARN_ON(vendor_event_idx < 0 ||
7509 vendor_event_idx >= wiphy->n_vendor_events))
7510 return NULL;
7511 info = &wiphy->vendor_events[vendor_event_idx];
7512 break;
7513 default:
7514 WARN_ON(1);
7515 return NULL;
7516 }
7517
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007518 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007519 cmd, attr, info, gfp);
7520}
7521EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7522
7523void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7524{
7525 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7526 void *hdr = ((void **)skb->cb)[1];
7527 struct nlattr *data = ((void **)skb->cb)[2];
7528 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7529
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007530 /* clear CB data for netlink core to own from now on */
7531 memset(skb->cb, 0, sizeof(skb->cb));
7532
Johannes Berge03ad6e2014-01-01 17:22:30 +01007533 nla_nest_end(skb, data);
7534 genlmsg_end(skb, hdr);
7535
7536 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7537 mcgrp = NL80211_MCGRP_VENDOR;
7538
7539 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7540 mcgrp, gfp);
7541}
7542EXPORT_SYMBOL(__cfg80211_send_event_skb);
7543
Johannes Bergaff89a92009-07-01 21:26:51 +02007544#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007545static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7546{
Johannes Berg4c476992010-10-04 21:36:35 +02007547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007548 struct wireless_dev *wdev =
7549 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007550 int err;
7551
David Spinadelfc73f112013-07-31 18:04:15 +03007552 if (!rdev->ops->testmode_cmd)
7553 return -EOPNOTSUPP;
7554
7555 if (IS_ERR(wdev)) {
7556 err = PTR_ERR(wdev);
7557 if (err != -EINVAL)
7558 return err;
7559 wdev = NULL;
7560 } else if (wdev->wiphy != &rdev->wiphy) {
7561 return -EINVAL;
7562 }
7563
Johannes Bergaff89a92009-07-01 21:26:51 +02007564 if (!info->attrs[NL80211_ATTR_TESTDATA])
7565 return -EINVAL;
7566
Johannes Bergad7e7182013-11-13 13:37:47 +01007567 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007568 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007569 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7570 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007571 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007572
Johannes Bergaff89a92009-07-01 21:26:51 +02007573 return err;
7574}
7575
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007576static int nl80211_testmode_dump(struct sk_buff *skb,
7577 struct netlink_callback *cb)
7578{
Johannes Berg00918d32011-12-13 17:22:05 +01007579 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007580 int err;
7581 long phy_idx;
7582 void *data = NULL;
7583 int data_len = 0;
7584
Johannes Berg5fe231e2013-05-08 21:45:15 +02007585 rtnl_lock();
7586
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007587 if (cb->args[0]) {
7588 /*
7589 * 0 is a valid index, but not valid for args[0],
7590 * so we need to offset by 1.
7591 */
7592 phy_idx = cb->args[0] - 1;
7593 } else {
7594 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7595 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7596 nl80211_policy);
7597 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007598 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007599
Johannes Berg2bd7e352012-06-15 14:23:16 +02007600 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7601 nl80211_fam.attrbuf);
7602 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007603 err = PTR_ERR(rdev);
7604 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007605 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007606 phy_idx = rdev->wiphy_idx;
7607 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007608
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007609 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7610 cb->args[1] =
7611 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7612 }
7613
7614 if (cb->args[1]) {
7615 data = nla_data((void *)cb->args[1]);
7616 data_len = nla_len((void *)cb->args[1]);
7617 }
7618
Johannes Berg00918d32011-12-13 17:22:05 +01007619 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7620 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007621 err = -ENOENT;
7622 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007623 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007624
Johannes Berg00918d32011-12-13 17:22:05 +01007625 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007626 err = -EOPNOTSUPP;
7627 goto out_err;
7628 }
7629
7630 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007631 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007632 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7633 NL80211_CMD_TESTMODE);
7634 struct nlattr *tmdata;
7635
Dan Carpentercb35fba2013-08-14 14:50:01 +03007636 if (!hdr)
7637 break;
7638
David S. Miller9360ffd2012-03-29 04:41:26 -04007639 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007640 genlmsg_cancel(skb, hdr);
7641 break;
7642 }
7643
7644 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7645 if (!tmdata) {
7646 genlmsg_cancel(skb, hdr);
7647 break;
7648 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007649 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007650 nla_nest_end(skb, tmdata);
7651
7652 if (err == -ENOBUFS || err == -ENOENT) {
7653 genlmsg_cancel(skb, hdr);
7654 break;
7655 } else if (err) {
7656 genlmsg_cancel(skb, hdr);
7657 goto out_err;
7658 }
7659
7660 genlmsg_end(skb, hdr);
7661 }
7662
7663 err = skb->len;
7664 /* see above */
7665 cb->args[0] = phy_idx + 1;
7666 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007667 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007668 return err;
7669}
Johannes Bergaff89a92009-07-01 21:26:51 +02007670#endif
7671
Samuel Ortizb23aa672009-07-01 21:26:54 +02007672static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7673{
Johannes Berg4c476992010-10-04 21:36:35 +02007674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7675 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007676 struct cfg80211_connect_params connect;
7677 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007678 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007679 int err;
7680
7681 memset(&connect, 0, sizeof(connect));
7682
7683 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7684 return -EINVAL;
7685
7686 if (!info->attrs[NL80211_ATTR_SSID] ||
7687 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7688 return -EINVAL;
7689
7690 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7691 connect.auth_type =
7692 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007693 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7694 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007695 return -EINVAL;
7696 } else
7697 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7698
7699 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7700
Johannes Bergc0692b82010-08-27 14:26:53 +03007701 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007702 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007703 if (err)
7704 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007705
Johannes Berg074ac8d2010-09-16 14:58:22 +02007706 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007707 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7708 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007709
Johannes Berg79c97e92009-07-07 03:56:12 +02007710 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007711
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307712 connect.bg_scan_period = -1;
7713 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7714 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7715 connect.bg_scan_period =
7716 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7717 }
7718
Samuel Ortizb23aa672009-07-01 21:26:54 +02007719 if (info->attrs[NL80211_ATTR_MAC])
7720 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007721 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7722 connect.bssid_hint =
7723 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007724 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7725 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7726
7727 if (info->attrs[NL80211_ATTR_IE]) {
7728 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7729 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7730 }
7731
Jouni Malinencee00a92013-01-15 17:15:57 +02007732 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7733 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7734 if (connect.mfp != NL80211_MFP_REQUIRED &&
7735 connect.mfp != NL80211_MFP_NO)
7736 return -EINVAL;
7737 } else {
7738 connect.mfp = NL80211_MFP_NO;
7739 }
7740
Samuel Ortizb23aa672009-07-01 21:26:54 +02007741 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007742 connect.channel = nl80211_get_valid_chan(
7743 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7744 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007745 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007746 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007747 connect.channel_hint = nl80211_get_valid_chan(
7748 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7749 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007750 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007751 }
7752
Johannes Bergfffd0932009-07-08 14:22:54 +02007753 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7754 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307755 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007756 if (IS_ERR(connkeys))
7757 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007758 }
7759
Ben Greear7e7c8922011-11-18 11:31:59 -08007760 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7761 connect.flags |= ASSOC_REQ_DISABLE_HT;
7762
7763 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7764 memcpy(&connect.ht_capa_mask,
7765 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7766 sizeof(connect.ht_capa_mask));
7767
7768 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007769 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007770 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007771 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007772 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007773 memcpy(&connect.ht_capa,
7774 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7775 sizeof(connect.ht_capa));
7776 }
7777
Johannes Bergee2aca32013-02-21 17:36:01 +01007778 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7779 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7780
7781 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7782 memcpy(&connect.vht_capa_mask,
7783 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7784 sizeof(connect.vht_capa_mask));
7785
7786 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7787 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007788 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007789 return -EINVAL;
7790 }
7791 memcpy(&connect.vht_capa,
7792 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7793 sizeof(connect.vht_capa));
7794 }
7795
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007796 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7797 if (!(rdev->wiphy.features &
7798 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7799 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7800 return -EINVAL;
7801 connect.flags |= ASSOC_REQ_USE_RRM;
7802 }
7803
Johannes Berg83739b02013-05-15 17:44:01 +02007804 wdev_lock(dev->ieee80211_ptr);
7805 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7806 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007807 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007808 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007809 return err;
7810}
7811
7812static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7813{
Johannes Berg4c476992010-10-04 21:36:35 +02007814 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7815 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007816 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007817 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007818
7819 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7820 reason = WLAN_REASON_DEAUTH_LEAVING;
7821 else
7822 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7823
7824 if (reason == 0)
7825 return -EINVAL;
7826
Johannes Berg074ac8d2010-09-16 14:58:22 +02007827 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007828 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7829 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007830
Johannes Berg83739b02013-05-15 17:44:01 +02007831 wdev_lock(dev->ieee80211_ptr);
7832 ret = cfg80211_disconnect(rdev, dev, reason, true);
7833 wdev_unlock(dev->ieee80211_ptr);
7834 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007835}
7836
Johannes Berg463d0182009-07-14 00:33:35 +02007837static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7838{
Johannes Berg4c476992010-10-04 21:36:35 +02007839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007840 struct net *net;
7841 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007842
Vadim Kochan4b681c82015-01-12 16:34:05 +02007843 if (info->attrs[NL80211_ATTR_PID]) {
7844 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7845
7846 net = get_net_ns_by_pid(pid);
7847 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7848 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7849
7850 net = get_net_ns_by_fd(fd);
7851 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007852 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007853 }
Johannes Berg463d0182009-07-14 00:33:35 +02007854
Johannes Berg4c476992010-10-04 21:36:35 +02007855 if (IS_ERR(net))
7856 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007857
7858 err = 0;
7859
7860 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007861 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7862 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007863
Johannes Berg463d0182009-07-14 00:33:35 +02007864 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007865 return err;
7866}
7867
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007868static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7869{
Johannes Berg4c476992010-10-04 21:36:35 +02007870 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007871 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7872 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007873 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007874 struct cfg80211_pmksa pmksa;
7875
7876 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7877
7878 if (!info->attrs[NL80211_ATTR_MAC])
7879 return -EINVAL;
7880
7881 if (!info->attrs[NL80211_ATTR_PMKID])
7882 return -EINVAL;
7883
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007884 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7885 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7886
Johannes Berg074ac8d2010-09-16 14:58:22 +02007887 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007888 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7889 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007890
7891 switch (info->genlhdr->cmd) {
7892 case NL80211_CMD_SET_PMKSA:
7893 rdev_ops = rdev->ops->set_pmksa;
7894 break;
7895 case NL80211_CMD_DEL_PMKSA:
7896 rdev_ops = rdev->ops->del_pmksa;
7897 break;
7898 default:
7899 WARN_ON(1);
7900 break;
7901 }
7902
Johannes Berg4c476992010-10-04 21:36:35 +02007903 if (!rdev_ops)
7904 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007905
Johannes Berg4c476992010-10-04 21:36:35 +02007906 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007907}
7908
7909static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7910{
Johannes Berg4c476992010-10-04 21:36:35 +02007911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7912 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007913
Johannes Berg074ac8d2010-09-16 14:58:22 +02007914 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007915 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7916 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007917
Johannes Berg4c476992010-10-04 21:36:35 +02007918 if (!rdev->ops->flush_pmksa)
7919 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007920
Hila Gonene35e4d22012-06-27 17:19:42 +03007921 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007922}
7923
Arik Nemtsov109086c2011-09-28 14:12:50 +03007924static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7925{
7926 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7927 struct net_device *dev = info->user_ptr[1];
7928 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307929 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007930 u16 status_code;
7931 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007932 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007933
7934 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7935 !rdev->ops->tdls_mgmt)
7936 return -EOPNOTSUPP;
7937
7938 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7939 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7940 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7941 !info->attrs[NL80211_ATTR_IE] ||
7942 !info->attrs[NL80211_ATTR_MAC])
7943 return -EINVAL;
7944
7945 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7946 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7947 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7948 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007949 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307950 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7951 peer_capability =
7952 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007953
Hila Gonene35e4d22012-06-27 17:19:42 +03007954 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307955 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007956 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007957 nla_data(info->attrs[NL80211_ATTR_IE]),
7958 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007959}
7960
7961static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7962{
7963 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7964 struct net_device *dev = info->user_ptr[1];
7965 enum nl80211_tdls_operation operation;
7966 u8 *peer;
7967
7968 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7969 !rdev->ops->tdls_oper)
7970 return -EOPNOTSUPP;
7971
7972 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7973 !info->attrs[NL80211_ATTR_MAC])
7974 return -EINVAL;
7975
7976 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7977 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7978
Hila Gonene35e4d22012-06-27 17:19:42 +03007979 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007980}
7981
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007982static int nl80211_remain_on_channel(struct sk_buff *skb,
7983 struct genl_info *info)
7984{
Johannes Berg4c476992010-10-04 21:36:35 +02007985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007986 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007987 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007988 struct sk_buff *msg;
7989 void *hdr;
7990 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007991 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007992 int err;
7993
7994 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7995 !info->attrs[NL80211_ATTR_DURATION])
7996 return -EINVAL;
7997
7998 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7999
Johannes Berg7c4ef712011-11-18 15:33:48 +01008000 if (!rdev->ops->remain_on_channel ||
8001 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02008002 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008003
Johannes Bergebf348f2012-06-01 12:50:54 +02008004 /*
8005 * We should be on that channel for at least a minimum amount of
8006 * time (10ms) but no longer than the driver supports.
8007 */
8008 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8009 duration > rdev->wiphy.max_remain_on_channel_duration)
8010 return -EINVAL;
8011
Johannes Berg683b6d32012-11-08 21:25:48 +01008012 err = nl80211_parse_chandef(rdev, info, &chandef);
8013 if (err)
8014 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008015
8016 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008017 if (!msg)
8018 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008019
Eric W. Biederman15e47302012-09-07 20:12:54 +00008020 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008021 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008022 if (!hdr) {
8023 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008024 goto free_msg;
8025 }
8026
Johannes Berg683b6d32012-11-08 21:25:48 +01008027 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8028 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008029
8030 if (err)
8031 goto free_msg;
8032
David S. Miller9360ffd2012-03-29 04:41:26 -04008033 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8034 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008035
8036 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008037
8038 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008039
8040 nla_put_failure:
8041 err = -ENOBUFS;
8042 free_msg:
8043 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008044 return err;
8045}
8046
8047static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8048 struct genl_info *info)
8049{
Johannes Berg4c476992010-10-04 21:36:35 +02008050 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008051 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008052 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008053
8054 if (!info->attrs[NL80211_ATTR_COOKIE])
8055 return -EINVAL;
8056
Johannes Berg4c476992010-10-04 21:36:35 +02008057 if (!rdev->ops->cancel_remain_on_channel)
8058 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008059
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008060 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8061
Hila Gonene35e4d22012-06-27 17:19:42 +03008062 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008063}
8064
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008065static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8066 u8 *rates, u8 rates_len)
8067{
8068 u8 i;
8069 u32 mask = 0;
8070
8071 for (i = 0; i < rates_len; i++) {
8072 int rate = (rates[i] & 0x7f) * 5;
8073 int ridx;
8074 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8075 struct ieee80211_rate *srate =
8076 &sband->bitrates[ridx];
8077 if (rate == srate->bitrate) {
8078 mask |= 1 << ridx;
8079 break;
8080 }
8081 }
8082 if (ridx == sband->n_bitrates)
8083 return 0; /* rate not found */
8084 }
8085
8086 return mask;
8087}
8088
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008089static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8090 u8 *rates, u8 rates_len,
8091 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8092{
8093 u8 i;
8094
8095 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8096
8097 for (i = 0; i < rates_len; i++) {
8098 int ridx, rbit;
8099
8100 ridx = rates[i] / 8;
8101 rbit = BIT(rates[i] % 8);
8102
8103 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008104 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008105 return false;
8106
8107 /* check availability */
8108 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8109 mcs[ridx] |= rbit;
8110 else
8111 return false;
8112 }
8113
8114 return true;
8115}
8116
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008117static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8118{
8119 u16 mcs_mask = 0;
8120
8121 switch (vht_mcs_map) {
8122 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8123 break;
8124 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8125 mcs_mask = 0x00FF;
8126 break;
8127 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8128 mcs_mask = 0x01FF;
8129 break;
8130 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8131 mcs_mask = 0x03FF;
8132 break;
8133 default:
8134 break;
8135 }
8136
8137 return mcs_mask;
8138}
8139
8140static void vht_build_mcs_mask(u16 vht_mcs_map,
8141 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8142{
8143 u8 nss;
8144
8145 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8146 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8147 vht_mcs_map >>= 2;
8148 }
8149}
8150
8151static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8152 struct nl80211_txrate_vht *txrate,
8153 u16 mcs[NL80211_VHT_NSS_MAX])
8154{
8155 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8156 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8157 u8 i;
8158
8159 if (!sband->vht_cap.vht_supported)
8160 return false;
8161
8162 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8163
8164 /* Build vht_mcs_mask from VHT capabilities */
8165 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8166
8167 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8168 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8169 mcs[i] = txrate->mcs[i];
8170 else
8171 return false;
8172 }
8173
8174 return true;
8175}
8176
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008177static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008178 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8179 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008180 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8181 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008182 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008183 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008184};
8185
8186static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8187 struct genl_info *info)
8188{
8189 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008190 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008191 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008192 int rem, i;
8193 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008194 struct nlattr *tx_rates;
8195 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008196 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008197
Johannes Berg4c476992010-10-04 21:36:35 +02008198 if (!rdev->ops->set_bitrate_mask)
8199 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008200
8201 memset(&mask, 0, sizeof(mask));
8202 /* Default to all rates enabled */
8203 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8204 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008205
8206 if (!sband)
8207 continue;
8208
8209 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008210 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008211 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008212 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008213
8214 if (!sband->vht_cap.vht_supported)
8215 continue;
8216
8217 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8218 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008219 }
8220
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008221 /* if no rates are given set it back to the defaults */
8222 if (!info->attrs[NL80211_ATTR_TX_RATES])
8223 goto out;
8224
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008225 /*
8226 * The nested attribute uses enum nl80211_band as the index. This maps
8227 * directly to the enum ieee80211_band values used in cfg80211.
8228 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008229 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008230 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008231 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008232 int err;
8233
Johannes Berg4c476992010-10-04 21:36:35 +02008234 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8235 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008236 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008237 if (sband == NULL)
8238 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008239 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8240 nla_len(tx_rates), nl80211_txattr_policy);
8241 if (err)
8242 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008243 if (tb[NL80211_TXRATE_LEGACY]) {
8244 mask.control[band].legacy = rateset_to_mask(
8245 sband,
8246 nla_data(tb[NL80211_TXRATE_LEGACY]),
8247 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308248 if ((mask.control[band].legacy == 0) &&
8249 nla_len(tb[NL80211_TXRATE_LEGACY]))
8250 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008251 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008252 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008253 if (!ht_rateset_to_mask(
8254 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008255 nla_data(tb[NL80211_TXRATE_HT]),
8256 nla_len(tb[NL80211_TXRATE_HT]),
8257 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008258 return -EINVAL;
8259 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008260 if (tb[NL80211_TXRATE_VHT]) {
8261 if (!vht_set_mcs_mask(
8262 sband,
8263 nla_data(tb[NL80211_TXRATE_VHT]),
8264 mask.control[band].vht_mcs))
8265 return -EINVAL;
8266 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008267 if (tb[NL80211_TXRATE_GI]) {
8268 mask.control[band].gi =
8269 nla_get_u8(tb[NL80211_TXRATE_GI]);
8270 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8271 return -EINVAL;
8272 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008273
8274 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008275 /* don't allow empty legacy rates if HT or VHT
8276 * are not even supported.
8277 */
8278 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8279 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008280 return -EINVAL;
8281
8282 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008283 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008284 goto out;
8285
8286 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8287 if (mask.control[band].vht_mcs[i])
8288 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008289
8290 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008291 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008292 }
8293 }
8294
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008295out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008296 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008297}
8298
Johannes Berg2e161f72010-08-12 15:38:38 +02008299static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008300{
Johannes Berg4c476992010-10-04 21:36:35 +02008301 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008302 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008303 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008304
8305 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8306 return -EINVAL;
8307
Johannes Berg2e161f72010-08-12 15:38:38 +02008308 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8309 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008310
Johannes Berg71bbc992012-06-15 15:30:18 +02008311 switch (wdev->iftype) {
8312 case NL80211_IFTYPE_STATION:
8313 case NL80211_IFTYPE_ADHOC:
8314 case NL80211_IFTYPE_P2P_CLIENT:
8315 case NL80211_IFTYPE_AP:
8316 case NL80211_IFTYPE_AP_VLAN:
8317 case NL80211_IFTYPE_MESH_POINT:
8318 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008319 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008320 break;
8321 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008322 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008323 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008324
8325 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008326 if (!rdev->ops->mgmt_tx)
8327 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008328
Eric W. Biederman15e47302012-09-07 20:12:54 +00008329 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008330 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8331 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008332}
8333
Johannes Berg2e161f72010-08-12 15:38:38 +02008334static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008335{
Johannes Berg4c476992010-10-04 21:36:35 +02008336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008337 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008338 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008339 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008340 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008341 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008342 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008343 struct cfg80211_mgmt_tx_params params = {
8344 .dont_wait_for_ack =
8345 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8346 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008347
Johannes Berg683b6d32012-11-08 21:25:48 +01008348 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008349 return -EINVAL;
8350
Johannes Berg4c476992010-10-04 21:36:35 +02008351 if (!rdev->ops->mgmt_tx)
8352 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008353
Johannes Berg71bbc992012-06-15 15:30:18 +02008354 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008355 case NL80211_IFTYPE_P2P_DEVICE:
8356 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8357 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008358 case NL80211_IFTYPE_STATION:
8359 case NL80211_IFTYPE_ADHOC:
8360 case NL80211_IFTYPE_P2P_CLIENT:
8361 case NL80211_IFTYPE_AP:
8362 case NL80211_IFTYPE_AP_VLAN:
8363 case NL80211_IFTYPE_MESH_POINT:
8364 case NL80211_IFTYPE_P2P_GO:
8365 break;
8366 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008367 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008368 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008369
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008370 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008371 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008372 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008373 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008374
8375 /*
8376 * We should wait on the channel for at least a minimum amount
8377 * of time (10ms) but no longer than the driver supports.
8378 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008379 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8380 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008381 return -EINVAL;
8382
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008383 }
8384
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008385 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008386
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008387 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008388 return -EINVAL;
8389
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008390 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308391
Antonio Quartulliea141b752013-06-11 14:20:03 +02008392 /* get the channel if any has been specified, otherwise pass NULL to
8393 * the driver. The latter will use the current one
8394 */
8395 chandef.chan = NULL;
8396 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8397 err = nl80211_parse_chandef(rdev, info, &chandef);
8398 if (err)
8399 return err;
8400 }
8401
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008402 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008403 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008404
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008405 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8406 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8407
8408 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8409 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8410 int i;
8411
8412 if (len % sizeof(u16))
8413 return -EINVAL;
8414
8415 params.n_csa_offsets = len / sizeof(u16);
8416 params.csa_offsets =
8417 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8418
8419 /* check that all the offsets fit the frame */
8420 for (i = 0; i < params.n_csa_offsets; i++) {
8421 if (params.csa_offsets[i] >= params.len)
8422 return -EINVAL;
8423 }
8424 }
8425
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008426 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008427 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8428 if (!msg)
8429 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008430
Eric W. Biederman15e47302012-09-07 20:12:54 +00008431 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008432 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008433 if (!hdr) {
8434 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008435 goto free_msg;
8436 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008437 }
Johannes Berge247bd902011-11-04 11:18:21 +01008438
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008439 params.chan = chandef.chan;
8440 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008441 if (err)
8442 goto free_msg;
8443
Johannes Berge247bd902011-11-04 11:18:21 +01008444 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008445 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8446 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008447
Johannes Berge247bd902011-11-04 11:18:21 +01008448 genlmsg_end(msg, hdr);
8449 return genlmsg_reply(msg, info);
8450 }
8451
8452 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008453
8454 nla_put_failure:
8455 err = -ENOBUFS;
8456 free_msg:
8457 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008458 return err;
8459}
8460
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008461static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8462{
8463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008464 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008465 u64 cookie;
8466
8467 if (!info->attrs[NL80211_ATTR_COOKIE])
8468 return -EINVAL;
8469
8470 if (!rdev->ops->mgmt_tx_cancel_wait)
8471 return -EOPNOTSUPP;
8472
Johannes Berg71bbc992012-06-15 15:30:18 +02008473 switch (wdev->iftype) {
8474 case NL80211_IFTYPE_STATION:
8475 case NL80211_IFTYPE_ADHOC:
8476 case NL80211_IFTYPE_P2P_CLIENT:
8477 case NL80211_IFTYPE_AP:
8478 case NL80211_IFTYPE_AP_VLAN:
8479 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008480 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008481 break;
8482 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008483 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008484 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008485
8486 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8487
Hila Gonene35e4d22012-06-27 17:19:42 +03008488 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008489}
8490
Kalle Valoffb9eb32010-02-17 17:58:10 +02008491static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8492{
Johannes Berg4c476992010-10-04 21:36:35 +02008493 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008494 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008495 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008496 u8 ps_state;
8497 bool state;
8498 int err;
8499
Johannes Berg4c476992010-10-04 21:36:35 +02008500 if (!info->attrs[NL80211_ATTR_PS_STATE])
8501 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008502
8503 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8504
Johannes Berg4c476992010-10-04 21:36:35 +02008505 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8506 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008507
8508 wdev = dev->ieee80211_ptr;
8509
Johannes Berg4c476992010-10-04 21:36:35 +02008510 if (!rdev->ops->set_power_mgmt)
8511 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008512
8513 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8514
8515 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008516 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008517
Hila Gonene35e4d22012-06-27 17:19:42 +03008518 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008519 if (!err)
8520 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008521 return err;
8522}
8523
8524static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8525{
Johannes Berg4c476992010-10-04 21:36:35 +02008526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008527 enum nl80211_ps_state ps_state;
8528 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008529 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008530 struct sk_buff *msg;
8531 void *hdr;
8532 int err;
8533
Kalle Valoffb9eb32010-02-17 17:58:10 +02008534 wdev = dev->ieee80211_ptr;
8535
Johannes Berg4c476992010-10-04 21:36:35 +02008536 if (!rdev->ops->set_power_mgmt)
8537 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008538
8539 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008540 if (!msg)
8541 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008542
Eric W. Biederman15e47302012-09-07 20:12:54 +00008543 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008544 NL80211_CMD_GET_POWER_SAVE);
8545 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008546 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008547 goto free_msg;
8548 }
8549
8550 if (wdev->ps)
8551 ps_state = NL80211_PS_ENABLED;
8552 else
8553 ps_state = NL80211_PS_DISABLED;
8554
David S. Miller9360ffd2012-03-29 04:41:26 -04008555 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8556 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008557
8558 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008559 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008560
Johannes Berg4c476992010-10-04 21:36:35 +02008561 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008562 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008563 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008564 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008565 return err;
8566}
8567
Johannes Berg94e860f2014-01-20 23:58:15 +01008568static const struct nla_policy
8569nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008570 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8571 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8572 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008573 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8574 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8575 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008576};
8577
Thomas Pedersen84f10702012-07-12 16:17:33 -07008578static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008579 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008580{
8581 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008582 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008583 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008584
Johannes Bergd9d8b012012-11-26 12:51:52 +01008585 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008586 return -EINVAL;
8587
Thomas Pedersen84f10702012-07-12 16:17:33 -07008588 if (!rdev->ops->set_cqm_txe_config)
8589 return -EOPNOTSUPP;
8590
8591 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8592 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8593 return -EOPNOTSUPP;
8594
Hila Gonene35e4d22012-06-27 17:19:42 +03008595 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008596}
8597
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008598static int nl80211_set_cqm_rssi(struct genl_info *info,
8599 s32 threshold, u32 hysteresis)
8600{
Johannes Berg4c476992010-10-04 21:36:35 +02008601 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008602 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008603 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008604
8605 if (threshold > 0)
8606 return -EINVAL;
8607
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008608 /* disabling - hysteresis should also be zero then */
8609 if (threshold == 0)
8610 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008611
Johannes Berg4c476992010-10-04 21:36:35 +02008612 if (!rdev->ops->set_cqm_rssi_config)
8613 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008614
Johannes Berg074ac8d2010-09-16 14:58:22 +02008615 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008616 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8617 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008618
Hila Gonene35e4d22012-06-27 17:19:42 +03008619 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008620}
8621
8622static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8623{
8624 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8625 struct nlattr *cqm;
8626 int err;
8627
8628 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008629 if (!cqm)
8630 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008631
8632 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8633 nl80211_attr_cqm_policy);
8634 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008635 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008636
8637 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8638 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008639 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8640 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008641
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008642 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8643 }
8644
8645 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8646 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8647 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8648 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8649 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8650 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8651
8652 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8653 }
8654
8655 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008656}
8657
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008658static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8659{
8660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8661 struct net_device *dev = info->user_ptr[1];
8662 struct ocb_setup setup = {};
8663 int err;
8664
8665 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8666 if (err)
8667 return err;
8668
8669 return cfg80211_join_ocb(rdev, dev, &setup);
8670}
8671
8672static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8673{
8674 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8675 struct net_device *dev = info->user_ptr[1];
8676
8677 return cfg80211_leave_ocb(rdev, dev);
8678}
8679
Johannes Berg29cbe682010-12-03 09:20:44 +01008680static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8681{
8682 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8683 struct net_device *dev = info->user_ptr[1];
8684 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008685 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008686 int err;
8687
8688 /* start with default */
8689 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008690 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008691
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008692 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008693 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008694 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008695 if (err)
8696 return err;
8697 }
8698
8699 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8700 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8701 return -EINVAL;
8702
Javier Cardonac80d5452010-12-16 17:37:49 -08008703 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8704 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8705
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008706 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8707 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8708 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8709 return -EINVAL;
8710
Marco Porsch9bdbf042013-01-07 16:04:51 +01008711 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8712 setup.beacon_interval =
8713 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8714 if (setup.beacon_interval < 10 ||
8715 setup.beacon_interval > 10000)
8716 return -EINVAL;
8717 }
8718
8719 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8720 setup.dtim_period =
8721 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8722 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8723 return -EINVAL;
8724 }
8725
Javier Cardonac80d5452010-12-16 17:37:49 -08008726 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8727 /* parse additional setup parameters if given */
8728 err = nl80211_parse_mesh_setup(info, &setup);
8729 if (err)
8730 return err;
8731 }
8732
Thomas Pedersend37bb182013-03-04 13:06:13 -08008733 if (setup.user_mpm)
8734 cfg.auto_open_plinks = false;
8735
Johannes Bergcc1d2802012-05-16 23:50:20 +02008736 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008737 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8738 if (err)
8739 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008740 } else {
8741 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008742 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008743 }
8744
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008745 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8746 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8747 int n_rates =
8748 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8749 struct ieee80211_supported_band *sband;
8750
8751 if (!setup.chandef.chan)
8752 return -EINVAL;
8753
8754 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8755
8756 err = ieee80211_get_ratemask(sband, rates, n_rates,
8757 &setup.basic_rates);
8758 if (err)
8759 return err;
8760 }
8761
Javier Cardonac80d5452010-12-16 17:37:49 -08008762 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008763}
8764
8765static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8766{
8767 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8768 struct net_device *dev = info->user_ptr[1];
8769
8770 return cfg80211_leave_mesh(rdev, dev);
8771}
8772
Johannes Bergdfb89c52012-06-27 09:23:48 +02008773#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008774static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8775 struct cfg80211_registered_device *rdev)
8776{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008777 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008778 struct nlattr *nl_pats, *nl_pat;
8779 int i, pat_len;
8780
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008781 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008782 return 0;
8783
8784 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8785 if (!nl_pats)
8786 return -ENOBUFS;
8787
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008788 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008789 nl_pat = nla_nest_start(msg, i + 1);
8790 if (!nl_pat)
8791 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008792 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008793 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008794 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008795 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8796 wowlan->patterns[i].pattern) ||
8797 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008798 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008799 return -ENOBUFS;
8800 nla_nest_end(msg, nl_pat);
8801 }
8802 nla_nest_end(msg, nl_pats);
8803
8804 return 0;
8805}
8806
Johannes Berg2a0e0472013-01-23 22:57:40 +01008807static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8808 struct cfg80211_wowlan_tcp *tcp)
8809{
8810 struct nlattr *nl_tcp;
8811
8812 if (!tcp)
8813 return 0;
8814
8815 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8816 if (!nl_tcp)
8817 return -ENOBUFS;
8818
Jiri Benc930345e2015-03-29 16:59:25 +02008819 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8820 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01008821 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8822 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8823 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8824 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8825 tcp->payload_len, tcp->payload) ||
8826 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8827 tcp->data_interval) ||
8828 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8829 tcp->wake_len, tcp->wake_data) ||
8830 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8831 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8832 return -ENOBUFS;
8833
8834 if (tcp->payload_seq.len &&
8835 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8836 sizeof(tcp->payload_seq), &tcp->payload_seq))
8837 return -ENOBUFS;
8838
8839 if (tcp->payload_tok.len &&
8840 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8841 sizeof(tcp->payload_tok) + tcp->tokens_size,
8842 &tcp->payload_tok))
8843 return -ENOBUFS;
8844
Johannes Berge248ad32013-05-16 10:24:28 +02008845 nla_nest_end(msg, nl_tcp);
8846
Johannes Berg2a0e0472013-01-23 22:57:40 +01008847 return 0;
8848}
8849
Luciano Coelho75453cc2015-01-09 14:06:37 +02008850static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8851 struct cfg80211_sched_scan_request *req)
8852{
8853 struct nlattr *nd, *freqs, *matches, *match;
8854 int i;
8855
8856 if (!req)
8857 return 0;
8858
8859 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
8860 if (!nd)
8861 return -ENOBUFS;
8862
8863 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval))
8864 return -ENOBUFS;
8865
Luciano Coelho21fea562015-03-17 16:36:01 +02008866 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
8867 return -ENOBUFS;
8868
Luciano Coelho75453cc2015-01-09 14:06:37 +02008869 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8870 if (!freqs)
8871 return -ENOBUFS;
8872
8873 for (i = 0; i < req->n_channels; i++)
8874 nla_put_u32(msg, i, req->channels[i]->center_freq);
8875
8876 nla_nest_end(msg, freqs);
8877
8878 if (req->n_match_sets) {
8879 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
8880 for (i = 0; i < req->n_match_sets; i++) {
8881 match = nla_nest_start(msg, i);
8882 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
8883 req->match_sets[i].ssid.ssid_len,
8884 req->match_sets[i].ssid.ssid);
8885 nla_nest_end(msg, match);
8886 }
8887 nla_nest_end(msg, matches);
8888 }
8889
8890 nla_nest_end(msg, nd);
8891
8892 return 0;
8893}
8894
Johannes Bergff1b6e62011-05-04 15:37:28 +02008895static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8896{
8897 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8898 struct sk_buff *msg;
8899 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008900 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008901
Johannes Berg964dc9e2013-06-03 17:25:34 +02008902 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008903 return -EOPNOTSUPP;
8904
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008905 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008906 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008907 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8908 rdev->wiphy.wowlan_config->tcp->payload_len +
8909 rdev->wiphy.wowlan_config->tcp->wake_len +
8910 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008911 }
8912
8913 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008914 if (!msg)
8915 return -ENOMEM;
8916
Eric W. Biederman15e47302012-09-07 20:12:54 +00008917 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008918 NL80211_CMD_GET_WOWLAN);
8919 if (!hdr)
8920 goto nla_put_failure;
8921
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008922 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008923 struct nlattr *nl_wowlan;
8924
8925 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8926 if (!nl_wowlan)
8927 goto nla_put_failure;
8928
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008929 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008930 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008931 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008932 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008933 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008934 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008935 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008936 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008937 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008938 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008939 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008940 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008941 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008942 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8943 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008944
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008945 if (nl80211_send_wowlan_patterns(msg, rdev))
8946 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008947
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008948 if (nl80211_send_wowlan_tcp(msg,
8949 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008950 goto nla_put_failure;
8951
Luciano Coelho75453cc2015-01-09 14:06:37 +02008952 if (nl80211_send_wowlan_nd(
8953 msg,
8954 rdev->wiphy.wowlan_config->nd_config))
8955 goto nla_put_failure;
8956
Johannes Bergff1b6e62011-05-04 15:37:28 +02008957 nla_nest_end(msg, nl_wowlan);
8958 }
8959
8960 genlmsg_end(msg, hdr);
8961 return genlmsg_reply(msg, info);
8962
8963nla_put_failure:
8964 nlmsg_free(msg);
8965 return -ENOBUFS;
8966}
8967
Johannes Berg2a0e0472013-01-23 22:57:40 +01008968static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8969 struct nlattr *attr,
8970 struct cfg80211_wowlan *trig)
8971{
8972 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8973 struct cfg80211_wowlan_tcp *cfg;
8974 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8975 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8976 u32 size;
8977 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8978 int err, port;
8979
Johannes Berg964dc9e2013-06-03 17:25:34 +02008980 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008981 return -EINVAL;
8982
8983 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8984 nla_data(attr), nla_len(attr),
8985 nl80211_wowlan_tcp_policy);
8986 if (err)
8987 return err;
8988
8989 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8990 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8991 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8992 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8993 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8994 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8995 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8996 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8997 return -EINVAL;
8998
8999 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009000 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009001 return -EINVAL;
9002
9003 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02009004 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01009005 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009006 return -EINVAL;
9007
9008 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009009 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009010 return -EINVAL;
9011
9012 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
9013 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
9014 return -EINVAL;
9015
9016 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
9017 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9018
9019 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9020 tokens_size = tokln - sizeof(*tok);
9021
9022 if (!tok->len || tokens_size % tok->len)
9023 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009024 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009025 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009026 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009027 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009028 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009029 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009030 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009031 return -EINVAL;
9032 if (tok->offset + tok->len > data_size)
9033 return -EINVAL;
9034 }
9035
9036 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9037 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009038 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009039 return -EINVAL;
9040 if (seq->len == 0 || seq->len > 4)
9041 return -EINVAL;
9042 if (seq->len + seq->offset > data_size)
9043 return -EINVAL;
9044 }
9045
9046 size = sizeof(*cfg);
9047 size += data_size;
9048 size += wake_size + wake_mask_size;
9049 size += tokens_size;
9050
9051 cfg = kzalloc(size, GFP_KERNEL);
9052 if (!cfg)
9053 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009054 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9055 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009056 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9057 ETH_ALEN);
9058 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9059 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9060 else
9061 port = 0;
9062#ifdef CONFIG_INET
9063 /* allocate a socket and port for it and use it */
9064 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9065 IPPROTO_TCP, &cfg->sock, 1);
9066 if (err) {
9067 kfree(cfg);
9068 return err;
9069 }
9070 if (inet_csk_get_port(cfg->sock->sk, port)) {
9071 sock_release(cfg->sock);
9072 kfree(cfg);
9073 return -EADDRINUSE;
9074 }
9075 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9076#else
9077 if (!port) {
9078 kfree(cfg);
9079 return -EINVAL;
9080 }
9081 cfg->src_port = port;
9082#endif
9083
9084 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9085 cfg->payload_len = data_size;
9086 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9087 memcpy((void *)cfg->payload,
9088 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9089 data_size);
9090 if (seq)
9091 cfg->payload_seq = *seq;
9092 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9093 cfg->wake_len = wake_size;
9094 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9095 memcpy((void *)cfg->wake_data,
9096 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9097 wake_size);
9098 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9099 data_size + wake_size;
9100 memcpy((void *)cfg->wake_mask,
9101 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9102 wake_mask_size);
9103 if (tok) {
9104 cfg->tokens_size = tokens_size;
9105 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9106 }
9107
9108 trig->tcp = cfg;
9109
9110 return 0;
9111}
9112
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009113static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9114 const struct wiphy_wowlan_support *wowlan,
9115 struct nlattr *attr,
9116 struct cfg80211_wowlan *trig)
9117{
9118 struct nlattr **tb;
9119 int err;
9120
9121 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9122 if (!tb)
9123 return -ENOMEM;
9124
9125 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9126 err = -EOPNOTSUPP;
9127 goto out;
9128 }
9129
9130 err = nla_parse(tb, NL80211_ATTR_MAX,
9131 nla_data(attr), nla_len(attr),
9132 nl80211_policy);
9133 if (err)
9134 goto out;
9135
Johannes Bergad2b26a2014-06-12 21:39:05 +02009136 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009137 err = PTR_ERR_OR_ZERO(trig->nd_config);
9138 if (err)
9139 trig->nd_config = NULL;
9140
9141out:
9142 kfree(tb);
9143 return err;
9144}
9145
Johannes Bergff1b6e62011-05-04 15:37:28 +02009146static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9147{
9148 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9149 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009150 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009151 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009152 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009153 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009154 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009155 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009156
Johannes Berg964dc9e2013-06-03 17:25:34 +02009157 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009158 return -EOPNOTSUPP;
9159
Johannes Bergae33bd82012-07-12 16:25:02 +02009160 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9161 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009162 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009163 goto set_wakeup;
9164 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009165
9166 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9167 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9168 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9169 nl80211_wowlan_policy);
9170 if (err)
9171 return err;
9172
9173 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9174 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9175 return -EINVAL;
9176 new_triggers.any = true;
9177 }
9178
9179 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9180 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9181 return -EINVAL;
9182 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009183 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009184 }
9185
9186 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9187 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9188 return -EINVAL;
9189 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009190 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009191 }
9192
Johannes Berg77dbbb12011-07-13 10:48:55 +02009193 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9194 return -EINVAL;
9195
9196 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9197 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9198 return -EINVAL;
9199 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009200 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009201 }
9202
9203 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9204 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9205 return -EINVAL;
9206 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009207 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009208 }
9209
9210 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9211 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9212 return -EINVAL;
9213 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009214 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009215 }
9216
9217 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9218 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9219 return -EINVAL;
9220 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009221 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009222 }
9223
Johannes Bergff1b6e62011-05-04 15:37:28 +02009224 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9225 struct nlattr *pat;
9226 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009227 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009228 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009229
Johannes Berg98fc4382015-03-01 09:10:13 +02009230 regular = true;
9231
Johannes Bergff1b6e62011-05-04 15:37:28 +02009232 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9233 rem)
9234 n_patterns++;
9235 if (n_patterns > wowlan->n_patterns)
9236 return -EINVAL;
9237
9238 new_triggers.patterns = kcalloc(n_patterns,
9239 sizeof(new_triggers.patterns[0]),
9240 GFP_KERNEL);
9241 if (!new_triggers.patterns)
9242 return -ENOMEM;
9243
9244 new_triggers.n_patterns = n_patterns;
9245 i = 0;
9246
9247 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9248 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009249 u8 *mask_pat;
9250
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009251 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9252 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009253 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009254 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9255 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009256 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009257 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009258 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009259 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009260 goto error;
9261 if (pat_len > wowlan->pattern_max_len ||
9262 pat_len < wowlan->pattern_min_len)
9263 goto error;
9264
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009265 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009266 pkt_offset = 0;
9267 else
9268 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009269 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009270 if (pkt_offset > wowlan->max_pkt_offset)
9271 goto error;
9272 new_triggers.patterns[i].pkt_offset = pkt_offset;
9273
Johannes Berg922bd802014-05-19 17:59:50 +02009274 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9275 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009276 err = -ENOMEM;
9277 goto error;
9278 }
Johannes Berg922bd802014-05-19 17:59:50 +02009279 new_triggers.patterns[i].mask = mask_pat;
9280 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009281 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009282 mask_pat += mask_len;
9283 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009284 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009285 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009286 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009287 pat_len);
9288 i++;
9289 }
9290 }
9291
Johannes Berg2a0e0472013-01-23 22:57:40 +01009292 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009293 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009294 err = nl80211_parse_wowlan_tcp(
9295 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9296 &new_triggers);
9297 if (err)
9298 goto error;
9299 }
9300
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009301 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009302 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009303 err = nl80211_parse_wowlan_nd(
9304 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9305 &new_triggers);
9306 if (err)
9307 goto error;
9308 }
9309
Johannes Berg98fc4382015-03-01 09:10:13 +02009310 /* The 'any' trigger means the device continues operating more or less
9311 * as in its normal operation mode and wakes up the host on most of the
9312 * normal interrupts (like packet RX, ...)
9313 * It therefore makes little sense to combine with the more constrained
9314 * wakeup trigger modes.
9315 */
9316 if (new_triggers.any && regular) {
9317 err = -EINVAL;
9318 goto error;
9319 }
9320
Johannes Bergae33bd82012-07-12 16:25:02 +02009321 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9322 if (!ntrig) {
9323 err = -ENOMEM;
9324 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009325 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009326 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009327 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009328
Johannes Bergae33bd82012-07-12 16:25:02 +02009329 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009330 if (rdev->ops->set_wakeup &&
9331 prev_enabled != !!rdev->wiphy.wowlan_config)
9332 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009333
Johannes Bergff1b6e62011-05-04 15:37:28 +02009334 return 0;
9335 error:
9336 for (i = 0; i < new_triggers.n_patterns; i++)
9337 kfree(new_triggers.patterns[i].mask);
9338 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009339 if (new_triggers.tcp && new_triggers.tcp->sock)
9340 sock_release(new_triggers.tcp->sock);
9341 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009342 return err;
9343}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009344#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009345
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009346static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9347 struct cfg80211_registered_device *rdev)
9348{
9349 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9350 int i, j, pat_len;
9351 struct cfg80211_coalesce_rules *rule;
9352
9353 if (!rdev->coalesce->n_rules)
9354 return 0;
9355
9356 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9357 if (!nl_rules)
9358 return -ENOBUFS;
9359
9360 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9361 nl_rule = nla_nest_start(msg, i + 1);
9362 if (!nl_rule)
9363 return -ENOBUFS;
9364
9365 rule = &rdev->coalesce->rules[i];
9366 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9367 rule->delay))
9368 return -ENOBUFS;
9369
9370 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9371 rule->condition))
9372 return -ENOBUFS;
9373
9374 nl_pats = nla_nest_start(msg,
9375 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9376 if (!nl_pats)
9377 return -ENOBUFS;
9378
9379 for (j = 0; j < rule->n_patterns; j++) {
9380 nl_pat = nla_nest_start(msg, j + 1);
9381 if (!nl_pat)
9382 return -ENOBUFS;
9383 pat_len = rule->patterns[j].pattern_len;
9384 if (nla_put(msg, NL80211_PKTPAT_MASK,
9385 DIV_ROUND_UP(pat_len, 8),
9386 rule->patterns[j].mask) ||
9387 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9388 rule->patterns[j].pattern) ||
9389 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9390 rule->patterns[j].pkt_offset))
9391 return -ENOBUFS;
9392 nla_nest_end(msg, nl_pat);
9393 }
9394 nla_nest_end(msg, nl_pats);
9395 nla_nest_end(msg, nl_rule);
9396 }
9397 nla_nest_end(msg, nl_rules);
9398
9399 return 0;
9400}
9401
9402static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9403{
9404 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9405 struct sk_buff *msg;
9406 void *hdr;
9407
9408 if (!rdev->wiphy.coalesce)
9409 return -EOPNOTSUPP;
9410
9411 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9412 if (!msg)
9413 return -ENOMEM;
9414
9415 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9416 NL80211_CMD_GET_COALESCE);
9417 if (!hdr)
9418 goto nla_put_failure;
9419
9420 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9421 goto nla_put_failure;
9422
9423 genlmsg_end(msg, hdr);
9424 return genlmsg_reply(msg, info);
9425
9426nla_put_failure:
9427 nlmsg_free(msg);
9428 return -ENOBUFS;
9429}
9430
9431void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9432{
9433 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9434 int i, j;
9435 struct cfg80211_coalesce_rules *rule;
9436
9437 if (!coalesce)
9438 return;
9439
9440 for (i = 0; i < coalesce->n_rules; i++) {
9441 rule = &coalesce->rules[i];
9442 for (j = 0; j < rule->n_patterns; j++)
9443 kfree(rule->patterns[j].mask);
9444 kfree(rule->patterns);
9445 }
9446 kfree(coalesce->rules);
9447 kfree(coalesce);
9448 rdev->coalesce = NULL;
9449}
9450
9451static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9452 struct nlattr *rule,
9453 struct cfg80211_coalesce_rules *new_rule)
9454{
9455 int err, i;
9456 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9457 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9458 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9459 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9460
9461 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9462 nla_len(rule), nl80211_coalesce_policy);
9463 if (err)
9464 return err;
9465
9466 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9467 new_rule->delay =
9468 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9469 if (new_rule->delay > coalesce->max_delay)
9470 return -EINVAL;
9471
9472 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9473 new_rule->condition =
9474 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9475 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9476 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9477 return -EINVAL;
9478
9479 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9480 return -EINVAL;
9481
9482 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9483 rem)
9484 n_patterns++;
9485 if (n_patterns > coalesce->n_patterns)
9486 return -EINVAL;
9487
9488 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9489 GFP_KERNEL);
9490 if (!new_rule->patterns)
9491 return -ENOMEM;
9492
9493 new_rule->n_patterns = n_patterns;
9494 i = 0;
9495
9496 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9497 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009498 u8 *mask_pat;
9499
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009500 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9501 nla_len(pat), NULL);
9502 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9503 !pat_tb[NL80211_PKTPAT_PATTERN])
9504 return -EINVAL;
9505 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9506 mask_len = DIV_ROUND_UP(pat_len, 8);
9507 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9508 return -EINVAL;
9509 if (pat_len > coalesce->pattern_max_len ||
9510 pat_len < coalesce->pattern_min_len)
9511 return -EINVAL;
9512
9513 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9514 pkt_offset = 0;
9515 else
9516 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9517 if (pkt_offset > coalesce->max_pkt_offset)
9518 return -EINVAL;
9519 new_rule->patterns[i].pkt_offset = pkt_offset;
9520
Johannes Berg922bd802014-05-19 17:59:50 +02009521 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9522 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009523 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009524
9525 new_rule->patterns[i].mask = mask_pat;
9526 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9527 mask_len);
9528
9529 mask_pat += mask_len;
9530 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009531 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009532 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9533 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009534 i++;
9535 }
9536
9537 return 0;
9538}
9539
9540static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9541{
9542 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9543 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9544 struct cfg80211_coalesce new_coalesce = {};
9545 struct cfg80211_coalesce *n_coalesce;
9546 int err, rem_rule, n_rules = 0, i, j;
9547 struct nlattr *rule;
9548 struct cfg80211_coalesce_rules *tmp_rule;
9549
9550 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9551 return -EOPNOTSUPP;
9552
9553 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9554 cfg80211_rdev_free_coalesce(rdev);
9555 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9556 return 0;
9557 }
9558
9559 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9560 rem_rule)
9561 n_rules++;
9562 if (n_rules > coalesce->n_rules)
9563 return -EINVAL;
9564
9565 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9566 GFP_KERNEL);
9567 if (!new_coalesce.rules)
9568 return -ENOMEM;
9569
9570 new_coalesce.n_rules = n_rules;
9571 i = 0;
9572
9573 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9574 rem_rule) {
9575 err = nl80211_parse_coalesce_rule(rdev, rule,
9576 &new_coalesce.rules[i]);
9577 if (err)
9578 goto error;
9579
9580 i++;
9581 }
9582
9583 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9584 if (err)
9585 goto error;
9586
9587 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9588 if (!n_coalesce) {
9589 err = -ENOMEM;
9590 goto error;
9591 }
9592 cfg80211_rdev_free_coalesce(rdev);
9593 rdev->coalesce = n_coalesce;
9594
9595 return 0;
9596error:
9597 for (i = 0; i < new_coalesce.n_rules; i++) {
9598 tmp_rule = &new_coalesce.rules[i];
9599 for (j = 0; j < tmp_rule->n_patterns; j++)
9600 kfree(tmp_rule->patterns[j].mask);
9601 kfree(tmp_rule->patterns);
9602 }
9603 kfree(new_coalesce.rules);
9604
9605 return err;
9606}
9607
Johannes Berge5497d72011-07-05 16:35:40 +02009608static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9609{
9610 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9611 struct net_device *dev = info->user_ptr[1];
9612 struct wireless_dev *wdev = dev->ieee80211_ptr;
9613 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9614 struct cfg80211_gtk_rekey_data rekey_data;
9615 int err;
9616
9617 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9618 return -EINVAL;
9619
9620 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9621 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9622 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9623 nl80211_rekey_policy);
9624 if (err)
9625 return err;
9626
9627 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9628 return -ERANGE;
9629 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9630 return -ERANGE;
9631 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9632 return -ERANGE;
9633
Johannes Berg78f686c2014-09-10 22:28:06 +03009634 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9635 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9636 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009637
9638 wdev_lock(wdev);
9639 if (!wdev->current_bss) {
9640 err = -ENOTCONN;
9641 goto out;
9642 }
9643
9644 if (!rdev->ops->set_rekey_data) {
9645 err = -EOPNOTSUPP;
9646 goto out;
9647 }
9648
Hila Gonene35e4d22012-06-27 17:19:42 +03009649 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009650 out:
9651 wdev_unlock(wdev);
9652 return err;
9653}
9654
Johannes Berg28946da2011-11-04 11:18:12 +01009655static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9656 struct genl_info *info)
9657{
9658 struct net_device *dev = info->user_ptr[1];
9659 struct wireless_dev *wdev = dev->ieee80211_ptr;
9660
9661 if (wdev->iftype != NL80211_IFTYPE_AP &&
9662 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9663 return -EINVAL;
9664
Eric W. Biederman15e47302012-09-07 20:12:54 +00009665 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009666 return -EBUSY;
9667
Eric W. Biederman15e47302012-09-07 20:12:54 +00009668 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009669 return 0;
9670}
9671
Johannes Berg7f6cf312011-11-04 11:18:15 +01009672static int nl80211_probe_client(struct sk_buff *skb,
9673 struct genl_info *info)
9674{
9675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9676 struct net_device *dev = info->user_ptr[1];
9677 struct wireless_dev *wdev = dev->ieee80211_ptr;
9678 struct sk_buff *msg;
9679 void *hdr;
9680 const u8 *addr;
9681 u64 cookie;
9682 int err;
9683
9684 if (wdev->iftype != NL80211_IFTYPE_AP &&
9685 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9686 return -EOPNOTSUPP;
9687
9688 if (!info->attrs[NL80211_ATTR_MAC])
9689 return -EINVAL;
9690
9691 if (!rdev->ops->probe_client)
9692 return -EOPNOTSUPP;
9693
9694 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9695 if (!msg)
9696 return -ENOMEM;
9697
Eric W. Biederman15e47302012-09-07 20:12:54 +00009698 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009699 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009700 if (!hdr) {
9701 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009702 goto free_msg;
9703 }
9704
9705 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9706
Hila Gonene35e4d22012-06-27 17:19:42 +03009707 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009708 if (err)
9709 goto free_msg;
9710
David S. Miller9360ffd2012-03-29 04:41:26 -04009711 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9712 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009713
9714 genlmsg_end(msg, hdr);
9715
9716 return genlmsg_reply(msg, info);
9717
9718 nla_put_failure:
9719 err = -ENOBUFS;
9720 free_msg:
9721 nlmsg_free(msg);
9722 return err;
9723}
9724
Johannes Berg5e760232011-11-04 11:18:17 +01009725static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9726{
9727 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009728 struct cfg80211_beacon_registration *reg, *nreg;
9729 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009730
9731 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9732 return -EOPNOTSUPP;
9733
Ben Greear37c73b52012-10-26 14:49:25 -07009734 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9735 if (!nreg)
9736 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009737
Ben Greear37c73b52012-10-26 14:49:25 -07009738 /* First, check if already registered. */
9739 spin_lock_bh(&rdev->beacon_registrations_lock);
9740 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9741 if (reg->nlportid == info->snd_portid) {
9742 rv = -EALREADY;
9743 goto out_err;
9744 }
9745 }
9746 /* Add it to the list */
9747 nreg->nlportid = info->snd_portid;
9748 list_add(&nreg->list, &rdev->beacon_registrations);
9749
9750 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009751
9752 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009753out_err:
9754 spin_unlock_bh(&rdev->beacon_registrations_lock);
9755 kfree(nreg);
9756 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009757}
9758
Johannes Berg98104fde2012-06-16 00:19:54 +02009759static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9760{
9761 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9762 struct wireless_dev *wdev = info->user_ptr[1];
9763 int err;
9764
9765 if (!rdev->ops->start_p2p_device)
9766 return -EOPNOTSUPP;
9767
9768 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9769 return -EOPNOTSUPP;
9770
9771 if (wdev->p2p_started)
9772 return 0;
9773
Luciano Coelhob6a55012014-02-27 11:07:21 +02009774 if (rfkill_blocked(rdev->rfkill))
9775 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009776
Johannes Bergeeb126e2012-10-23 15:16:50 +02009777 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009778 if (err)
9779 return err;
9780
9781 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009782 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009783
9784 return 0;
9785}
9786
9787static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9788{
9789 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9790 struct wireless_dev *wdev = info->user_ptr[1];
9791
9792 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9793 return -EOPNOTSUPP;
9794
9795 if (!rdev->ops->stop_p2p_device)
9796 return -EOPNOTSUPP;
9797
Johannes Bergf9f47522013-03-19 15:04:07 +01009798 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009799
9800 return 0;
9801}
9802
Johannes Berg3713b4e2013-02-14 16:19:38 +01009803static int nl80211_get_protocol_features(struct sk_buff *skb,
9804 struct genl_info *info)
9805{
9806 void *hdr;
9807 struct sk_buff *msg;
9808
9809 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9810 if (!msg)
9811 return -ENOMEM;
9812
9813 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9814 NL80211_CMD_GET_PROTOCOL_FEATURES);
9815 if (!hdr)
9816 goto nla_put_failure;
9817
9818 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9819 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9820 goto nla_put_failure;
9821
9822 genlmsg_end(msg, hdr);
9823 return genlmsg_reply(msg, info);
9824
9825 nla_put_failure:
9826 kfree_skb(msg);
9827 return -ENOBUFS;
9828}
9829
Jouni Malinen355199e2013-02-27 17:14:27 +02009830static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9831{
9832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9833 struct cfg80211_update_ft_ies_params ft_params;
9834 struct net_device *dev = info->user_ptr[1];
9835
9836 if (!rdev->ops->update_ft_ies)
9837 return -EOPNOTSUPP;
9838
9839 if (!info->attrs[NL80211_ATTR_MDID] ||
9840 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9841 return -EINVAL;
9842
9843 memset(&ft_params, 0, sizeof(ft_params));
9844 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9845 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9846 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9847
9848 return rdev_update_ft_ies(rdev, dev, &ft_params);
9849}
9850
Arend van Spriel5de17982013-04-18 15:49:00 +02009851static int nl80211_crit_protocol_start(struct sk_buff *skb,
9852 struct genl_info *info)
9853{
9854 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9855 struct wireless_dev *wdev = info->user_ptr[1];
9856 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9857 u16 duration;
9858 int ret;
9859
9860 if (!rdev->ops->crit_proto_start)
9861 return -EOPNOTSUPP;
9862
9863 if (WARN_ON(!rdev->ops->crit_proto_stop))
9864 return -EINVAL;
9865
9866 if (rdev->crit_proto_nlportid)
9867 return -EBUSY;
9868
9869 /* determine protocol if provided */
9870 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9871 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9872
9873 if (proto >= NUM_NL80211_CRIT_PROTO)
9874 return -EINVAL;
9875
9876 /* timeout must be provided */
9877 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9878 return -EINVAL;
9879
9880 duration =
9881 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9882
9883 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9884 return -ERANGE;
9885
9886 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9887 if (!ret)
9888 rdev->crit_proto_nlportid = info->snd_portid;
9889
9890 return ret;
9891}
9892
9893static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9894 struct genl_info *info)
9895{
9896 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9897 struct wireless_dev *wdev = info->user_ptr[1];
9898
9899 if (!rdev->ops->crit_proto_stop)
9900 return -EOPNOTSUPP;
9901
9902 if (rdev->crit_proto_nlportid) {
9903 rdev->crit_proto_nlportid = 0;
9904 rdev_crit_proto_stop(rdev, wdev);
9905 }
9906 return 0;
9907}
9908
Johannes Bergad7e7182013-11-13 13:37:47 +01009909static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9910{
9911 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9912 struct wireless_dev *wdev =
9913 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9914 int i, err;
9915 u32 vid, subcmd;
9916
9917 if (!rdev->wiphy.vendor_commands)
9918 return -EOPNOTSUPP;
9919
9920 if (IS_ERR(wdev)) {
9921 err = PTR_ERR(wdev);
9922 if (err != -EINVAL)
9923 return err;
9924 wdev = NULL;
9925 } else if (wdev->wiphy != &rdev->wiphy) {
9926 return -EINVAL;
9927 }
9928
9929 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9930 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9931 return -EINVAL;
9932
9933 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9934 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9935 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9936 const struct wiphy_vendor_command *vcmd;
9937 void *data = NULL;
9938 int len = 0;
9939
9940 vcmd = &rdev->wiphy.vendor_commands[i];
9941
9942 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9943 continue;
9944
9945 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9946 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9947 if (!wdev)
9948 return -EINVAL;
9949 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9950 !wdev->netdev)
9951 return -EINVAL;
9952
9953 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9954 if (wdev->netdev &&
9955 !netif_running(wdev->netdev))
9956 return -ENETDOWN;
9957 if (!wdev->netdev && !wdev->p2p_started)
9958 return -ENETDOWN;
9959 }
Johannes Berg7bdbe402015-08-15 22:39:49 +03009960
9961 if (!vcmd->doit)
9962 return -EOPNOTSUPP;
Johannes Bergad7e7182013-11-13 13:37:47 +01009963 } else {
9964 wdev = NULL;
9965 }
9966
9967 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9968 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9969 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9970 }
9971
9972 rdev->cur_cmd_info = info;
9973 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9974 data, len);
9975 rdev->cur_cmd_info = NULL;
9976 return err;
9977 }
9978
9979 return -EOPNOTSUPP;
9980}
9981
Johannes Berg7bdbe402015-08-15 22:39:49 +03009982static int nl80211_prepare_vendor_dump(struct sk_buff *skb,
9983 struct netlink_callback *cb,
9984 struct cfg80211_registered_device **rdev,
9985 struct wireless_dev **wdev)
9986{
9987 u32 vid, subcmd;
9988 unsigned int i;
9989 int vcmd_idx = -1;
9990 int err;
9991 void *data = NULL;
9992 unsigned int data_len = 0;
9993
9994 rtnl_lock();
9995
9996 if (cb->args[0]) {
9997 /* subtract the 1 again here */
9998 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
9999 struct wireless_dev *tmp;
10000
10001 if (!wiphy) {
10002 err = -ENODEV;
10003 goto out_unlock;
10004 }
10005 *rdev = wiphy_to_rdev(wiphy);
10006 *wdev = NULL;
10007
10008 if (cb->args[1]) {
10009 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
10010 if (tmp->identifier == cb->args[1] - 1) {
10011 *wdev = tmp;
10012 break;
10013 }
10014 }
10015 }
10016
10017 /* keep rtnl locked in successful case */
10018 return 0;
10019 }
10020
10021 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
10022 nl80211_fam.attrbuf, nl80211_fam.maxattr,
10023 nl80211_policy);
10024 if (err)
10025 goto out_unlock;
10026
10027 if (!nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID] ||
10028 !nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]) {
10029 err = -EINVAL;
10030 goto out_unlock;
10031 }
10032
10033 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
10034 nl80211_fam.attrbuf);
10035 if (IS_ERR(*wdev))
10036 *wdev = NULL;
10037
10038 *rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
10039 nl80211_fam.attrbuf);
10040 if (IS_ERR(*rdev)) {
10041 err = PTR_ERR(*rdev);
10042 goto out_unlock;
10043 }
10044
10045 vid = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_ID]);
10046 subcmd = nla_get_u32(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_SUBCMD]);
10047
10048 for (i = 0; i < (*rdev)->wiphy.n_vendor_commands; i++) {
10049 const struct wiphy_vendor_command *vcmd;
10050
10051 vcmd = &(*rdev)->wiphy.vendor_commands[i];
10052
10053 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
10054 continue;
10055
10056 if (!vcmd->dumpit) {
10057 err = -EOPNOTSUPP;
10058 goto out_unlock;
10059 }
10060
10061 vcmd_idx = i;
10062 break;
10063 }
10064
10065 if (vcmd_idx < 0) {
10066 err = -EOPNOTSUPP;
10067 goto out_unlock;
10068 }
10069
10070 if (nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]) {
10071 data = nla_data(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10072 data_len = nla_len(nl80211_fam.attrbuf[NL80211_ATTR_VENDOR_DATA]);
10073 }
10074
10075 /* 0 is the first index - add 1 to parse only once */
10076 cb->args[0] = (*rdev)->wiphy_idx + 1;
10077 /* add 1 to know if it was NULL */
10078 cb->args[1] = *wdev ? (*wdev)->identifier + 1 : 0;
10079 cb->args[2] = vcmd_idx;
10080 cb->args[3] = (unsigned long)data;
10081 cb->args[4] = data_len;
10082
10083 /* keep rtnl locked in successful case */
10084 return 0;
10085 out_unlock:
10086 rtnl_unlock();
10087 return err;
10088}
10089
10090static int nl80211_vendor_cmd_dump(struct sk_buff *skb,
10091 struct netlink_callback *cb)
10092{
10093 struct cfg80211_registered_device *rdev;
10094 struct wireless_dev *wdev;
10095 unsigned int vcmd_idx;
10096 const struct wiphy_vendor_command *vcmd;
10097 void *data;
10098 int data_len;
10099 int err;
10100 struct nlattr *vendor_data;
10101
10102 err = nl80211_prepare_vendor_dump(skb, cb, &rdev, &wdev);
10103 if (err)
10104 return err;
10105
10106 vcmd_idx = cb->args[2];
10107 data = (void *)cb->args[3];
10108 data_len = cb->args[4];
10109 vcmd = &rdev->wiphy.vendor_commands[vcmd_idx];
10110
10111 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
10112 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
10113 if (!wdev)
10114 return -EINVAL;
10115 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
10116 !wdev->netdev)
10117 return -EINVAL;
10118
10119 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
10120 if (wdev->netdev &&
10121 !netif_running(wdev->netdev))
10122 return -ENETDOWN;
10123 if (!wdev->netdev && !wdev->p2p_started)
10124 return -ENETDOWN;
10125 }
10126 }
10127
10128 while (1) {
10129 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
10130 cb->nlh->nlmsg_seq, NLM_F_MULTI,
10131 NL80211_CMD_VENDOR);
10132 if (!hdr)
10133 break;
10134
10135 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10136 (wdev && nla_put_u64(skb, NL80211_ATTR_WDEV,
10137 wdev_id(wdev)))) {
10138 genlmsg_cancel(skb, hdr);
10139 break;
10140 }
10141
10142 vendor_data = nla_nest_start(skb, NL80211_ATTR_VENDOR_DATA);
10143 if (!vendor_data) {
10144 genlmsg_cancel(skb, hdr);
10145 break;
10146 }
10147
10148 err = vcmd->dumpit(&rdev->wiphy, wdev, skb, data, data_len,
10149 (unsigned long *)&cb->args[5]);
10150 nla_nest_end(skb, vendor_data);
10151
10152 if (err == -ENOBUFS || err == -ENOENT) {
10153 genlmsg_cancel(skb, hdr);
10154 break;
10155 } else if (err) {
10156 genlmsg_cancel(skb, hdr);
10157 goto out;
10158 }
10159
10160 genlmsg_end(skb, hdr);
10161 }
10162
10163 err = skb->len;
10164 out:
10165 rtnl_unlock();
10166 return err;
10167}
10168
Johannes Bergad7e7182013-11-13 13:37:47 +010010169struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
10170 enum nl80211_commands cmd,
10171 enum nl80211_attrs attr,
10172 int approxlen)
10173{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010174 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +010010175
10176 if (WARN_ON(!rdev->cur_cmd_info))
10177 return NULL;
10178
Ahmad Kholaif6c09e792015-02-26 15:26:53 +020010179 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +010010180 rdev->cur_cmd_info->snd_portid,
10181 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +010010182 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +010010183}
10184EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
10185
10186int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
10187{
10188 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
10189 void *hdr = ((void **)skb->cb)[1];
10190 struct nlattr *data = ((void **)skb->cb)[2];
10191
Johannes Bergbd8c78e2014-07-30 14:55:26 +020010192 /* clear CB data for netlink core to own from now on */
10193 memset(skb->cb, 0, sizeof(skb->cb));
10194
Johannes Bergad7e7182013-11-13 13:37:47 +010010195 if (WARN_ON(!rdev->cur_cmd_info)) {
10196 kfree_skb(skb);
10197 return -EINVAL;
10198 }
10199
10200 nla_nest_end(skb, data);
10201 genlmsg_end(skb, hdr);
10202 return genlmsg_reply(skb, rdev->cur_cmd_info);
10203}
10204EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
10205
10206
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010207static int nl80211_set_qos_map(struct sk_buff *skb,
10208 struct genl_info *info)
10209{
10210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10211 struct cfg80211_qos_map *qos_map = NULL;
10212 struct net_device *dev = info->user_ptr[1];
10213 u8 *pos, len, num_des, des_len, des;
10214 int ret;
10215
10216 if (!rdev->ops->set_qos_map)
10217 return -EOPNOTSUPP;
10218
10219 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10220 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10221 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10222
10223 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10224 len > IEEE80211_QOS_MAP_LEN_MAX)
10225 return -EINVAL;
10226
10227 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10228 if (!qos_map)
10229 return -ENOMEM;
10230
10231 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10232 if (num_des) {
10233 des_len = num_des *
10234 sizeof(struct cfg80211_dscp_exception);
10235 memcpy(qos_map->dscp_exception, pos, des_len);
10236 qos_map->num_des = num_des;
10237 for (des = 0; des < num_des; des++) {
10238 if (qos_map->dscp_exception[des].up > 7) {
10239 kfree(qos_map);
10240 return -EINVAL;
10241 }
10242 }
10243 pos += des_len;
10244 }
10245 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10246 }
10247
10248 wdev_lock(dev->ieee80211_ptr);
10249 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10250 if (!ret)
10251 ret = rdev_set_qos_map(rdev, dev, qos_map);
10252 wdev_unlock(dev->ieee80211_ptr);
10253
10254 kfree(qos_map);
10255 return ret;
10256}
10257
Johannes Berg960d01a2014-09-09 22:55:35 +030010258static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10259{
10260 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10261 struct net_device *dev = info->user_ptr[1];
10262 struct wireless_dev *wdev = dev->ieee80211_ptr;
10263 const u8 *peer;
10264 u8 tsid, up;
10265 u16 admitted_time = 0;
10266 int err;
10267
Johannes Berg723e73a2014-10-22 09:25:06 +020010268 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010269 return -EOPNOTSUPP;
10270
10271 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10272 !info->attrs[NL80211_ATTR_USER_PRIO])
10273 return -EINVAL;
10274
10275 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10276 if (tsid >= IEEE80211_NUM_TIDS)
10277 return -EINVAL;
10278
10279 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10280 if (up >= IEEE80211_NUM_UPS)
10281 return -EINVAL;
10282
10283 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010284 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010285 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010286 * need more attributes for that (e.g. BA session requirement);
10287 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010288 */
10289 return -EINVAL;
10290 }
10291
10292 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10293
10294 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10295 admitted_time =
10296 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10297 if (!admitted_time)
10298 return -EINVAL;
10299 }
10300
10301 wdev_lock(wdev);
10302 switch (wdev->iftype) {
10303 case NL80211_IFTYPE_STATION:
10304 case NL80211_IFTYPE_P2P_CLIENT:
10305 if (wdev->current_bss)
10306 break;
10307 err = -ENOTCONN;
10308 goto out;
10309 default:
10310 err = -EOPNOTSUPP;
10311 goto out;
10312 }
10313
10314 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10315
10316 out:
10317 wdev_unlock(wdev);
10318 return err;
10319}
10320
10321static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10322{
10323 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10324 struct net_device *dev = info->user_ptr[1];
10325 struct wireless_dev *wdev = dev->ieee80211_ptr;
10326 const u8 *peer;
10327 u8 tsid;
10328 int err;
10329
10330 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10331 return -EINVAL;
10332
10333 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10334 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10335
10336 wdev_lock(wdev);
10337 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10338 wdev_unlock(wdev);
10339
10340 return err;
10341}
10342
Arik Nemtsov1057d352014-11-19 12:54:26 +020010343static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10344 struct genl_info *info)
10345{
10346 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10347 struct net_device *dev = info->user_ptr[1];
10348 struct wireless_dev *wdev = dev->ieee80211_ptr;
10349 struct cfg80211_chan_def chandef = {};
10350 const u8 *addr;
10351 u8 oper_class;
10352 int err;
10353
10354 if (!rdev->ops->tdls_channel_switch ||
10355 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10356 return -EOPNOTSUPP;
10357
10358 switch (dev->ieee80211_ptr->iftype) {
10359 case NL80211_IFTYPE_STATION:
10360 case NL80211_IFTYPE_P2P_CLIENT:
10361 break;
10362 default:
10363 return -EOPNOTSUPP;
10364 }
10365
10366 if (!info->attrs[NL80211_ATTR_MAC] ||
10367 !info->attrs[NL80211_ATTR_OPER_CLASS])
10368 return -EINVAL;
10369
10370 err = nl80211_parse_chandef(rdev, info, &chandef);
10371 if (err)
10372 return err;
10373
10374 /*
10375 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10376 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10377 * specification is not defined for them.
10378 */
10379 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10380 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10381 chandef.width != NL80211_CHAN_WIDTH_20)
10382 return -EINVAL;
10383
10384 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010385 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10386 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010387 return -EINVAL;
10388
10389 /* don't allow switching to DFS channels */
10390 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10391 return -EINVAL;
10392
10393 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10394 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10395
10396 wdev_lock(wdev);
10397 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10398 wdev_unlock(wdev);
10399
10400 return err;
10401}
10402
10403static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10404 struct genl_info *info)
10405{
10406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10407 struct net_device *dev = info->user_ptr[1];
10408 struct wireless_dev *wdev = dev->ieee80211_ptr;
10409 const u8 *addr;
10410
10411 if (!rdev->ops->tdls_channel_switch ||
10412 !rdev->ops->tdls_cancel_channel_switch ||
10413 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10414 return -EOPNOTSUPP;
10415
10416 switch (dev->ieee80211_ptr->iftype) {
10417 case NL80211_IFTYPE_STATION:
10418 case NL80211_IFTYPE_P2P_CLIENT:
10419 break;
10420 default:
10421 return -EOPNOTSUPP;
10422 }
10423
10424 if (!info->attrs[NL80211_ATTR_MAC])
10425 return -EINVAL;
10426
10427 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10428
10429 wdev_lock(wdev);
10430 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10431 wdev_unlock(wdev);
10432
10433 return 0;
10434}
10435
Johannes Berg4c476992010-10-04 21:36:35 +020010436#define NL80211_FLAG_NEED_WIPHY 0x01
10437#define NL80211_FLAG_NEED_NETDEV 0x02
10438#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010439#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10440#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10441 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010442#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010443/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010444#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10445 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010446#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010447
Johannes Bergf84f7712013-11-14 17:14:45 +010010448static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010449 struct genl_info *info)
10450{
10451 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010452 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010453 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010454 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10455
10456 if (rtnl)
10457 rtnl_lock();
10458
10459 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010460 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010461 if (IS_ERR(rdev)) {
10462 if (rtnl)
10463 rtnl_unlock();
10464 return PTR_ERR(rdev);
10465 }
10466 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010467 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10468 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010469 ASSERT_RTNL();
10470
Johannes Berg89a54e42012-06-15 14:33:17 +020010471 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10472 info->attrs);
10473 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010474 if (rtnl)
10475 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010476 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010477 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010478
Johannes Berg89a54e42012-06-15 14:33:17 +020010479 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010480 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010481
Johannes Berg1bf614e2012-06-15 15:23:36 +020010482 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10483 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010484 if (rtnl)
10485 rtnl_unlock();
10486 return -EINVAL;
10487 }
10488
10489 info->user_ptr[1] = dev;
10490 } else {
10491 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010492 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010493
Johannes Berg1bf614e2012-06-15 15:23:36 +020010494 if (dev) {
10495 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10496 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010497 if (rtnl)
10498 rtnl_unlock();
10499 return -ENETDOWN;
10500 }
10501
10502 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010503 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10504 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010505 if (rtnl)
10506 rtnl_unlock();
10507 return -ENETDOWN;
10508 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010509 }
10510
Johannes Berg4c476992010-10-04 21:36:35 +020010511 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010512 }
10513
10514 return 0;
10515}
10516
Johannes Bergf84f7712013-11-14 17:14:45 +010010517static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010518 struct genl_info *info)
10519{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010520 if (info->user_ptr[1]) {
10521 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10522 struct wireless_dev *wdev = info->user_ptr[1];
10523
10524 if (wdev->netdev)
10525 dev_put(wdev->netdev);
10526 } else {
10527 dev_put(info->user_ptr[1]);
10528 }
10529 }
Johannes Berg5393b912014-09-10 15:00:16 +030010530
Johannes Berg4c476992010-10-04 21:36:35 +020010531 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10532 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010533
10534 /* If needed, clear the netlink message payload from the SKB
10535 * as it might contain key data that shouldn't stick around on
10536 * the heap after the SKB is freed. The netlink message header
10537 * is still needed for further processing, so leave it intact.
10538 */
10539 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10540 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10541
10542 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10543 }
Johannes Berg4c476992010-10-04 21:36:35 +020010544}
10545
Johannes Berg4534de82013-11-14 17:14:46 +010010546static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010547 {
10548 .cmd = NL80211_CMD_GET_WIPHY,
10549 .doit = nl80211_get_wiphy,
10550 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010551 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010552 .policy = nl80211_policy,
10553 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010554 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10555 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010556 },
10557 {
10558 .cmd = NL80211_CMD_SET_WIPHY,
10559 .doit = nl80211_set_wiphy,
10560 .policy = nl80211_policy,
10561 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010562 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010563 },
10564 {
10565 .cmd = NL80211_CMD_GET_INTERFACE,
10566 .doit = nl80211_get_interface,
10567 .dumpit = nl80211_dump_interface,
10568 .policy = nl80211_policy,
10569 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010570 .internal_flags = NL80211_FLAG_NEED_WDEV |
10571 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010572 },
10573 {
10574 .cmd = NL80211_CMD_SET_INTERFACE,
10575 .doit = nl80211_set_interface,
10576 .policy = nl80211_policy,
10577 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010578 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10579 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010580 },
10581 {
10582 .cmd = NL80211_CMD_NEW_INTERFACE,
10583 .doit = nl80211_new_interface,
10584 .policy = nl80211_policy,
10585 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010586 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10587 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010588 },
10589 {
10590 .cmd = NL80211_CMD_DEL_INTERFACE,
10591 .doit = nl80211_del_interface,
10592 .policy = nl80211_policy,
10593 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010594 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010595 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010596 },
Johannes Berg41ade002007-12-19 02:03:29 +010010597 {
10598 .cmd = NL80211_CMD_GET_KEY,
10599 .doit = nl80211_get_key,
10600 .policy = nl80211_policy,
10601 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010602 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010603 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010604 },
10605 {
10606 .cmd = NL80211_CMD_SET_KEY,
10607 .doit = nl80211_set_key,
10608 .policy = nl80211_policy,
10609 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010611 NL80211_FLAG_NEED_RTNL |
10612 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010613 },
10614 {
10615 .cmd = NL80211_CMD_NEW_KEY,
10616 .doit = nl80211_new_key,
10617 .policy = nl80211_policy,
10618 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010619 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010620 NL80211_FLAG_NEED_RTNL |
10621 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010622 },
10623 {
10624 .cmd = NL80211_CMD_DEL_KEY,
10625 .doit = nl80211_del_key,
10626 .policy = nl80211_policy,
10627 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010628 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010629 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010630 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010631 {
10632 .cmd = NL80211_CMD_SET_BEACON,
10633 .policy = nl80211_policy,
10634 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010635 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010636 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010637 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010638 },
10639 {
Johannes Berg88600202012-02-13 15:17:18 +010010640 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010641 .policy = nl80211_policy,
10642 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010643 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010644 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010645 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010646 },
10647 {
Johannes Berg88600202012-02-13 15:17:18 +010010648 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010649 .policy = nl80211_policy,
10650 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010651 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010652 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010653 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010654 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010655 {
10656 .cmd = NL80211_CMD_GET_STATION,
10657 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010658 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010659 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010660 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10661 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010662 },
10663 {
10664 .cmd = NL80211_CMD_SET_STATION,
10665 .doit = nl80211_set_station,
10666 .policy = nl80211_policy,
10667 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010668 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010669 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010670 },
10671 {
10672 .cmd = NL80211_CMD_NEW_STATION,
10673 .doit = nl80211_new_station,
10674 .policy = nl80211_policy,
10675 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010676 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010677 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010678 },
10679 {
10680 .cmd = NL80211_CMD_DEL_STATION,
10681 .doit = nl80211_del_station,
10682 .policy = nl80211_policy,
10683 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010684 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010685 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010686 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010687 {
10688 .cmd = NL80211_CMD_GET_MPATH,
10689 .doit = nl80211_get_mpath,
10690 .dumpit = nl80211_dump_mpath,
10691 .policy = nl80211_policy,
10692 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010693 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010694 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010695 },
10696 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010697 .cmd = NL80211_CMD_GET_MPP,
10698 .doit = nl80211_get_mpp,
10699 .dumpit = nl80211_dump_mpp,
10700 .policy = nl80211_policy,
10701 .flags = GENL_ADMIN_PERM,
10702 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10703 NL80211_FLAG_NEED_RTNL,
10704 },
10705 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010706 .cmd = NL80211_CMD_SET_MPATH,
10707 .doit = nl80211_set_mpath,
10708 .policy = nl80211_policy,
10709 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010710 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010711 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010712 },
10713 {
10714 .cmd = NL80211_CMD_NEW_MPATH,
10715 .doit = nl80211_new_mpath,
10716 .policy = nl80211_policy,
10717 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010718 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010719 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010720 },
10721 {
10722 .cmd = NL80211_CMD_DEL_MPATH,
10723 .doit = nl80211_del_mpath,
10724 .policy = nl80211_policy,
10725 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010726 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010727 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010728 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010729 {
10730 .cmd = NL80211_CMD_SET_BSS,
10731 .doit = nl80211_set_bss,
10732 .policy = nl80211_policy,
10733 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010734 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010735 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010736 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010737 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010738 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010739 .doit = nl80211_get_reg_do,
10740 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010741 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010742 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010743 /* can be retrieved by unprivileged users */
10744 },
10745 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010746 .cmd = NL80211_CMD_SET_REG,
10747 .doit = nl80211_set_reg,
10748 .policy = nl80211_policy,
10749 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010750 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010751 },
10752 {
10753 .cmd = NL80211_CMD_REQ_SET_REG,
10754 .doit = nl80211_req_set_reg,
10755 .policy = nl80211_policy,
10756 .flags = GENL_ADMIN_PERM,
10757 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010758 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010759 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10760 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010761 .policy = nl80211_policy,
10762 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010763 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010764 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010765 },
10766 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010767 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10768 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010769 .policy = nl80211_policy,
10770 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010771 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010772 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010773 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010774 {
Johannes Berg2a519312009-02-10 21:25:55 +010010775 .cmd = NL80211_CMD_TRIGGER_SCAN,
10776 .doit = nl80211_trigger_scan,
10777 .policy = nl80211_policy,
10778 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010779 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010780 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010781 },
10782 {
10783 .cmd = NL80211_CMD_GET_SCAN,
10784 .policy = nl80211_policy,
10785 .dumpit = nl80211_dump_scan,
10786 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010787 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010788 .cmd = NL80211_CMD_START_SCHED_SCAN,
10789 .doit = nl80211_start_sched_scan,
10790 .policy = nl80211_policy,
10791 .flags = GENL_ADMIN_PERM,
10792 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10793 NL80211_FLAG_NEED_RTNL,
10794 },
10795 {
10796 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10797 .doit = nl80211_stop_sched_scan,
10798 .policy = nl80211_policy,
10799 .flags = GENL_ADMIN_PERM,
10800 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10801 NL80211_FLAG_NEED_RTNL,
10802 },
10803 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010804 .cmd = NL80211_CMD_AUTHENTICATE,
10805 .doit = nl80211_authenticate,
10806 .policy = nl80211_policy,
10807 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010808 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010809 NL80211_FLAG_NEED_RTNL |
10810 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010811 },
10812 {
10813 .cmd = NL80211_CMD_ASSOCIATE,
10814 .doit = nl80211_associate,
10815 .policy = nl80211_policy,
10816 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010817 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010818 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010819 },
10820 {
10821 .cmd = NL80211_CMD_DEAUTHENTICATE,
10822 .doit = nl80211_deauthenticate,
10823 .policy = nl80211_policy,
10824 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010825 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010826 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010827 },
10828 {
10829 .cmd = NL80211_CMD_DISASSOCIATE,
10830 .doit = nl80211_disassociate,
10831 .policy = nl80211_policy,
10832 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010833 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010834 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010835 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010836 {
10837 .cmd = NL80211_CMD_JOIN_IBSS,
10838 .doit = nl80211_join_ibss,
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 Berg04a773a2009-04-19 21:24:32 +020010843 },
10844 {
10845 .cmd = NL80211_CMD_LEAVE_IBSS,
10846 .doit = nl80211_leave_ibss,
10847 .policy = nl80211_policy,
10848 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010849 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010850 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010851 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010852#ifdef CONFIG_NL80211_TESTMODE
10853 {
10854 .cmd = NL80211_CMD_TESTMODE,
10855 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010856 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010857 .policy = nl80211_policy,
10858 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010859 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10860 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010861 },
10862#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010863 {
10864 .cmd = NL80211_CMD_CONNECT,
10865 .doit = nl80211_connect,
10866 .policy = nl80211_policy,
10867 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010868 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010869 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010870 },
10871 {
10872 .cmd = NL80211_CMD_DISCONNECT,
10873 .doit = nl80211_disconnect,
10874 .policy = nl80211_policy,
10875 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010876 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010877 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010878 },
Johannes Berg463d0182009-07-14 00:33:35 +020010879 {
10880 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10881 .doit = nl80211_wiphy_netns,
10882 .policy = nl80211_policy,
10883 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010884 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10885 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010886 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010887 {
10888 .cmd = NL80211_CMD_GET_SURVEY,
10889 .policy = nl80211_policy,
10890 .dumpit = nl80211_dump_survey,
10891 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010892 {
10893 .cmd = NL80211_CMD_SET_PMKSA,
10894 .doit = nl80211_setdel_pmksa,
10895 .policy = nl80211_policy,
10896 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010897 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010898 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010899 },
10900 {
10901 .cmd = NL80211_CMD_DEL_PMKSA,
10902 .doit = nl80211_setdel_pmksa,
10903 .policy = nl80211_policy,
10904 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010905 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010906 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010907 },
10908 {
10909 .cmd = NL80211_CMD_FLUSH_PMKSA,
10910 .doit = nl80211_flush_pmksa,
10911 .policy = nl80211_policy,
10912 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010913 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010914 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010915 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010916 {
10917 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10918 .doit = nl80211_remain_on_channel,
10919 .policy = nl80211_policy,
10920 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010921 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010922 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010923 },
10924 {
10925 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10926 .doit = nl80211_cancel_remain_on_channel,
10927 .policy = nl80211_policy,
10928 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010929 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010930 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010931 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010932 {
10933 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10934 .doit = nl80211_set_tx_bitrate_mask,
10935 .policy = nl80211_policy,
10936 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010937 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10938 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010939 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010940 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010941 .cmd = NL80211_CMD_REGISTER_FRAME,
10942 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010943 .policy = nl80211_policy,
10944 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010945 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010946 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010947 },
10948 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010949 .cmd = NL80211_CMD_FRAME,
10950 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010951 .policy = nl80211_policy,
10952 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010953 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010954 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010955 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010956 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010957 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10958 .doit = nl80211_tx_mgmt_cancel_wait,
10959 .policy = nl80211_policy,
10960 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010961 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010962 NL80211_FLAG_NEED_RTNL,
10963 },
10964 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010965 .cmd = NL80211_CMD_SET_POWER_SAVE,
10966 .doit = nl80211_set_power_save,
10967 .policy = nl80211_policy,
10968 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010969 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10970 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010971 },
10972 {
10973 .cmd = NL80211_CMD_GET_POWER_SAVE,
10974 .doit = nl80211_get_power_save,
10975 .policy = nl80211_policy,
10976 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010977 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10978 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010979 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010980 {
10981 .cmd = NL80211_CMD_SET_CQM,
10982 .doit = nl80211_set_cqm,
10983 .policy = nl80211_policy,
10984 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010985 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10986 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010987 },
Johannes Bergf444de02010-05-05 15:25:02 +020010988 {
10989 .cmd = NL80211_CMD_SET_CHANNEL,
10990 .doit = nl80211_set_channel,
10991 .policy = nl80211_policy,
10992 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010993 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10994 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010995 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010996 {
10997 .cmd = NL80211_CMD_SET_WDS_PEER,
10998 .doit = nl80211_set_wds_peer,
10999 .policy = nl80211_policy,
11000 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020011001 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11002 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040011003 },
Johannes Berg29cbe682010-12-03 09:20:44 +010011004 {
11005 .cmd = NL80211_CMD_JOIN_MESH,
11006 .doit = nl80211_join_mesh,
11007 .policy = nl80211_policy,
11008 .flags = GENL_ADMIN_PERM,
11009 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11010 NL80211_FLAG_NEED_RTNL,
11011 },
11012 {
11013 .cmd = NL80211_CMD_LEAVE_MESH,
11014 .doit = nl80211_leave_mesh,
11015 .policy = nl80211_policy,
11016 .flags = GENL_ADMIN_PERM,
11017 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11018 NL80211_FLAG_NEED_RTNL,
11019 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010011020 {
11021 .cmd = NL80211_CMD_JOIN_OCB,
11022 .doit = nl80211_join_ocb,
11023 .policy = nl80211_policy,
11024 .flags = GENL_ADMIN_PERM,
11025 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11026 NL80211_FLAG_NEED_RTNL,
11027 },
11028 {
11029 .cmd = NL80211_CMD_LEAVE_OCB,
11030 .doit = nl80211_leave_ocb,
11031 .policy = nl80211_policy,
11032 .flags = GENL_ADMIN_PERM,
11033 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11034 NL80211_FLAG_NEED_RTNL,
11035 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011036#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020011037 {
11038 .cmd = NL80211_CMD_GET_WOWLAN,
11039 .doit = nl80211_get_wowlan,
11040 .policy = nl80211_policy,
11041 /* can be retrieved by unprivileged users */
11042 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11043 NL80211_FLAG_NEED_RTNL,
11044 },
11045 {
11046 .cmd = NL80211_CMD_SET_WOWLAN,
11047 .doit = nl80211_set_wowlan,
11048 .policy = nl80211_policy,
11049 .flags = GENL_ADMIN_PERM,
11050 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11051 NL80211_FLAG_NEED_RTNL,
11052 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020011053#endif
Johannes Berge5497d72011-07-05 16:35:40 +020011054 {
11055 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
11056 .doit = nl80211_set_rekey_data,
11057 .policy = nl80211_policy,
11058 .flags = GENL_ADMIN_PERM,
11059 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030011060 NL80211_FLAG_NEED_RTNL |
11061 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020011062 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030011063 {
11064 .cmd = NL80211_CMD_TDLS_MGMT,
11065 .doit = nl80211_tdls_mgmt,
11066 .policy = nl80211_policy,
11067 .flags = GENL_ADMIN_PERM,
11068 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11069 NL80211_FLAG_NEED_RTNL,
11070 },
11071 {
11072 .cmd = NL80211_CMD_TDLS_OPER,
11073 .doit = nl80211_tdls_oper,
11074 .policy = nl80211_policy,
11075 .flags = GENL_ADMIN_PERM,
11076 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11077 NL80211_FLAG_NEED_RTNL,
11078 },
Johannes Berg28946da2011-11-04 11:18:12 +010011079 {
11080 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
11081 .doit = nl80211_register_unexpected_frame,
11082 .policy = nl80211_policy,
11083 .flags = GENL_ADMIN_PERM,
11084 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11085 NL80211_FLAG_NEED_RTNL,
11086 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010011087 {
11088 .cmd = NL80211_CMD_PROBE_CLIENT,
11089 .doit = nl80211_probe_client,
11090 .policy = nl80211_policy,
11091 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020011092 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010011093 NL80211_FLAG_NEED_RTNL,
11094 },
Johannes Berg5e760232011-11-04 11:18:17 +010011095 {
11096 .cmd = NL80211_CMD_REGISTER_BEACONS,
11097 .doit = nl80211_register_beacons,
11098 .policy = nl80211_policy,
11099 .flags = GENL_ADMIN_PERM,
11100 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11101 NL80211_FLAG_NEED_RTNL,
11102 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010011103 {
11104 .cmd = NL80211_CMD_SET_NOACK_MAP,
11105 .doit = nl80211_set_noack_map,
11106 .policy = nl80211_policy,
11107 .flags = GENL_ADMIN_PERM,
11108 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11109 NL80211_FLAG_NEED_RTNL,
11110 },
Johannes Berg98104fde2012-06-16 00:19:54 +020011111 {
11112 .cmd = NL80211_CMD_START_P2P_DEVICE,
11113 .doit = nl80211_start_p2p_device,
11114 .policy = nl80211_policy,
11115 .flags = GENL_ADMIN_PERM,
11116 .internal_flags = NL80211_FLAG_NEED_WDEV |
11117 NL80211_FLAG_NEED_RTNL,
11118 },
11119 {
11120 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
11121 .doit = nl80211_stop_p2p_device,
11122 .policy = nl80211_policy,
11123 .flags = GENL_ADMIN_PERM,
11124 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11125 NL80211_FLAG_NEED_RTNL,
11126 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010011127 {
11128 .cmd = NL80211_CMD_SET_MCAST_RATE,
11129 .doit = nl80211_set_mcast_rate,
11130 .policy = nl80211_policy,
11131 .flags = GENL_ADMIN_PERM,
11132 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11133 NL80211_FLAG_NEED_RTNL,
11134 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053011135 {
11136 .cmd = NL80211_CMD_SET_MAC_ACL,
11137 .doit = nl80211_set_mac_acl,
11138 .policy = nl80211_policy,
11139 .flags = GENL_ADMIN_PERM,
11140 .internal_flags = NL80211_FLAG_NEED_NETDEV |
11141 NL80211_FLAG_NEED_RTNL,
11142 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010011143 {
11144 .cmd = NL80211_CMD_RADAR_DETECT,
11145 .doit = nl80211_start_radar_detection,
11146 .policy = nl80211_policy,
11147 .flags = GENL_ADMIN_PERM,
11148 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11149 NL80211_FLAG_NEED_RTNL,
11150 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010011151 {
11152 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
11153 .doit = nl80211_get_protocol_features,
11154 .policy = nl80211_policy,
11155 },
Jouni Malinen355199e2013-02-27 17:14:27 +020011156 {
11157 .cmd = NL80211_CMD_UPDATE_FT_IES,
11158 .doit = nl80211_update_ft_ies,
11159 .policy = nl80211_policy,
11160 .flags = GENL_ADMIN_PERM,
11161 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11162 NL80211_FLAG_NEED_RTNL,
11163 },
Arend van Spriel5de17982013-04-18 15:49:00 +020011164 {
11165 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
11166 .doit = nl80211_crit_protocol_start,
11167 .policy = nl80211_policy,
11168 .flags = GENL_ADMIN_PERM,
11169 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11170 NL80211_FLAG_NEED_RTNL,
11171 },
11172 {
11173 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
11174 .doit = nl80211_crit_protocol_stop,
11175 .policy = nl80211_policy,
11176 .flags = GENL_ADMIN_PERM,
11177 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
11178 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070011179 },
11180 {
11181 .cmd = NL80211_CMD_GET_COALESCE,
11182 .doit = nl80211_get_coalesce,
11183 .policy = nl80211_policy,
11184 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11185 NL80211_FLAG_NEED_RTNL,
11186 },
11187 {
11188 .cmd = NL80211_CMD_SET_COALESCE,
11189 .doit = nl80211_set_coalesce,
11190 .policy = nl80211_policy,
11191 .flags = GENL_ADMIN_PERM,
11192 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11193 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020011194 },
11195 {
11196 .cmd = NL80211_CMD_CHANNEL_SWITCH,
11197 .doit = nl80211_channel_switch,
11198 .policy = nl80211_policy,
11199 .flags = GENL_ADMIN_PERM,
11200 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11201 NL80211_FLAG_NEED_RTNL,
11202 },
Johannes Bergad7e7182013-11-13 13:37:47 +010011203 {
11204 .cmd = NL80211_CMD_VENDOR,
11205 .doit = nl80211_vendor_cmd,
Johannes Berg7bdbe402015-08-15 22:39:49 +030011206 .dumpit = nl80211_vendor_cmd_dump,
Johannes Bergad7e7182013-11-13 13:37:47 +010011207 .policy = nl80211_policy,
11208 .flags = GENL_ADMIN_PERM,
11209 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11210 NL80211_FLAG_NEED_RTNL,
11211 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011212 {
11213 .cmd = NL80211_CMD_SET_QOS_MAP,
11214 .doit = nl80211_set_qos_map,
11215 .policy = nl80211_policy,
11216 .flags = GENL_ADMIN_PERM,
11217 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11218 NL80211_FLAG_NEED_RTNL,
11219 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011220 {
11221 .cmd = NL80211_CMD_ADD_TX_TS,
11222 .doit = nl80211_add_tx_ts,
11223 .policy = nl80211_policy,
11224 .flags = GENL_ADMIN_PERM,
11225 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11226 NL80211_FLAG_NEED_RTNL,
11227 },
11228 {
11229 .cmd = NL80211_CMD_DEL_TX_TS,
11230 .doit = nl80211_del_tx_ts,
11231 .policy = nl80211_policy,
11232 .flags = GENL_ADMIN_PERM,
11233 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11234 NL80211_FLAG_NEED_RTNL,
11235 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011236 {
11237 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11238 .doit = nl80211_tdls_channel_switch,
11239 .policy = nl80211_policy,
11240 .flags = GENL_ADMIN_PERM,
11241 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11242 NL80211_FLAG_NEED_RTNL,
11243 },
11244 {
11245 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11246 .doit = nl80211_tdls_cancel_channel_switch,
11247 .policy = nl80211_policy,
11248 .flags = GENL_ADMIN_PERM,
11249 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11250 NL80211_FLAG_NEED_RTNL,
11251 },
Johannes Berg55682962007-09-20 13:09:35 -040011252};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011253
Johannes Berg55682962007-09-20 13:09:35 -040011254/* notification functions */
11255
Johannes Berg3bb20552014-05-26 13:52:25 +020011256void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11257 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011258{
11259 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011260 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011261
Johannes Berg3bb20552014-05-26 13:52:25 +020011262 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11263 cmd != NL80211_CMD_DEL_WIPHY);
11264
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011265 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011266 if (!msg)
11267 return;
11268
Johannes Berg3bb20552014-05-26 13:52:25 +020011269 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011270 nlmsg_free(msg);
11271 return;
11272 }
11273
Johannes Berg68eb5502013-11-19 15:19:38 +010011274 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011275 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011276}
11277
Johannes Berg362a4152009-05-24 16:43:15 +020011278static int nl80211_add_scan_req(struct sk_buff *msg,
11279 struct cfg80211_registered_device *rdev)
11280{
11281 struct cfg80211_scan_request *req = rdev->scan_req;
11282 struct nlattr *nest;
11283 int i;
11284
11285 if (WARN_ON(!req))
11286 return 0;
11287
11288 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11289 if (!nest)
11290 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011291 for (i = 0; i < req->n_ssids; i++) {
11292 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11293 goto nla_put_failure;
11294 }
Johannes Berg362a4152009-05-24 16:43:15 +020011295 nla_nest_end(msg, nest);
11296
11297 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11298 if (!nest)
11299 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011300 for (i = 0; i < req->n_channels; i++) {
11301 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11302 goto nla_put_failure;
11303 }
Johannes Berg362a4152009-05-24 16:43:15 +020011304 nla_nest_end(msg, nest);
11305
David S. Miller9360ffd2012-03-29 04:41:26 -040011306 if (req->ie &&
11307 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11308 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011309
Johannes Bergae917c92013-10-25 11:05:22 +020011310 if (req->flags &&
11311 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11312 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011313
Johannes Berg362a4152009-05-24 16:43:15 +020011314 return 0;
11315 nla_put_failure:
11316 return -ENOBUFS;
11317}
11318
Johannes Berga538e2d2009-06-16 19:56:42 +020011319static int nl80211_send_scan_msg(struct sk_buff *msg,
11320 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011321 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011322 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011323 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011324{
11325 void *hdr;
11326
Eric W. Biederman15e47302012-09-07 20:12:54 +000011327 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011328 if (!hdr)
11329 return -1;
11330
David S. Miller9360ffd2012-03-29 04:41:26 -040011331 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011332 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11333 wdev->netdev->ifindex)) ||
11334 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011335 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011336
Johannes Berg362a4152009-05-24 16:43:15 +020011337 /* ignore errors and send incomplete event anyway */
11338 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011339
Johannes Berg053c0952015-01-16 22:09:00 +010011340 genlmsg_end(msg, hdr);
11341 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011342
11343 nla_put_failure:
11344 genlmsg_cancel(msg, hdr);
11345 return -EMSGSIZE;
11346}
11347
Luciano Coelho807f8a82011-05-11 17:09:35 +030011348static int
11349nl80211_send_sched_scan_msg(struct sk_buff *msg,
11350 struct cfg80211_registered_device *rdev,
11351 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011352 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011353{
11354 void *hdr;
11355
Eric W. Biederman15e47302012-09-07 20:12:54 +000011356 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011357 if (!hdr)
11358 return -1;
11359
David S. Miller9360ffd2012-03-29 04:41:26 -040011360 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11361 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11362 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011363
Johannes Berg053c0952015-01-16 22:09:00 +010011364 genlmsg_end(msg, hdr);
11365 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011366
11367 nla_put_failure:
11368 genlmsg_cancel(msg, hdr);
11369 return -EMSGSIZE;
11370}
11371
Johannes Berga538e2d2009-06-16 19:56:42 +020011372void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011373 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011374{
11375 struct sk_buff *msg;
11376
Thomas Graf58050fc2012-06-28 03:57:45 +000011377 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011378 if (!msg)
11379 return;
11380
Johannes Bergfd014282012-06-18 19:17:03 +020011381 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011382 NL80211_CMD_TRIGGER_SCAN) < 0) {
11383 nlmsg_free(msg);
11384 return;
11385 }
11386
Johannes Berg68eb5502013-11-19 15:19:38 +010011387 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011388 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011389}
11390
Johannes Bergf9d15d12014-01-22 11:14:19 +020011391struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11392 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011393{
11394 struct sk_buff *msg;
11395
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011396 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011397 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011398 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011399
Johannes Bergfd014282012-06-18 19:17:03 +020011400 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011401 aborted ? NL80211_CMD_SCAN_ABORTED :
11402 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011403 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011404 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011405 }
11406
Johannes Bergf9d15d12014-01-22 11:14:19 +020011407 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011408}
11409
Johannes Bergf9d15d12014-01-22 11:14:19 +020011410void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11411 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011412{
Johannes Berg2a519312009-02-10 21:25:55 +010011413 if (!msg)
11414 return;
11415
Johannes Berg68eb5502013-11-19 15:19:38 +010011416 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011417 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011418}
11419
Luciano Coelho807f8a82011-05-11 17:09:35 +030011420void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11421 struct net_device *netdev)
11422{
11423 struct sk_buff *msg;
11424
11425 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11426 if (!msg)
11427 return;
11428
11429 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11430 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11431 nlmsg_free(msg);
11432 return;
11433 }
11434
Johannes Berg68eb5502013-11-19 15:19:38 +010011435 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011436 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011437}
11438
11439void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11440 struct net_device *netdev, u32 cmd)
11441{
11442 struct sk_buff *msg;
11443
Thomas Graf58050fc2012-06-28 03:57:45 +000011444 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011445 if (!msg)
11446 return;
11447
11448 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11449 nlmsg_free(msg);
11450 return;
11451 }
11452
Johannes Berg68eb5502013-11-19 15:19:38 +010011453 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011454 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011455}
11456
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011457static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11458 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011459{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011460 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011461 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11462 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011463
David S. Miller9360ffd2012-03-29 04:41:26 -040011464 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11465 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11466 NL80211_REGDOM_TYPE_WORLD))
11467 goto nla_put_failure;
11468 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11469 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11470 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11471 goto nla_put_failure;
11472 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11473 request->intersect) {
11474 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11475 NL80211_REGDOM_TYPE_INTERSECTION))
11476 goto nla_put_failure;
11477 } else {
11478 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11479 NL80211_REGDOM_TYPE_COUNTRY) ||
11480 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11481 request->alpha2))
11482 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011483 }
11484
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011485 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11486 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11487
11488 if (wiphy &&
11489 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11490 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011491
11492 if (wiphy &&
11493 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11494 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11495 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011496 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011497
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011498 return true;
11499
11500nla_put_failure:
11501 return false;
11502}
11503
11504/*
11505 * This can happen on global regulatory changes or device specific settings
11506 * based on custom regulatory domains.
11507 */
11508void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11509 struct regulatory_request *request)
11510{
11511 struct sk_buff *msg;
11512 void *hdr;
11513
11514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11515 if (!msg)
11516 return;
11517
11518 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11519 if (!hdr) {
11520 nlmsg_free(msg);
11521 return;
11522 }
11523
11524 if (nl80211_reg_change_event_fill(msg, request) == false)
11525 goto nla_put_failure;
11526
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011527 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011528
Johannes Bergbc43b282009-07-25 10:54:13 +020011529 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011530 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011531 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011532 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011533
11534 return;
11535
11536nla_put_failure:
11537 genlmsg_cancel(msg, hdr);
11538 nlmsg_free(msg);
11539}
11540
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011541static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11542 struct net_device *netdev,
11543 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011544 enum nl80211_commands cmd, gfp_t gfp,
11545 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011546{
11547 struct sk_buff *msg;
11548 void *hdr;
11549
Johannes Berge6d6e342009-07-01 21:26:47 +020011550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011551 if (!msg)
11552 return;
11553
11554 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11555 if (!hdr) {
11556 nlmsg_free(msg);
11557 return;
11558 }
11559
David S. Miller9360ffd2012-03-29 04:41:26 -040011560 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11561 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11562 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11563 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011564
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011565 if (uapsd_queues >= 0) {
11566 struct nlattr *nla_wmm =
11567 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11568 if (!nla_wmm)
11569 goto nla_put_failure;
11570
11571 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11572 uapsd_queues))
11573 goto nla_put_failure;
11574
11575 nla_nest_end(msg, nla_wmm);
11576 }
11577
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011578 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011579
Johannes Berg68eb5502013-11-19 15:19:38 +010011580 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011581 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011582 return;
11583
11584 nla_put_failure:
11585 genlmsg_cancel(msg, hdr);
11586 nlmsg_free(msg);
11587}
11588
11589void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011590 struct net_device *netdev, const u8 *buf,
11591 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011592{
11593 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011594 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011595}
11596
11597void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11598 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011599 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011600{
Johannes Berge6d6e342009-07-01 21:26:47 +020011601 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011602 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011603}
11604
Jouni Malinen53b46b82009-03-27 20:53:56 +020011605void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011606 struct net_device *netdev, const u8 *buf,
11607 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011608{
11609 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011610 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011611}
11612
Jouni Malinen53b46b82009-03-27 20:53:56 +020011613void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11614 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011615 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011616{
11617 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011618 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011619}
11620
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011621void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11622 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011623{
Johannes Berg947add32013-02-22 22:05:20 +010011624 struct wireless_dev *wdev = dev->ieee80211_ptr;
11625 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011626 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011627 const struct ieee80211_mgmt *mgmt = (void *)buf;
11628 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011629
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011630 if (WARN_ON(len < 2))
11631 return;
11632
11633 if (ieee80211_is_deauth(mgmt->frame_control))
11634 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11635 else
11636 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11637
11638 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011639 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011640}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011641EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011642
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011643static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11644 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011645 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011646{
11647 struct sk_buff *msg;
11648 void *hdr;
11649
Johannes Berge6d6e342009-07-01 21:26:47 +020011650 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011651 if (!msg)
11652 return;
11653
11654 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11655 if (!hdr) {
11656 nlmsg_free(msg);
11657 return;
11658 }
11659
David S. Miller9360ffd2012-03-29 04:41:26 -040011660 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11661 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11662 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11663 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11664 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011665
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011666 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011667
Johannes Berg68eb5502013-11-19 15:19:38 +010011668 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011669 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011670 return;
11671
11672 nla_put_failure:
11673 genlmsg_cancel(msg, hdr);
11674 nlmsg_free(msg);
11675}
11676
11677void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011678 struct net_device *netdev, const u8 *addr,
11679 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011680{
11681 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011682 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011683}
11684
11685void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011686 struct net_device *netdev, const u8 *addr,
11687 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011688{
Johannes Berge6d6e342009-07-01 21:26:47 +020011689 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11690 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011691}
11692
Samuel Ortizb23aa672009-07-01 21:26:54 +020011693void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11694 struct net_device *netdev, const u8 *bssid,
11695 const u8 *req_ie, size_t req_ie_len,
11696 const u8 *resp_ie, size_t resp_ie_len,
11697 u16 status, gfp_t gfp)
11698{
11699 struct sk_buff *msg;
11700 void *hdr;
11701
Thomas Graf58050fc2012-06-28 03:57:45 +000011702 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011703 if (!msg)
11704 return;
11705
11706 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11707 if (!hdr) {
11708 nlmsg_free(msg);
11709 return;
11710 }
11711
David S. Miller9360ffd2012-03-29 04:41:26 -040011712 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11713 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11714 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11715 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11716 (req_ie &&
11717 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11718 (resp_ie &&
11719 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11720 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011721
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011722 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011723
Johannes Berg68eb5502013-11-19 15:19:38 +010011724 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011725 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011726 return;
11727
11728 nla_put_failure:
11729 genlmsg_cancel(msg, hdr);
11730 nlmsg_free(msg);
11731
11732}
11733
11734void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11735 struct net_device *netdev, const u8 *bssid,
11736 const u8 *req_ie, size_t req_ie_len,
11737 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11738{
11739 struct sk_buff *msg;
11740 void *hdr;
11741
Thomas Graf58050fc2012-06-28 03:57:45 +000011742 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011743 if (!msg)
11744 return;
11745
11746 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11747 if (!hdr) {
11748 nlmsg_free(msg);
11749 return;
11750 }
11751
David S. Miller9360ffd2012-03-29 04:41:26 -040011752 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11753 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11754 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11755 (req_ie &&
11756 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11757 (resp_ie &&
11758 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11759 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011760
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011761 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011762
Johannes Berg68eb5502013-11-19 15:19:38 +010011763 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011764 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011765 return;
11766
11767 nla_put_failure:
11768 genlmsg_cancel(msg, hdr);
11769 nlmsg_free(msg);
11770
11771}
11772
11773void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11774 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011775 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011776{
11777 struct sk_buff *msg;
11778 void *hdr;
11779
Thomas Graf58050fc2012-06-28 03:57:45 +000011780 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011781 if (!msg)
11782 return;
11783
11784 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11785 if (!hdr) {
11786 nlmsg_free(msg);
11787 return;
11788 }
11789
David S. Miller9360ffd2012-03-29 04:41:26 -040011790 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11791 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11792 (from_ap && reason &&
11793 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11794 (from_ap &&
11795 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11796 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11797 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011798
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011799 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011800
Johannes Berg68eb5502013-11-19 15:19:38 +010011801 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011802 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011803 return;
11804
11805 nla_put_failure:
11806 genlmsg_cancel(msg, hdr);
11807 nlmsg_free(msg);
11808
11809}
11810
Johannes Berg04a773a2009-04-19 21:24:32 +020011811void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11812 struct net_device *netdev, const u8 *bssid,
11813 gfp_t gfp)
11814{
11815 struct sk_buff *msg;
11816 void *hdr;
11817
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011818 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011819 if (!msg)
11820 return;
11821
11822 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11823 if (!hdr) {
11824 nlmsg_free(msg);
11825 return;
11826 }
11827
David S. Miller9360ffd2012-03-29 04:41:26 -040011828 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11829 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11830 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11831 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011832
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011833 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011834
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);
Johannes Berg04a773a2009-04-19 21:24:32 +020011837 return;
11838
11839 nla_put_failure:
11840 genlmsg_cancel(msg, hdr);
11841 nlmsg_free(msg);
11842}
11843
Johannes Berg947add32013-02-22 22:05:20 +010011844void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11845 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011846{
Johannes Berg947add32013-02-22 22:05:20 +010011847 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011848 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011849 struct sk_buff *msg;
11850 void *hdr;
11851
Johannes Berg947add32013-02-22 22:05:20 +010011852 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11853 return;
11854
11855 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11856
Javier Cardonac93b5e72011-04-07 15:08:34 -070011857 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11858 if (!msg)
11859 return;
11860
11861 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11862 if (!hdr) {
11863 nlmsg_free(msg);
11864 return;
11865 }
11866
David S. Miller9360ffd2012-03-29 04:41:26 -040011867 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011868 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11869 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011870 (ie_len && ie &&
11871 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11872 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011873
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011874 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011875
Johannes Berg68eb5502013-11-19 15:19:38 +010011876 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011877 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011878 return;
11879
11880 nla_put_failure:
11881 genlmsg_cancel(msg, hdr);
11882 nlmsg_free(msg);
11883}
Johannes Berg947add32013-02-22 22:05:20 +010011884EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011885
Jouni Malinena3b8b052009-03-27 21:59:49 +020011886void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11887 struct net_device *netdev, const u8 *addr,
11888 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011889 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011890{
11891 struct sk_buff *msg;
11892 void *hdr;
11893
Johannes Berge6d6e342009-07-01 21:26:47 +020011894 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011895 if (!msg)
11896 return;
11897
11898 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11899 if (!hdr) {
11900 nlmsg_free(msg);
11901 return;
11902 }
11903
David S. Miller9360ffd2012-03-29 04:41:26 -040011904 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11905 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11906 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11907 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11908 (key_id != -1 &&
11909 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11910 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11911 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011912
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011913 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011914
Johannes Berg68eb5502013-11-19 15:19:38 +010011915 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011916 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011917 return;
11918
11919 nla_put_failure:
11920 genlmsg_cancel(msg, hdr);
11921 nlmsg_free(msg);
11922}
11923
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011924void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11925 struct ieee80211_channel *channel_before,
11926 struct ieee80211_channel *channel_after)
11927{
11928 struct sk_buff *msg;
11929 void *hdr;
11930 struct nlattr *nl_freq;
11931
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011932 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011933 if (!msg)
11934 return;
11935
11936 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11937 if (!hdr) {
11938 nlmsg_free(msg);
11939 return;
11940 }
11941
11942 /*
11943 * Since we are applying the beacon hint to a wiphy we know its
11944 * wiphy_idx is valid
11945 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011946 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11947 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011948
11949 /* Before */
11950 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11951 if (!nl_freq)
11952 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011953 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011954 goto nla_put_failure;
11955 nla_nest_end(msg, nl_freq);
11956
11957 /* After */
11958 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11959 if (!nl_freq)
11960 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011961 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011962 goto nla_put_failure;
11963 nla_nest_end(msg, nl_freq);
11964
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011965 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011966
Johannes Berg463d0182009-07-14 00:33:35 +020011967 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011968 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011969 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011970 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011971
11972 return;
11973
11974nla_put_failure:
11975 genlmsg_cancel(msg, hdr);
11976 nlmsg_free(msg);
11977}
11978
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011979static void nl80211_send_remain_on_chan_event(
11980 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011981 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011982 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011983 unsigned int duration, gfp_t gfp)
11984{
11985 struct sk_buff *msg;
11986 void *hdr;
11987
11988 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11989 if (!msg)
11990 return;
11991
11992 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11993 if (!hdr) {
11994 nlmsg_free(msg);
11995 return;
11996 }
11997
David S. Miller9360ffd2012-03-29 04:41:26 -040011998 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011999 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12000 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020012001 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012002 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010012003 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
12004 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012005 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
12006 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012007
David S. Miller9360ffd2012-03-29 04:41:26 -040012008 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
12009 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
12010 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012011
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012012 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012013
Johannes Berg68eb5502013-11-19 15:19:38 +010012014 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012015 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012016 return;
12017
12018 nla_put_failure:
12019 genlmsg_cancel(msg, hdr);
12020 nlmsg_free(msg);
12021}
12022
Johannes Berg947add32013-02-22 22:05:20 +010012023void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
12024 struct ieee80211_channel *chan,
12025 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012026{
Johannes Berg947add32013-02-22 22:05:20 +010012027 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012028 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012029
12030 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012031 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020012032 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010012033 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012034}
Johannes Berg947add32013-02-22 22:05:20 +010012035EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012036
Johannes Berg947add32013-02-22 22:05:20 +010012037void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
12038 struct ieee80211_channel *chan,
12039 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012040{
Johannes Berg947add32013-02-22 22:05:20 +010012041 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012042 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012043
12044 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012045 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010012046 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012047}
Johannes Berg947add32013-02-22 22:05:20 +010012048EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010012049
Johannes Berg947add32013-02-22 22:05:20 +010012050void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
12051 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010012052{
Johannes Berg947add32013-02-22 22:05:20 +010012053 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012054 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010012055 struct sk_buff *msg;
12056
Johannes Berg947add32013-02-22 22:05:20 +010012057 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
12058
Thomas Graf58050fc2012-06-28 03:57:45 +000012059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012060 if (!msg)
12061 return;
12062
Johannes Bergcf5ead82014-11-14 17:14:00 +010012063 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040012064 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010012065 nlmsg_free(msg);
12066 return;
12067 }
12068
Johannes Berg68eb5502013-11-19 15:19:38 +010012069 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012070 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010012071}
Johannes Berg947add32013-02-22 22:05:20 +010012072EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010012073
Johannes Bergcf5ead82014-11-14 17:14:00 +010012074void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
12075 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020012076{
Johannes Berg947add32013-02-22 22:05:20 +010012077 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012078 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020012079 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010012080 struct station_info empty_sinfo = {};
12081
12082 if (!sinfo)
12083 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020012084
Johannes Berg947add32013-02-22 22:05:20 +010012085 trace_cfg80211_del_sta(dev, mac_addr);
12086
Thomas Graf58050fc2012-06-28 03:57:45 +000012087 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012088 if (!msg)
12089 return;
12090
Johannes Bergcf5ead82014-11-14 17:14:00 +010012091 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010012092 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020012093 nlmsg_free(msg);
12094 return;
12095 }
12096
Johannes Berg68eb5502013-11-19 15:19:38 +010012097 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012098 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020012099}
Johannes Bergcf5ead82014-11-14 17:14:00 +010012100EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020012101
Johannes Berg947add32013-02-22 22:05:20 +010012102void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
12103 enum nl80211_connect_failed_reason reason,
12104 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012105{
Johannes Berg947add32013-02-22 22:05:20 +010012106 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012107 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012108 struct sk_buff *msg;
12109 void *hdr;
12110
12111 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
12112 if (!msg)
12113 return;
12114
12115 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
12116 if (!hdr) {
12117 nlmsg_free(msg);
12118 return;
12119 }
12120
12121 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12122 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
12123 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
12124 goto nla_put_failure;
12125
12126 genlmsg_end(msg, hdr);
12127
Johannes Berg68eb5502013-11-19 15:19:38 +010012128 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012129 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012130 return;
12131
12132 nla_put_failure:
12133 genlmsg_cancel(msg, hdr);
12134 nlmsg_free(msg);
12135}
Johannes Berg947add32013-02-22 22:05:20 +010012136EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053012137
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012138static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
12139 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010012140{
12141 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012142 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010012143 struct sk_buff *msg;
12144 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000012145 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012146
Eric W. Biederman15e47302012-09-07 20:12:54 +000012147 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010012148 return false;
12149
12150 msg = nlmsg_new(100, gfp);
12151 if (!msg)
12152 return true;
12153
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012154 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010012155 if (!hdr) {
12156 nlmsg_free(msg);
12157 return true;
12158 }
12159
David S. Miller9360ffd2012-03-29 04:41:26 -040012160 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12161 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12162 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
12163 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010012164
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012165 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000012166 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010012167 return true;
12168
12169 nla_put_failure:
12170 genlmsg_cancel(msg, hdr);
12171 nlmsg_free(msg);
12172 return true;
12173}
12174
Johannes Berg947add32013-02-22 22:05:20 +010012175bool cfg80211_rx_spurious_frame(struct net_device *dev,
12176 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012177{
Johannes Berg947add32013-02-22 22:05:20 +010012178 struct wireless_dev *wdev = dev->ieee80211_ptr;
12179 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012180
Johannes Berg947add32013-02-22 22:05:20 +010012181 trace_cfg80211_rx_spurious_frame(dev, addr);
12182
12183 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12184 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
12185 trace_cfg80211_return_bool(false);
12186 return false;
12187 }
12188 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
12189 addr, gfp);
12190 trace_cfg80211_return_bool(ret);
12191 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012192}
Johannes Berg947add32013-02-22 22:05:20 +010012193EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
12194
12195bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
12196 const u8 *addr, gfp_t gfp)
12197{
12198 struct wireless_dev *wdev = dev->ieee80211_ptr;
12199 bool ret;
12200
12201 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
12202
12203 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
12204 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
12205 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
12206 trace_cfg80211_return_bool(false);
12207 return false;
12208 }
12209 ret = __nl80211_unexpected_frame(dev,
12210 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12211 addr, gfp);
12212 trace_cfg80211_return_bool(ret);
12213 return ret;
12214}
12215EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012216
Johannes Berg2e161f72010-08-12 15:38:38 +020012217int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012218 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012219 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012220 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012221{
Johannes Berg71bbc992012-06-15 15:30:18 +020012222 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012223 struct sk_buff *msg;
12224 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012225
12226 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12227 if (!msg)
12228 return -ENOMEM;
12229
Johannes Berg2e161f72010-08-12 15:38:38 +020012230 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012231 if (!hdr) {
12232 nlmsg_free(msg);
12233 return -ENOMEM;
12234 }
12235
David S. Miller9360ffd2012-03-29 04:41:26 -040012236 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012237 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12238 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012239 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012240 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12241 (sig_dbm &&
12242 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012243 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12244 (flags &&
12245 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012246 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012247
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012248 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012249
Eric W. Biederman15e47302012-09-07 20:12:54 +000012250 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012251
12252 nla_put_failure:
12253 genlmsg_cancel(msg, hdr);
12254 nlmsg_free(msg);
12255 return -ENOBUFS;
12256}
12257
Johannes Berg947add32013-02-22 22:05:20 +010012258void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12259 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012260{
Johannes Berg947add32013-02-22 22:05:20 +010012261 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012262 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012263 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012264 struct sk_buff *msg;
12265 void *hdr;
12266
Johannes Berg947add32013-02-22 22:05:20 +010012267 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12268
Jouni Malinen026331c2010-02-15 12:53:10 +020012269 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12270 if (!msg)
12271 return;
12272
Johannes Berg2e161f72010-08-12 15:38:38 +020012273 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012274 if (!hdr) {
12275 nlmsg_free(msg);
12276 return;
12277 }
12278
David S. Miller9360ffd2012-03-29 04:41:26 -040012279 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012280 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12281 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012282 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012283 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12284 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12285 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12286 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012287
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012288 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012289
Johannes Berg68eb5502013-11-19 15:19:38 +010012290 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012291 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012292 return;
12293
12294 nla_put_failure:
12295 genlmsg_cancel(msg, hdr);
12296 nlmsg_free(msg);
12297}
Johannes Berg947add32013-02-22 22:05:20 +010012298EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012299
Johannes Berg5b97f492014-11-26 12:37:43 +010012300static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12301 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012302{
Johannes Berg947add32013-02-22 22:05:20 +010012303 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012304 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12305 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12306 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012307
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012308 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012309 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012310
Johannes Berg5b97f492014-11-26 12:37:43 +010012311 cb = (void **)msg->cb;
12312
12313 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12314 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012315 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012316 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012317 }
12318
David S. Miller9360ffd2012-03-29 04:41:26 -040012319 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012320 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012321 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012322
Johannes Berg5b97f492014-11-26 12:37:43 +010012323 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012324 goto nla_put_failure;
12325
Johannes Berg5b97f492014-11-26 12:37:43 +010012326 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12327 if (!cb[1])
12328 goto nla_put_failure;
12329
12330 cb[2] = rdev;
12331
12332 return msg;
12333 nla_put_failure:
12334 nlmsg_free(msg);
12335 return NULL;
12336}
12337
12338static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12339{
12340 void **cb = (void **)msg->cb;
12341 struct cfg80211_registered_device *rdev = cb[2];
12342
12343 nla_nest_end(msg, cb[1]);
12344 genlmsg_end(msg, cb[0]);
12345
12346 memset(msg->cb, 0, sizeof(msg->cb));
12347
12348 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12349 NL80211_MCGRP_MLME, gfp);
12350}
12351
12352void cfg80211_cqm_rssi_notify(struct net_device *dev,
12353 enum nl80211_cqm_rssi_threshold_event rssi_event,
12354 gfp_t gfp)
12355{
12356 struct sk_buff *msg;
12357
12358 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12359
Johannes Berg98f03342014-11-26 12:42:02 +010012360 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12361 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12362 return;
12363
Johannes Berg5b97f492014-11-26 12:37:43 +010012364 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12365 if (!msg)
12366 return;
12367
David S. Miller9360ffd2012-03-29 04:41:26 -040012368 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12369 rssi_event))
12370 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012371
Johannes Berg5b97f492014-11-26 12:37:43 +010012372 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012373
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012374 return;
12375
12376 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012377 nlmsg_free(msg);
12378}
Johannes Berg947add32013-02-22 22:05:20 +010012379EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012380
Johannes Berg5b97f492014-11-26 12:37:43 +010012381void cfg80211_cqm_txe_notify(struct net_device *dev,
12382 const u8 *peer, u32 num_packets,
12383 u32 rate, u32 intvl, gfp_t gfp)
12384{
12385 struct sk_buff *msg;
12386
12387 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12388 if (!msg)
12389 return;
12390
12391 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12392 goto nla_put_failure;
12393
12394 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12395 goto nla_put_failure;
12396
12397 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12398 goto nla_put_failure;
12399
12400 cfg80211_send_cqm(msg, gfp);
12401 return;
12402
12403 nla_put_failure:
12404 nlmsg_free(msg);
12405}
12406EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12407
12408void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12409 const u8 *peer, u32 num_packets, gfp_t gfp)
12410{
12411 struct sk_buff *msg;
12412
12413 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12414
12415 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12416 if (!msg)
12417 return;
12418
12419 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12420 goto nla_put_failure;
12421
12422 cfg80211_send_cqm(msg, gfp);
12423 return;
12424
12425 nla_put_failure:
12426 nlmsg_free(msg);
12427}
12428EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12429
Johannes Berg98f03342014-11-26 12:42:02 +010012430void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12431{
12432 struct sk_buff *msg;
12433
12434 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12435 if (!msg)
12436 return;
12437
12438 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12439 goto nla_put_failure;
12440
12441 cfg80211_send_cqm(msg, gfp);
12442 return;
12443
12444 nla_put_failure:
12445 nlmsg_free(msg);
12446}
12447EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12448
Johannes Berg947add32013-02-22 22:05:20 +010012449static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12450 struct net_device *netdev, const u8 *bssid,
12451 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012452{
12453 struct sk_buff *msg;
12454 struct nlattr *rekey_attr;
12455 void *hdr;
12456
Thomas Graf58050fc2012-06-28 03:57:45 +000012457 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012458 if (!msg)
12459 return;
12460
12461 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12462 if (!hdr) {
12463 nlmsg_free(msg);
12464 return;
12465 }
12466
David S. Miller9360ffd2012-03-29 04:41:26 -040012467 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12468 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12469 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12470 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012471
12472 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12473 if (!rekey_attr)
12474 goto nla_put_failure;
12475
David S. Miller9360ffd2012-03-29 04:41:26 -040012476 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12477 NL80211_REPLAY_CTR_LEN, replay_ctr))
12478 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012479
12480 nla_nest_end(msg, rekey_attr);
12481
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012482 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012483
Johannes Berg68eb5502013-11-19 15:19:38 +010012484 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012485 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012486 return;
12487
12488 nla_put_failure:
12489 genlmsg_cancel(msg, hdr);
12490 nlmsg_free(msg);
12491}
12492
Johannes Berg947add32013-02-22 22:05:20 +010012493void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12494 const u8 *replay_ctr, gfp_t gfp)
12495{
12496 struct wireless_dev *wdev = dev->ieee80211_ptr;
12497 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012498 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012499
12500 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12501 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12502}
12503EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12504
12505static void
12506nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12507 struct net_device *netdev, int index,
12508 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012509{
12510 struct sk_buff *msg;
12511 struct nlattr *attr;
12512 void *hdr;
12513
Thomas Graf58050fc2012-06-28 03:57:45 +000012514 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012515 if (!msg)
12516 return;
12517
12518 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12519 if (!hdr) {
12520 nlmsg_free(msg);
12521 return;
12522 }
12523
David S. Miller9360ffd2012-03-29 04:41:26 -040012524 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12525 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12526 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012527
12528 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12529 if (!attr)
12530 goto nla_put_failure;
12531
David S. Miller9360ffd2012-03-29 04:41:26 -040012532 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12533 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12534 (preauth &&
12535 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12536 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012537
12538 nla_nest_end(msg, attr);
12539
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012540 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012541
Johannes Berg68eb5502013-11-19 15:19:38 +010012542 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012543 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012544 return;
12545
12546 nla_put_failure:
12547 genlmsg_cancel(msg, hdr);
12548 nlmsg_free(msg);
12549}
12550
Johannes Berg947add32013-02-22 22:05:20 +010012551void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12552 const u8 *bssid, bool preauth, gfp_t gfp)
12553{
12554 struct wireless_dev *wdev = dev->ieee80211_ptr;
12555 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012556 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012557
12558 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12559 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12560}
12561EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12562
12563static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12564 struct net_device *netdev,
12565 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012566 gfp_t gfp,
12567 enum nl80211_commands notif,
12568 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012569{
12570 struct sk_buff *msg;
12571 void *hdr;
12572
Thomas Graf58050fc2012-06-28 03:57:45 +000012573 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012574 if (!msg)
12575 return;
12576
Luciano Coelhof8d75522014-11-07 14:31:35 +020012577 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012578 if (!hdr) {
12579 nlmsg_free(msg);
12580 return;
12581 }
12582
Johannes Berg683b6d32012-11-08 21:25:48 +010012583 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12584 goto nla_put_failure;
12585
12586 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012587 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012588
Luciano Coelhof8d75522014-11-07 14:31:35 +020012589 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12590 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12591 goto nla_put_failure;
12592
Thomas Pedersen53145262012-04-06 13:35:47 -070012593 genlmsg_end(msg, hdr);
12594
Johannes Berg68eb5502013-11-19 15:19:38 +010012595 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012596 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012597 return;
12598
12599 nla_put_failure:
12600 genlmsg_cancel(msg, hdr);
12601 nlmsg_free(msg);
12602}
12603
Johannes Berg947add32013-02-22 22:05:20 +010012604void cfg80211_ch_switch_notify(struct net_device *dev,
12605 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012606{
Johannes Berg947add32013-02-22 22:05:20 +010012607 struct wireless_dev *wdev = dev->ieee80211_ptr;
12608 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012609 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012610
Simon Wunderliche487eae2013-11-21 18:19:51 +010012611 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012612
Simon Wunderliche487eae2013-11-21 18:19:51 +010012613 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012614
Michal Kazior9e0e2962014-01-29 14:22:27 +010012615 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012616 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012617 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12618 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012619}
12620EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12621
Luciano Coelhof8d75522014-11-07 14:31:35 +020012622void cfg80211_ch_switch_started_notify(struct net_device *dev,
12623 struct cfg80211_chan_def *chandef,
12624 u8 count)
12625{
12626 struct wireless_dev *wdev = dev->ieee80211_ptr;
12627 struct wiphy *wiphy = wdev->wiphy;
12628 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12629
12630 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12631
12632 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12633 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12634}
12635EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12636
Thomas Pedersen84f10702012-07-12 16:17:33 -070012637void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012638nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012639 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012640 enum nl80211_radar_event event,
12641 struct net_device *netdev, gfp_t gfp)
12642{
12643 struct sk_buff *msg;
12644 void *hdr;
12645
12646 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12647 if (!msg)
12648 return;
12649
12650 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12651 if (!hdr) {
12652 nlmsg_free(msg);
12653 return;
12654 }
12655
12656 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12657 goto nla_put_failure;
12658
12659 /* NOP and radar events don't need a netdev parameter */
12660 if (netdev) {
12661 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12662
12663 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12664 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12665 goto nla_put_failure;
12666 }
12667
12668 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12669 goto nla_put_failure;
12670
12671 if (nl80211_send_chandef(msg, chandef))
12672 goto nla_put_failure;
12673
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012674 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012675
Johannes Berg68eb5502013-11-19 15:19:38 +010012676 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012677 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012678 return;
12679
12680 nla_put_failure:
12681 genlmsg_cancel(msg, hdr);
12682 nlmsg_free(msg);
12683}
12684
Johannes Berg7f6cf312011-11-04 11:18:15 +010012685void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12686 u64 cookie, bool acked, gfp_t gfp)
12687{
12688 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012689 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012690 struct sk_buff *msg;
12691 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012692
Beni Lev4ee3e062012-08-27 12:49:39 +030012693 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12694
Thomas Graf58050fc2012-06-28 03:57:45 +000012695 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012696
Johannes Berg7f6cf312011-11-04 11:18:15 +010012697 if (!msg)
12698 return;
12699
12700 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12701 if (!hdr) {
12702 nlmsg_free(msg);
12703 return;
12704 }
12705
David S. Miller9360ffd2012-03-29 04:41:26 -040012706 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12707 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12708 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12709 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12710 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12711 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012712
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012713 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012714
Johannes Berg68eb5502013-11-19 15:19:38 +010012715 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012716 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012717 return;
12718
12719 nla_put_failure:
12720 genlmsg_cancel(msg, hdr);
12721 nlmsg_free(msg);
12722}
12723EXPORT_SYMBOL(cfg80211_probe_status);
12724
Johannes Berg5e760232011-11-04 11:18:17 +010012725void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12726 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012727 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012728{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012729 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012730 struct sk_buff *msg;
12731 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012732 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012733
Beni Lev4ee3e062012-08-27 12:49:39 +030012734 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12735
Ben Greear37c73b52012-10-26 14:49:25 -070012736 spin_lock_bh(&rdev->beacon_registrations_lock);
12737 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12738 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12739 if (!msg) {
12740 spin_unlock_bh(&rdev->beacon_registrations_lock);
12741 return;
12742 }
Johannes Berg5e760232011-11-04 11:18:17 +010012743
Ben Greear37c73b52012-10-26 14:49:25 -070012744 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12745 if (!hdr)
12746 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012747
Ben Greear37c73b52012-10-26 14:49:25 -070012748 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12749 (freq &&
12750 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12751 (sig_dbm &&
12752 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12753 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12754 goto nla_put_failure;
12755
12756 genlmsg_end(msg, hdr);
12757
12758 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012759 }
Ben Greear37c73b52012-10-26 14:49:25 -070012760 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012761 return;
12762
12763 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012764 spin_unlock_bh(&rdev->beacon_registrations_lock);
12765 if (hdr)
12766 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012767 nlmsg_free(msg);
12768}
12769EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12770
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012771#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012772static int cfg80211_net_detect_results(struct sk_buff *msg,
12773 struct cfg80211_wowlan_wakeup *wakeup)
12774{
12775 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12776 struct nlattr *nl_results, *nl_match, *nl_freqs;
12777 int i, j;
12778
12779 nl_results = nla_nest_start(
12780 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12781 if (!nl_results)
12782 return -EMSGSIZE;
12783
12784 for (i = 0; i < nd->n_matches; i++) {
12785 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12786
12787 nl_match = nla_nest_start(msg, i);
12788 if (!nl_match)
12789 break;
12790
12791 /* The SSID attribute is optional in nl80211, but for
12792 * simplicity reasons it's always present in the
12793 * cfg80211 structure. If a driver can't pass the
12794 * SSID, that needs to be changed. A zero length SSID
12795 * is still a valid SSID (wildcard), so it cannot be
12796 * used for this purpose.
12797 */
12798 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12799 match->ssid.ssid)) {
12800 nla_nest_cancel(msg, nl_match);
12801 goto out;
12802 }
12803
12804 if (match->n_channels) {
12805 nl_freqs = nla_nest_start(
12806 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12807 if (!nl_freqs) {
12808 nla_nest_cancel(msg, nl_match);
12809 goto out;
12810 }
12811
12812 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020012813 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012814 nla_nest_cancel(msg, nl_freqs);
12815 nla_nest_cancel(msg, nl_match);
12816 goto out;
12817 }
12818 }
12819
12820 nla_nest_end(msg, nl_freqs);
12821 }
12822
12823 nla_nest_end(msg, nl_match);
12824 }
12825
12826out:
12827 nla_nest_end(msg, nl_results);
12828 return 0;
12829}
12830
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012831void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12832 struct cfg80211_wowlan_wakeup *wakeup,
12833 gfp_t gfp)
12834{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012835 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012836 struct sk_buff *msg;
12837 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012838 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012839
12840 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12841
12842 if (wakeup)
12843 size += wakeup->packet_present_len;
12844
12845 msg = nlmsg_new(size, gfp);
12846 if (!msg)
12847 return;
12848
12849 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12850 if (!hdr)
12851 goto free_msg;
12852
12853 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12854 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12855 goto free_msg;
12856
12857 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12858 wdev->netdev->ifindex))
12859 goto free_msg;
12860
12861 if (wakeup) {
12862 struct nlattr *reasons;
12863
12864 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012865 if (!reasons)
12866 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012867
12868 if (wakeup->disconnect &&
12869 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12870 goto free_msg;
12871 if (wakeup->magic_pkt &&
12872 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12873 goto free_msg;
12874 if (wakeup->gtk_rekey_failure &&
12875 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12876 goto free_msg;
12877 if (wakeup->eap_identity_req &&
12878 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12879 goto free_msg;
12880 if (wakeup->four_way_handshake &&
12881 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12882 goto free_msg;
12883 if (wakeup->rfkill_release &&
12884 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12885 goto free_msg;
12886
12887 if (wakeup->pattern_idx >= 0 &&
12888 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12889 wakeup->pattern_idx))
12890 goto free_msg;
12891
Johannes Bergae917c92013-10-25 11:05:22 +020012892 if (wakeup->tcp_match &&
12893 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12894 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012895
Johannes Bergae917c92013-10-25 11:05:22 +020012896 if (wakeup->tcp_connlost &&
12897 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12898 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012899
Johannes Bergae917c92013-10-25 11:05:22 +020012900 if (wakeup->tcp_nomoretokens &&
12901 nla_put_flag(msg,
12902 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12903 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012904
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012905 if (wakeup->packet) {
12906 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12907 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12908
12909 if (!wakeup->packet_80211) {
12910 pkt_attr =
12911 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12912 len_attr =
12913 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12914 }
12915
12916 if (wakeup->packet_len &&
12917 nla_put_u32(msg, len_attr, wakeup->packet_len))
12918 goto free_msg;
12919
12920 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12921 wakeup->packet))
12922 goto free_msg;
12923 }
12924
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012925 if (wakeup->net_detect &&
12926 cfg80211_net_detect_results(msg, wakeup))
12927 goto free_msg;
12928
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012929 nla_nest_end(msg, reasons);
12930 }
12931
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012932 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012933
Johannes Berg68eb5502013-11-19 15:19:38 +010012934 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012935 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012936 return;
12937
12938 free_msg:
12939 nlmsg_free(msg);
12940}
12941EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12942#endif
12943
Jouni Malinen3475b092012-11-16 22:49:57 +020012944void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12945 enum nl80211_tdls_operation oper,
12946 u16 reason_code, gfp_t gfp)
12947{
12948 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012949 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012950 struct sk_buff *msg;
12951 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012952
12953 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12954 reason_code);
12955
12956 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12957 if (!msg)
12958 return;
12959
12960 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12961 if (!hdr) {
12962 nlmsg_free(msg);
12963 return;
12964 }
12965
12966 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12967 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12968 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12969 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12970 (reason_code > 0 &&
12971 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12972 goto nla_put_failure;
12973
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012974 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012975
Johannes Berg68eb5502013-11-19 15:19:38 +010012976 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012977 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012978 return;
12979
12980 nla_put_failure:
12981 genlmsg_cancel(msg, hdr);
12982 nlmsg_free(msg);
12983}
12984EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12985
Jouni Malinen026331c2010-02-15 12:53:10 +020012986static int nl80211_netlink_notify(struct notifier_block * nb,
12987 unsigned long state,
12988 void *_notify)
12989{
12990 struct netlink_notify *notify = _notify;
12991 struct cfg80211_registered_device *rdev;
12992 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012993 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012994
12995 if (state != NETLINK_URELEASE)
12996 return NOTIFY_DONE;
12997
12998 rcu_read_lock();
12999
Johannes Berg5e760232011-11-04 11:18:17 +010013000 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010013001 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013002 bool schedule_scan_stop = false;
13003 struct cfg80211_sched_scan_request *sched_scan_req =
13004 rcu_dereference(rdev->sched_scan_req);
13005
13006 if (sched_scan_req && notify->portid &&
13007 sched_scan_req->owner_nlportid == notify->portid)
13008 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010013009
13010 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000013011 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070013012
Johannes Berg78f22b62014-03-24 17:57:27 +010013013 if (wdev->owner_nlportid == notify->portid)
13014 schedule_destroy_work = true;
13015 }
13016
Ben Greear37c73b52012-10-26 14:49:25 -070013017 spin_lock_bh(&rdev->beacon_registrations_lock);
13018 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
13019 list) {
13020 if (reg->nlportid == notify->portid) {
13021 list_del(&reg->list);
13022 kfree(reg);
13023 break;
13024 }
13025 }
13026 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010013027
13028 if (schedule_destroy_work) {
13029 struct cfg80211_iface_destroy *destroy;
13030
13031 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
13032 if (destroy) {
13033 destroy->nlportid = notify->portid;
13034 spin_lock(&rdev->destroy_list_lock);
13035 list_add(&destroy->list, &rdev->destroy_list);
13036 spin_unlock(&rdev->destroy_list_lock);
13037 schedule_work(&rdev->destroy_work);
13038 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020013039 } else if (schedule_scan_stop) {
13040 sched_scan_req->owner_nlportid = 0;
13041
13042 if (rdev->ops->sched_scan_stop &&
13043 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
13044 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010013045 }
Johannes Berg5e760232011-11-04 11:18:17 +010013046 }
Jouni Malinen026331c2010-02-15 12:53:10 +020013047
13048 rcu_read_unlock();
13049
Ilan peer05050752015-03-04 00:32:06 -050013050 /*
13051 * It is possible that the user space process that is controlling the
13052 * indoor setting disappeared, so notify the regulatory core.
13053 */
13054 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080013055 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020013056}
13057
13058static struct notifier_block nl80211_netlink_notifier = {
13059 .notifier_call = nl80211_netlink_notify,
13060};
13061
Jouni Malinen355199e2013-02-27 17:14:27 +020013062void cfg80211_ft_event(struct net_device *netdev,
13063 struct cfg80211_ft_event_params *ft_event)
13064{
13065 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013066 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020013067 struct sk_buff *msg;
13068 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020013069
13070 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
13071
13072 if (!ft_event->target_ap)
13073 return;
13074
13075 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13076 if (!msg)
13077 return;
13078
13079 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020013080 if (!hdr)
13081 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013082
Johannes Bergae917c92013-10-25 11:05:22 +020013083 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13084 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
13085 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
13086 goto out;
13087
13088 if (ft_event->ies &&
13089 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
13090 goto out;
13091 if (ft_event->ric_ies &&
13092 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
13093 ft_event->ric_ies))
13094 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020013095
Johannes Berg9c90a9f2013-06-04 12:46:03 +020013096 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020013097
Johannes Berg68eb5502013-11-19 15:19:38 +010013098 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010013099 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020013100 return;
13101 out:
13102 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020013103}
13104EXPORT_SYMBOL(cfg80211_ft_event);
13105
Arend van Spriel5de17982013-04-18 15:49:00 +020013106void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
13107{
13108 struct cfg80211_registered_device *rdev;
13109 struct sk_buff *msg;
13110 void *hdr;
13111 u32 nlportid;
13112
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013113 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020013114 if (!rdev->crit_proto_nlportid)
13115 return;
13116
13117 nlportid = rdev->crit_proto_nlportid;
13118 rdev->crit_proto_nlportid = 0;
13119
13120 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
13121 if (!msg)
13122 return;
13123
13124 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
13125 if (!hdr)
13126 goto nla_put_failure;
13127
13128 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13129 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13130 goto nla_put_failure;
13131
13132 genlmsg_end(msg, hdr);
13133
13134 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
13135 return;
13136
13137 nla_put_failure:
13138 if (hdr)
13139 genlmsg_cancel(msg, hdr);
13140 nlmsg_free(msg);
13141
13142}
13143EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
13144
Johannes Berg348baf02014-01-24 14:06:29 +010013145void nl80211_send_ap_stopped(struct wireless_dev *wdev)
13146{
13147 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080013148 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010013149 struct sk_buff *msg;
13150 void *hdr;
13151
13152 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
13153 if (!msg)
13154 return;
13155
13156 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
13157 if (!hdr)
13158 goto out;
13159
13160 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
13161 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
13162 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
13163 goto out;
13164
13165 genlmsg_end(msg, hdr);
13166
13167 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
13168 NL80211_MCGRP_MLME, GFP_KERNEL);
13169 return;
13170 out:
13171 nlmsg_free(msg);
13172}
13173
Johannes Berg55682962007-09-20 13:09:35 -040013174/* initialisation/exit functions */
13175
13176int nl80211_init(void)
13177{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000013178 int err;
Johannes Berg55682962007-09-20 13:09:35 -040013179
Johannes Berg2a94fe42013-11-19 15:19:39 +010013180 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
13181 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040013182 if (err)
13183 return err;
13184
Jouni Malinen026331c2010-02-15 12:53:10 +020013185 err = netlink_register_notifier(&nl80211_netlink_notifier);
13186 if (err)
13187 goto err_out;
13188
Johannes Berg55682962007-09-20 13:09:35 -040013189 return 0;
13190 err_out:
13191 genl_unregister_family(&nl80211_fam);
13192 return err;
13193}
13194
13195void nl80211_exit(void)
13196{
Jouni Malinen026331c2010-02-15 12:53:10 +020013197 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040013198 genl_unregister_family(&nl80211_fam);
13199}