blob: 454d7a079d039a3d7d129e8d927677183e957663 [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 Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010062 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
63 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
64 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
65 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
66 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010068 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010069#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee47782012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee47782012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee47782012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee47782012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee47782012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee47782012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300212static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200229 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f782010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200391 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200398 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200399 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200400 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200401 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Johannes Berg55682962007-09-20 13:09:35 -0400402};
403
Johannes Berge31b8212010-10-05 19:39:30 +0200404/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000405static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200406 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200407 [NL80211_KEY_IDX] = { .type = NLA_U8 },
408 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200409 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200410 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
411 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200412 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100413 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
414};
415
416/* policy for the key default flags */
417static const struct nla_policy
418nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
419 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
420 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200421};
422
Johannes Bergff1b6e62011-05-04 15:37:28 +0200423/* policy for WoWLAN attributes */
424static const struct nla_policy
425nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
426 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
427 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200430 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
431 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100434 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300435 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100436};
437
438static const struct nla_policy
439nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
440 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
441 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
442 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
443 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
444 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
445 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
446 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
447 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
448 },
449 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
450 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
451 },
452 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
453 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
454 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200455};
456
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700457/* policy for coalesce rule attributes */
458static const struct nla_policy
459nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
460 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
461 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
462 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
463};
464
Johannes Berge5497d72011-07-05 16:35:40 +0200465/* policy for GTK rekey offload attributes */
466static const struct nla_policy
467nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
468 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
469 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
470 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
471};
472
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300473static const struct nla_policy
474nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200475 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300476 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700477 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300478};
479
Johannes Berg97990a02013-04-19 01:02:55 +0200480static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
481 struct netlink_callback *cb,
482 struct cfg80211_registered_device **rdev,
483 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100484{
Johannes Berg67748892010-10-04 21:14:06 +0200485 int err;
486
Johannes Berg67748892010-10-04 21:14:06 +0200487 rtnl_lock();
488
Johannes Berg97990a02013-04-19 01:02:55 +0200489 if (!cb->args[0]) {
490 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
491 nl80211_fam.attrbuf, nl80211_fam.maxattr,
492 nl80211_policy);
493 if (err)
494 goto out_unlock;
495
496 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
497 nl80211_fam.attrbuf);
498 if (IS_ERR(*wdev)) {
499 err = PTR_ERR(*wdev);
500 goto out_unlock;
501 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800502 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200503 /* 0 is the first index - add 1 to parse only once */
504 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200505 cb->args[1] = (*wdev)->identifier;
506 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200507 /* subtract the 1 again here */
508 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200509 struct wireless_dev *tmp;
510
511 if (!wiphy) {
512 err = -ENODEV;
513 goto out_unlock;
514 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800515 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200516 *wdev = NULL;
517
Johannes Berg97990a02013-04-19 01:02:55 +0200518 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
519 if (tmp->identifier == cb->args[1]) {
520 *wdev = tmp;
521 break;
522 }
523 }
Johannes Berg97990a02013-04-19 01:02:55 +0200524
525 if (!*wdev) {
526 err = -ENODEV;
527 goto out_unlock;
528 }
Johannes Berg67748892010-10-04 21:14:06 +0200529 }
530
Johannes Berg67748892010-10-04 21:14:06 +0200531 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200532 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200533 rtnl_unlock();
534 return err;
535}
536
Johannes Berg97990a02013-04-19 01:02:55 +0200537static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200538{
Johannes Berg67748892010-10-04 21:14:06 +0200539 rtnl_unlock();
540}
541
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100542/* IE validation */
543static bool is_valid_ie_attr(const struct nlattr *attr)
544{
545 const u8 *pos;
546 int len;
547
548 if (!attr)
549 return true;
550
551 pos = nla_data(attr);
552 len = nla_len(attr);
553
554 while (len) {
555 u8 elemlen;
556
557 if (len < 2)
558 return false;
559 len -= 2;
560
561 elemlen = pos[1];
562 if (elemlen > len)
563 return false;
564
565 len -= elemlen;
566 pos += 2 + elemlen;
567 }
568
569 return true;
570}
571
Johannes Berg55682962007-09-20 13:09:35 -0400572/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000573static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400574 int flags, u8 cmd)
575{
576 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000577 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400578}
579
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400580static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100581 struct ieee80211_channel *chan,
582 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400583{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200584 /* Some channels must be completely excluded from the
585 * list to protect old user-space tools from breaking
586 */
587 if (!large && chan->flags &
588 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
589 return 0;
590
David S. Miller9360ffd2012-03-29 04:41:26 -0400591 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
592 chan->center_freq))
593 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400594
David S. Miller9360ffd2012-03-29 04:41:26 -0400595 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
596 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
597 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200598 if (chan->flags & IEEE80211_CHAN_NO_IR) {
599 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
600 goto nla_put_failure;
601 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
602 goto nla_put_failure;
603 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100604 if (chan->flags & IEEE80211_CHAN_RADAR) {
605 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
606 goto nla_put_failure;
607 if (large) {
608 u32 time;
609
610 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
611
612 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
613 chan->dfs_state))
614 goto nla_put_failure;
615 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
616 time))
617 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100618 if (nla_put_u32(msg,
619 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
620 chan->dfs_cac_ms))
621 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100622 }
623 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400624
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100625 if (large) {
626 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
627 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
628 goto nla_put_failure;
629 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
630 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
631 goto nla_put_failure;
632 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
633 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
634 goto nla_put_failure;
635 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
636 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
637 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200638 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
639 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
640 goto nla_put_failure;
641 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
642 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
643 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200644 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
645 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
646 goto nla_put_failure;
647 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
648 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
649 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100650 }
651
David S. Miller9360ffd2012-03-29 04:41:26 -0400652 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
653 DBM_TO_MBM(chan->max_power)))
654 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400655
656 return 0;
657
658 nla_put_failure:
659 return -ENOBUFS;
660}
661
Johannes Berg55682962007-09-20 13:09:35 -0400662/* netlink command implementations */
663
Johannes Bergb9454e82009-07-08 13:29:08 +0200664struct key_parse {
665 struct key_params p;
666 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200667 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200668 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100669 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200670};
671
672static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
673{
674 struct nlattr *tb[NL80211_KEY_MAX + 1];
675 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
676 nl80211_key_policy);
677 if (err)
678 return err;
679
680 k->def = !!tb[NL80211_KEY_DEFAULT];
681 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
682
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100683 if (k->def) {
684 k->def_uni = true;
685 k->def_multi = true;
686 }
687 if (k->defmgmt)
688 k->def_multi = true;
689
Johannes Bergb9454e82009-07-08 13:29:08 +0200690 if (tb[NL80211_KEY_IDX])
691 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
692
693 if (tb[NL80211_KEY_DATA]) {
694 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
695 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
696 }
697
698 if (tb[NL80211_KEY_SEQ]) {
699 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
700 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
701 }
702
703 if (tb[NL80211_KEY_CIPHER])
704 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
705
Johannes Berge31b8212010-10-05 19:39:30 +0200706 if (tb[NL80211_KEY_TYPE]) {
707 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
708 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
709 return -EINVAL;
710 }
711
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100712 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
713 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100714 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
715 tb[NL80211_KEY_DEFAULT_TYPES],
716 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100717 if (err)
718 return err;
719
720 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
721 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
722 }
723
Johannes Bergb9454e82009-07-08 13:29:08 +0200724 return 0;
725}
726
727static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
728{
729 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
730 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
731 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
732 }
733
734 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
735 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
736 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
737 }
738
739 if (info->attrs[NL80211_ATTR_KEY_IDX])
740 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
741
742 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
743 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
744
745 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
746 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
747
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100748 if (k->def) {
749 k->def_uni = true;
750 k->def_multi = true;
751 }
752 if (k->defmgmt)
753 k->def_multi = true;
754
Johannes Berge31b8212010-10-05 19:39:30 +0200755 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
756 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
757 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
758 return -EINVAL;
759 }
760
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100761 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
762 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
763 int err = nla_parse_nested(
764 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
765 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
766 nl80211_key_default_policy);
767 if (err)
768 return err;
769
770 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
771 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
772 }
773
Johannes Bergb9454e82009-07-08 13:29:08 +0200774 return 0;
775}
776
777static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
778{
779 int err;
780
781 memset(k, 0, sizeof(*k));
782 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200783 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200784
785 if (info->attrs[NL80211_ATTR_KEY])
786 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
787 else
788 err = nl80211_parse_key_old(info, k);
789
790 if (err)
791 return err;
792
793 if (k->def && k->defmgmt)
794 return -EINVAL;
795
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100796 if (k->defmgmt) {
797 if (k->def_uni || !k->def_multi)
798 return -EINVAL;
799 }
800
Johannes Bergb9454e82009-07-08 13:29:08 +0200801 if (k->idx != -1) {
802 if (k->defmgmt) {
803 if (k->idx < 4 || k->idx > 5)
804 return -EINVAL;
805 } else if (k->def) {
806 if (k->idx < 0 || k->idx > 3)
807 return -EINVAL;
808 } else {
809 if (k->idx < 0 || k->idx > 5)
810 return -EINVAL;
811 }
812 }
813
814 return 0;
815}
816
Johannes Bergfffd0932009-07-08 14:22:54 +0200817static struct cfg80211_cached_keys *
818nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530819 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200820{
821 struct key_parse parse;
822 struct nlattr *key;
823 struct cfg80211_cached_keys *result;
824 int rem, err, def = 0;
825
826 result = kzalloc(sizeof(*result), GFP_KERNEL);
827 if (!result)
828 return ERR_PTR(-ENOMEM);
829
830 result->def = -1;
831 result->defmgmt = -1;
832
833 nla_for_each_nested(key, keys, rem) {
834 memset(&parse, 0, sizeof(parse));
835 parse.idx = -1;
836
837 err = nl80211_parse_key_new(key, &parse);
838 if (err)
839 goto error;
840 err = -EINVAL;
841 if (!parse.p.key)
842 goto error;
843 if (parse.idx < 0 || parse.idx > 4)
844 goto error;
845 if (parse.def) {
846 if (def)
847 goto error;
848 def = 1;
849 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100850 if (!parse.def_uni || !parse.def_multi)
851 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200852 } else if (parse.defmgmt)
853 goto error;
854 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200855 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200856 if (err)
857 goto error;
858 result->params[parse.idx].cipher = parse.p.cipher;
859 result->params[parse.idx].key_len = parse.p.key_len;
860 result->params[parse.idx].key = result->data[parse.idx];
861 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530862
863 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
864 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
865 if (no_ht)
866 *no_ht = true;
867 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200868 }
869
870 return result;
871 error:
872 kfree(result);
873 return ERR_PTR(err);
874}
875
876static int nl80211_key_allowed(struct wireless_dev *wdev)
877{
878 ASSERT_WDEV_LOCK(wdev);
879
Johannes Bergfffd0932009-07-08 14:22:54 +0200880 switch (wdev->iftype) {
881 case NL80211_IFTYPE_AP:
882 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200883 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700884 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200885 break;
886 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200887 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200888 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200889 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200890 return -ENOLINK;
891 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100892 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100893 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100894 case NL80211_IFTYPE_MONITOR:
895 case NL80211_IFTYPE_P2P_DEVICE:
896 case NL80211_IFTYPE_WDS:
897 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200898 return -EINVAL;
899 }
900
901 return 0;
902}
903
Jouni Malinen664834d2014-01-15 00:01:44 +0200904static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
905 struct nlattr *tb)
906{
907 struct ieee80211_channel *chan;
908
909 if (tb == NULL)
910 return NULL;
911 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
912 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
913 return NULL;
914 return chan;
915}
916
Johannes Berg7527a782011-05-13 10:58:57 +0200917static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
918{
919 struct nlattr *nl_modes = nla_nest_start(msg, attr);
920 int i;
921
922 if (!nl_modes)
923 goto nla_put_failure;
924
925 i = 0;
926 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400927 if ((ifmodes & 1) && nla_put_flag(msg, i))
928 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200929 ifmodes >>= 1;
930 i++;
931 }
932
933 nla_nest_end(msg, nl_modes);
934 return 0;
935
936nla_put_failure:
937 return -ENOBUFS;
938}
939
940static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100941 struct sk_buff *msg,
942 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200943{
944 struct nlattr *nl_combis;
945 int i, j;
946
947 nl_combis = nla_nest_start(msg,
948 NL80211_ATTR_INTERFACE_COMBINATIONS);
949 if (!nl_combis)
950 goto nla_put_failure;
951
952 for (i = 0; i < wiphy->n_iface_combinations; i++) {
953 const struct ieee80211_iface_combination *c;
954 struct nlattr *nl_combi, *nl_limits;
955
956 c = &wiphy->iface_combinations[i];
957
958 nl_combi = nla_nest_start(msg, i + 1);
959 if (!nl_combi)
960 goto nla_put_failure;
961
962 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
963 if (!nl_limits)
964 goto nla_put_failure;
965
966 for (j = 0; j < c->n_limits; j++) {
967 struct nlattr *nl_limit;
968
969 nl_limit = nla_nest_start(msg, j + 1);
970 if (!nl_limit)
971 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400972 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
973 c->limits[j].max))
974 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200975 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
976 c->limits[j].types))
977 goto nla_put_failure;
978 nla_nest_end(msg, nl_limit);
979 }
980
981 nla_nest_end(msg, nl_limits);
982
David S. Miller9360ffd2012-03-29 04:41:26 -0400983 if (c->beacon_int_infra_match &&
984 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
985 goto nla_put_failure;
986 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
987 c->num_different_channels) ||
988 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
989 c->max_interfaces))
990 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100991 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200992 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
993 c->radar_detect_widths) ||
994 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
995 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100996 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200997
998 nla_nest_end(msg, nl_combi);
999 }
1000
1001 nla_nest_end(msg, nl_combis);
1002
1003 return 0;
1004nla_put_failure:
1005 return -ENOBUFS;
1006}
1007
Johannes Berg3713b4e2013-02-14 16:19:38 +01001008#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001009static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1010 struct sk_buff *msg)
1011{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001012 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001013 struct nlattr *nl_tcp;
1014
1015 if (!tcp)
1016 return 0;
1017
1018 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1019 if (!nl_tcp)
1020 return -ENOBUFS;
1021
1022 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1023 tcp->data_payload_max))
1024 return -ENOBUFS;
1025
1026 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1027 tcp->data_payload_max))
1028 return -ENOBUFS;
1029
1030 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1031 return -ENOBUFS;
1032
1033 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1034 sizeof(*tcp->tok), tcp->tok))
1035 return -ENOBUFS;
1036
1037 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1038 tcp->data_interval_max))
1039 return -ENOBUFS;
1040
1041 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1042 tcp->wake_payload_max))
1043 return -ENOBUFS;
1044
1045 nla_nest_end(msg, nl_tcp);
1046 return 0;
1047}
1048
Johannes Berg3713b4e2013-02-14 16:19:38 +01001049static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001050 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001051 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001052{
1053 struct nlattr *nl_wowlan;
1054
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001055 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001056 return 0;
1057
1058 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1059 if (!nl_wowlan)
1060 return -ENOBUFS;
1061
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001062 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001063 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001064 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001065 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001066 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001067 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001068 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001069 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001070 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001071 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001072 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001073 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001074 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001075 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001076 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001077 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1078 return -ENOBUFS;
1079
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001080 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001081 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001082 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1083 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1084 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1085 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001086 };
1087
1088 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1089 sizeof(pat), &pat))
1090 return -ENOBUFS;
1091 }
1092
Luciano Coelho75453cc2015-01-09 14:06:37 +02001093 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1094 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1095 rdev->wiphy.wowlan->max_nd_match_sets))
1096 return -ENOBUFS;
1097
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001098 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001099 return -ENOBUFS;
1100
Luciano Coelho8cd4d452014-09-17 11:55:28 +03001101 /* TODO: send wowlan net detect */
1102
Johannes Berg3713b4e2013-02-14 16:19:38 +01001103 nla_nest_end(msg, nl_wowlan);
1104
1105 return 0;
1106}
1107#endif
1108
Amitkumar Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Berg2e161f782010-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 Berg2e161f782010-08-12 15:38:38 +02001544 goto nla_put_failure;
Johannes Berg2e161f782010-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 Berg2e161f782010-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 Berg2e161f782010-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 Karwarbe29b99a2013-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 Karwarbe29b99a2013-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 Berg55682962007-09-20 13:09:35 -04001726 return genlmsg_end(msg, hdr);
1727
1728 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001729 genlmsg_cancel(msg, hdr);
1730 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001731}
1732
Johannes Berg86e8cf92013-06-19 10:57:22 +02001733static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1734 struct netlink_callback *cb,
1735 struct nl80211_dump_wiphy_state *state)
1736{
1737 struct nlattr **tb = nl80211_fam.attrbuf;
1738 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1739 tb, nl80211_fam.maxattr, nl80211_policy);
1740 /* ignore parse errors for backward compatibility */
1741 if (ret)
1742 return 0;
1743
1744 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1745 if (tb[NL80211_ATTR_WIPHY])
1746 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1747 if (tb[NL80211_ATTR_WDEV])
1748 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1749 if (tb[NL80211_ATTR_IFINDEX]) {
1750 struct net_device *netdev;
1751 struct cfg80211_registered_device *rdev;
1752 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1753
Ying Xue7f2b8562014-01-15 10:23:45 +08001754 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001755 if (!netdev)
1756 return -ENODEV;
1757 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001758 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001759 netdev->ieee80211_ptr->wiphy);
1760 state->filter_wiphy = rdev->wiphy_idx;
1761 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001762 }
1763
1764 return 0;
1765}
1766
Johannes Berg55682962007-09-20 13:09:35 -04001767static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1768{
Johannes Berg645e77d2013-03-01 14:03:49 +01001769 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001770 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001771 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001772
Johannes Berg5fe231e2013-05-08 21:45:15 +02001773 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001774 if (!state) {
1775 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001776 if (!state) {
1777 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001780 state->filter_wiphy = -1;
1781 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1782 if (ret) {
1783 kfree(state);
1784 rtnl_unlock();
1785 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001786 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001787 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 }
1789
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001790 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1791 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001792 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001793 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001794 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001795 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001796 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001797 continue;
1798 /* attempt to fit multiple wiphy data chunks into the skb */
1799 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001800 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1801 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001802 NETLINK_CB(cb->skb).portid,
1803 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001805 if (ret < 0) {
1806 /*
1807 * If sending the wiphy data didn't fit (ENOBUFS
1808 * or EMSGSIZE returned), this SKB is still
1809 * empty (so it's not too big because another
1810 * wiphy dataset is already in the skb) and
1811 * we've not tried to adjust the dump allocation
1812 * yet ... then adjust the alloc size to be
1813 * bigger, and return 1 but with the empty skb.
1814 * This results in an empty message being RX'ed
1815 * in userspace, but that is ignored.
1816 *
1817 * We can then retry with the larger buffer.
1818 */
1819 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001820 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001821 cb->min_dump_alloc < 4096) {
1822 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001823 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001824 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001825 return 1;
1826 }
1827 idx--;
1828 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001829 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001830 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001831 break;
Johannes Berg55682962007-09-20 13:09:35 -04001832 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001833 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001834
Johannes Berg86e8cf92013-06-19 10:57:22 +02001835 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001836
1837 return skb->len;
1838}
1839
Johannes Berg86e8cf92013-06-19 10:57:22 +02001840static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1841{
1842 kfree((void *)cb->args[0]);
1843 return 0;
1844}
1845
Johannes Berg55682962007-09-20 13:09:35 -04001846static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1847{
1848 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001850 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001851
Johannes Berg645e77d2013-03-01 14:03:49 +01001852 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001853 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001854 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001855
Johannes Berg3bb20552014-05-26 13:52:25 +02001856 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1857 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001858 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001859 nlmsg_free(msg);
1860 return -ENOBUFS;
1861 }
Johannes Berg55682962007-09-20 13:09:35 -04001862
Johannes Berg134e6372009-07-10 09:51:34 +00001863 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001864}
1865
Jouni Malinen31888482008-10-30 16:59:24 +02001866static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1867 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1868 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1869 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1870 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1871 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1872};
1873
1874static int parse_txq_params(struct nlattr *tb[],
1875 struct ieee80211_txq_params *txq_params)
1876{
Johannes Berga3304b02012-03-28 11:04:24 +02001877 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001878 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1879 !tb[NL80211_TXQ_ATTR_AIFS])
1880 return -EINVAL;
1881
Johannes Berga3304b02012-03-28 11:04:24 +02001882 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001883 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1884 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1885 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1886 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1887
Johannes Berga3304b02012-03-28 11:04:24 +02001888 if (txq_params->ac >= NL80211_NUM_ACS)
1889 return -EINVAL;
1890
Jouni Malinen31888482008-10-30 16:59:24 +02001891 return 0;
1892}
1893
Johannes Bergf444de02010-05-05 15:25:02 +02001894static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1895{
1896 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001897 * You can only set the channel explicitly for WDS interfaces,
1898 * all others have their channel managed via their respective
1899 * "establish a connection" command (connect, join, ...)
1900 *
1901 * For AP/GO and mesh mode, the channel can be set with the
1902 * channel userspace API, but is only stored and passed to the
1903 * low-level driver when the AP starts or the mesh is joined.
1904 * This is for backward compatibility, userspace can also give
1905 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001906 *
1907 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001908 * whatever else is going on, so they have their own special
1909 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001910 */
1911 return !wdev ||
1912 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001913 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001914 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1915 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001916}
1917
Johannes Berg683b6d32012-11-08 21:25:48 +01001918static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1919 struct genl_info *info,
1920 struct cfg80211_chan_def *chandef)
1921{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301922 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001923
1924 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1925 return -EINVAL;
1926
1927 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1928
1929 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001930 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1931 chandef->center_freq1 = control_freq;
1932 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001933
1934 /* Primary channel not allowed */
1935 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1936 return -EINVAL;
1937
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1939 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001940
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001941 chantype = nla_get_u32(
1942 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1943
1944 switch (chantype) {
1945 case NL80211_CHAN_NO_HT:
1946 case NL80211_CHAN_HT20:
1947 case NL80211_CHAN_HT40PLUS:
1948 case NL80211_CHAN_HT40MINUS:
1949 cfg80211_chandef_create(chandef, chandef->chan,
1950 chantype);
1951 break;
1952 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001953 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001954 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001955 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1956 chandef->width =
1957 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1958 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1959 chandef->center_freq1 =
1960 nla_get_u32(
1961 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1962 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1963 chandef->center_freq2 =
1964 nla_get_u32(
1965 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1966 }
1967
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001968 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001969 return -EINVAL;
1970
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001971 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1972 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001973 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001974
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001975 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1976 chandef->width == NL80211_CHAN_WIDTH_10) &&
1977 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1978 return -EINVAL;
1979
Johannes Berg683b6d32012-11-08 21:25:48 +01001980 return 0;
1981}
1982
Johannes Bergf444de02010-05-05 15:25:02 +02001983static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001984 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001985 struct genl_info *info)
1986{
Johannes Berg683b6d32012-11-08 21:25:48 +01001987 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001988 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001989 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001990 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001991
Jouni Malinene16821b2014-04-28 11:22:08 +03001992 if (dev)
1993 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001994 if (!nl80211_can_set_dev_channel(wdev))
1995 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001996 if (wdev)
1997 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001998
Johannes Berg683b6d32012-11-08 21:25:48 +01001999 result = nl80211_parse_chandef(rdev, info, &chandef);
2000 if (result)
2001 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002002
Johannes Berge8c9bd52012-06-06 08:18:22 +02002003 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002004 case NL80211_IFTYPE_AP:
2005 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02002006 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002007 result = -EINVAL;
2008 break;
2009 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002010 if (wdev->beacon_interval) {
2011 if (!dev || !rdev->ops->set_ap_chanwidth ||
2012 !(rdev->wiphy.features &
2013 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2014 result = -EBUSY;
2015 break;
2016 }
2017
2018 /* Only allow dynamic channel width changes */
2019 if (chandef.chan != wdev->preset_chandef.chan) {
2020 result = -EBUSY;
2021 break;
2022 }
2023 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2024 if (result)
2025 break;
2026 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002027 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002028 result = 0;
2029 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002030 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002031 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002032 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002033 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002034 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002035 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002036 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002037 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002038 }
Johannes Bergf444de02010-05-05 15:25:02 +02002039
2040 return result;
2041}
2042
2043static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2044{
Johannes Berg4c476992010-10-04 21:36:35 +02002045 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2046 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002047
Jouni Malinene16821b2014-04-28 11:22:08 +03002048 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002049}
2050
Bill Jordane8347eb2010-10-01 13:54:28 -04002051static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2052{
Johannes Berg43b19952010-10-07 13:10:30 +02002053 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2054 struct net_device *dev = info->user_ptr[1];
2055 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002056 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002057
2058 if (!info->attrs[NL80211_ATTR_MAC])
2059 return -EINVAL;
2060
Johannes Berg43b19952010-10-07 13:10:30 +02002061 if (netif_running(dev))
2062 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002063
Johannes Berg43b19952010-10-07 13:10:30 +02002064 if (!rdev->ops->set_wds_peer)
2065 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002066
Johannes Berg43b19952010-10-07 13:10:30 +02002067 if (wdev->iftype != NL80211_IFTYPE_WDS)
2068 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002069
2070 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002071 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002072}
2073
2074
Johannes Berg55682962007-09-20 13:09:35 -04002075static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2076{
2077 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002078 struct net_device *netdev = NULL;
2079 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002080 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002081 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002082 u32 changed;
2083 u8 retry_short = 0, retry_long = 0;
2084 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002085 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002086
Johannes Berg5fe231e2013-05-08 21:45:15 +02002087 ASSERT_RTNL();
2088
Johannes Bergf444de02010-05-05 15:25:02 +02002089 /*
2090 * Try to find the wiphy and netdev. Normally this
2091 * function shouldn't need the netdev, but this is
2092 * done for backward compatibility -- previously
2093 * setting the channel was done per wiphy, but now
2094 * it is per netdev. Previous userland like hostapd
2095 * also passed a netdev to set_wiphy, so that it is
2096 * possible to let that go to the right netdev!
2097 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002098
Johannes Bergf444de02010-05-05 15:25:02 +02002099 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2100 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2101
Ying Xue7f2b8562014-01-15 10:23:45 +08002102 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002103 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002104 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002105 else
Johannes Bergf444de02010-05-05 15:25:02 +02002106 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002107 }
2108
Johannes Bergf444de02010-05-05 15:25:02 +02002109 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002110 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2111 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002112 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002113 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002114 wdev = NULL;
2115 netdev = NULL;
2116 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002117 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002118 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002119
2120 /*
2121 * end workaround code, by now the rdev is available
2122 * and locked, and wdev may or may not be NULL.
2123 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002124
2125 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002126 result = cfg80211_dev_rename(
2127 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002128
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002129 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002130 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002131
Jouni Malinen31888482008-10-30 16:59:24 +02002132 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2133 struct ieee80211_txq_params txq_params;
2134 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2135
Ying Xue7f2b8562014-01-15 10:23:45 +08002136 if (!rdev->ops->set_txq_params)
2137 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002138
Ying Xue7f2b8562014-01-15 10:23:45 +08002139 if (!netdev)
2140 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002141
Johannes Berg133a3ff2011-11-03 14:50:13 +01002142 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002143 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2144 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002145
Ying Xue7f2b8562014-01-15 10:23:45 +08002146 if (!netif_running(netdev))
2147 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002148
Jouni Malinen31888482008-10-30 16:59:24 +02002149 nla_for_each_nested(nl_txq_params,
2150 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2151 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002152 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2153 nla_data(nl_txq_params),
2154 nla_len(nl_txq_params),
2155 txq_params_policy);
2156 if (result)
2157 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002158 result = parse_txq_params(tb, &txq_params);
2159 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002160 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002161
Hila Gonene35e4d22012-06-27 17:19:42 +03002162 result = rdev_set_txq_params(rdev, netdev,
2163 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002164 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002165 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002166 }
2167 }
2168
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002169 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002170 result = __nl80211_set_channel(
2171 rdev,
2172 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2173 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002174 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002175 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002176 }
2177
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002178 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002179 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002180 enum nl80211_tx_power_setting type;
2181 int idx, mbm = 0;
2182
Johannes Bergc8442112012-10-24 10:17:18 +02002183 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2184 txp_wdev = NULL;
2185
Ying Xue7f2b8562014-01-15 10:23:45 +08002186 if (!rdev->ops->set_tx_power)
2187 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002188
2189 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2190 type = nla_get_u32(info->attrs[idx]);
2191
2192 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002193 (type != NL80211_TX_POWER_AUTOMATIC))
2194 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002195
2196 if (type != NL80211_TX_POWER_AUTOMATIC) {
2197 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2198 mbm = nla_get_u32(info->attrs[idx]);
2199 }
2200
Johannes Bergc8442112012-10-24 10:17:18 +02002201 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002202 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002203 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002204 }
2205
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002206 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2207 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2208 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002209 if ((!rdev->wiphy.available_antennas_tx &&
2210 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002211 !rdev->ops->set_antenna)
2212 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002213
2214 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2215 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2216
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002217 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002218 * available antenna masks, except for the "all" mask */
2219 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002220 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2221 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002222
Bruno Randolf7f531e02010-12-16 11:30:22 +09002223 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2224 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002225
Hila Gonene35e4d22012-06-27 17:19:42 +03002226 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002227 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002229 }
2230
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002231 changed = 0;
2232
2233 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2234 retry_short = nla_get_u8(
2235 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002236 if (retry_short == 0)
2237 return -EINVAL;
2238
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002239 changed |= WIPHY_PARAM_RETRY_SHORT;
2240 }
2241
2242 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2243 retry_long = nla_get_u8(
2244 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002245 if (retry_long == 0)
2246 return -EINVAL;
2247
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002248 changed |= WIPHY_PARAM_RETRY_LONG;
2249 }
2250
2251 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2252 frag_threshold = nla_get_u32(
2253 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002254 if (frag_threshold < 256)
2255 return -EINVAL;
2256
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002257 if (frag_threshold != (u32) -1) {
2258 /*
2259 * Fragments (apart from the last one) are required to
2260 * have even length. Make the fragmentation code
2261 * simpler by stripping LSB should someone try to use
2262 * odd threshold value.
2263 */
2264 frag_threshold &= ~0x1;
2265 }
2266 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2267 }
2268
2269 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2270 rts_threshold = nla_get_u32(
2271 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2272 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2273 }
2274
Lukáš Turek81077e82009-12-21 22:50:47 +01002275 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002276 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2277 return -EINVAL;
2278
Lukáš Turek81077e82009-12-21 22:50:47 +01002279 coverage_class = nla_get_u8(
2280 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2281 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2282 }
2283
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002284 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2285 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2286 return -EOPNOTSUPP;
2287
2288 changed |= WIPHY_PARAM_DYN_ACK;
2289 }
2290
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002291 if (changed) {
2292 u8 old_retry_short, old_retry_long;
2293 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002294 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002295
Ying Xue7f2b8562014-01-15 10:23:45 +08002296 if (!rdev->ops->set_wiphy_params)
2297 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002298
2299 old_retry_short = rdev->wiphy.retry_short;
2300 old_retry_long = rdev->wiphy.retry_long;
2301 old_frag_threshold = rdev->wiphy.frag_threshold;
2302 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002303 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002304
2305 if (changed & WIPHY_PARAM_RETRY_SHORT)
2306 rdev->wiphy.retry_short = retry_short;
2307 if (changed & WIPHY_PARAM_RETRY_LONG)
2308 rdev->wiphy.retry_long = retry_long;
2309 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2310 rdev->wiphy.frag_threshold = frag_threshold;
2311 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2312 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002313 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2314 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002315
Hila Gonene35e4d22012-06-27 17:19:42 +03002316 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002317 if (result) {
2318 rdev->wiphy.retry_short = old_retry_short;
2319 rdev->wiphy.retry_long = old_retry_long;
2320 rdev->wiphy.frag_threshold = old_frag_threshold;
2321 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002322 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002323 }
2324 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002325 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002326}
2327
Johannes Berg71bbc992012-06-15 15:30:18 +02002328static inline u64 wdev_id(struct wireless_dev *wdev)
2329{
2330 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002331 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002332}
Johannes Berg55682962007-09-20 13:09:35 -04002333
Johannes Berg683b6d32012-11-08 21:25:48 +01002334static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002335 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002336{
Johannes Berg601555c2014-11-27 17:26:56 +01002337 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2338 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002339
Johannes Berg683b6d32012-11-08 21:25:48 +01002340 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2341 chandef->chan->center_freq))
2342 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002343 switch (chandef->width) {
2344 case NL80211_CHAN_WIDTH_20_NOHT:
2345 case NL80211_CHAN_WIDTH_20:
2346 case NL80211_CHAN_WIDTH_40:
2347 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2348 cfg80211_get_chandef_type(chandef)))
2349 return -ENOBUFS;
2350 break;
2351 default:
2352 break;
2353 }
2354 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2355 return -ENOBUFS;
2356 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2357 return -ENOBUFS;
2358 if (chandef->center_freq2 &&
2359 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002360 return -ENOBUFS;
2361 return 0;
2362}
2363
Eric W. Biederman15e47302012-09-07 20:12:54 +00002364static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002365 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002366 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002367{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002368 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002369 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002370 void *hdr;
2371
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002372 if (removal)
2373 cmd = NL80211_CMD_DEL_INTERFACE;
2374
2375 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002376 if (!hdr)
2377 return -1;
2378
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002379 if (dev &&
2380 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002381 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002382 goto nla_put_failure;
2383
2384 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2385 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002386 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002387 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002388 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2389 rdev->devlist_generation ^
2390 (cfg80211_rdev_list_generation << 2)))
2391 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002392
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002393 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002394 int ret;
2395 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002396
Johannes Berg683b6d32012-11-08 21:25:48 +01002397 ret = rdev_get_channel(rdev, wdev, &chandef);
2398 if (ret == 0) {
2399 if (nl80211_send_chandef(msg, &chandef))
2400 goto nla_put_failure;
2401 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002402 }
2403
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002404 if (wdev->ssid_len) {
2405 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2406 goto nla_put_failure;
2407 }
2408
Johannes Berg55682962007-09-20 13:09:35 -04002409 return genlmsg_end(msg, hdr);
2410
2411 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002412 genlmsg_cancel(msg, hdr);
2413 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002414}
2415
2416static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2417{
2418 int wp_idx = 0;
2419 int if_idx = 0;
2420 int wp_start = cb->args[0];
2421 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002422 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002423 struct wireless_dev *wdev;
2424
Johannes Berg5fe231e2013-05-08 21:45:15 +02002425 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002426 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2427 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002428 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002429 if (wp_idx < wp_start) {
2430 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002431 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002432 }
Johannes Berg55682962007-09-20 13:09:35 -04002433 if_idx = 0;
2434
Johannes Berg89a54e42012-06-15 14:33:17 +02002435 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002436 if (if_idx < if_start) {
2437 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002438 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002439 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002440 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002441 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002442 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002443 goto out;
2444 }
2445 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002446 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002447
2448 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002449 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002450 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002451 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002452
2453 cb->args[0] = wp_idx;
2454 cb->args[1] = if_idx;
2455
2456 return skb->len;
2457}
2458
2459static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2460{
2461 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002462 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002463 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002464
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002465 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002466 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002467 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002468
Eric W. Biederman15e47302012-09-07 20:12:54 +00002469 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002470 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002471 nlmsg_free(msg);
2472 return -ENOBUFS;
2473 }
Johannes Berg55682962007-09-20 13:09:35 -04002474
Johannes Berg134e6372009-07-10 09:51:34 +00002475 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002476}
2477
Michael Wu66f7ac52008-01-31 19:48:22 +01002478static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2479 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2480 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2481 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2482 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2483 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002484 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002485};
2486
2487static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2488{
2489 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2490 int flag;
2491
2492 *mntrflags = 0;
2493
2494 if (!nla)
2495 return -EINVAL;
2496
2497 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2498 nla, mntr_flags_policy))
2499 return -EINVAL;
2500
2501 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2502 if (flags[flag])
2503 *mntrflags |= (1<<flag);
2504
2505 return 0;
2506}
2507
Johannes Berg9bc383d2009-11-19 11:55:19 +01002508static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002509 struct net_device *netdev, u8 use_4addr,
2510 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002511{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002512 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002513 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002514 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002515 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002516 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002517
2518 switch (iftype) {
2519 case NL80211_IFTYPE_AP_VLAN:
2520 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2521 return 0;
2522 break;
2523 case NL80211_IFTYPE_STATION:
2524 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2525 return 0;
2526 break;
2527 default:
2528 break;
2529 }
2530
2531 return -EOPNOTSUPP;
2532}
2533
Johannes Berg55682962007-09-20 13:09:35 -04002534static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2535{
Johannes Berg4c476992010-10-04 21:36:35 +02002536 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002537 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002538 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002539 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002540 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002541 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002542 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002543
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002544 memset(&params, 0, sizeof(params));
2545
Johannes Berg04a773a2009-04-19 21:24:32 +02002546 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002547
Johannes Berg723b0382008-09-16 20:22:09 +02002548 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002549 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002550 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002551 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002552 if (ntype > NL80211_IFTYPE_MAX)
2553 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002554 }
2555
Johannes Berg92ffe052008-09-16 20:39:36 +02002556 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002557 struct wireless_dev *wdev = dev->ieee80211_ptr;
2558
Johannes Berg4c476992010-10-04 21:36:35 +02002559 if (ntype != NL80211_IFTYPE_MESH_POINT)
2560 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002561 if (netif_running(dev))
2562 return -EBUSY;
2563
2564 wdev_lock(wdev);
2565 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2566 IEEE80211_MAX_MESH_ID_LEN);
2567 wdev->mesh_id_up_len =
2568 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2569 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2570 wdev->mesh_id_up_len);
2571 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002572 }
2573
Felix Fietkau8b787642009-11-10 18:53:10 +01002574 if (info->attrs[NL80211_ATTR_4ADDR]) {
2575 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2576 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002577 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002578 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002579 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002580 } else {
2581 params.use_4addr = -1;
2582 }
2583
Johannes Berg92ffe052008-09-16 20:39:36 +02002584 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002585 if (ntype != NL80211_IFTYPE_MONITOR)
2586 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002587 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2588 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002589 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002590 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002591
2592 flags = &_flags;
2593 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002594 }
Johannes Berg3b858752009-03-12 09:55:09 +01002595
Luciano Coelho18003292013-08-29 13:26:57 +03002596 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002597 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2598 return -EOPNOTSUPP;
2599
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002600 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002601 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002602 else
2603 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002604
Johannes Berg9bc383d2009-11-19 11:55:19 +01002605 if (!err && params.use_4addr != -1)
2606 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2607
Johannes Berg55682962007-09-20 13:09:35 -04002608 return err;
2609}
2610
2611static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2612{
Johannes Berg4c476992010-10-04 21:36:35 +02002613 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002614 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002615 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002616 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002617 int err;
2618 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002619 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002620
Johannes Berg78f22b62014-03-24 17:57:27 +01002621 /* to avoid failing a new interface creation due to pending removal */
2622 cfg80211_destroy_ifaces(rdev);
2623
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002624 memset(&params, 0, sizeof(params));
2625
Johannes Berg55682962007-09-20 13:09:35 -04002626 if (!info->attrs[NL80211_ATTR_IFNAME])
2627 return -EINVAL;
2628
2629 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2630 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2631 if (type > NL80211_IFTYPE_MAX)
2632 return -EINVAL;
2633 }
2634
Johannes Berg79c97e92009-07-07 03:56:12 +02002635 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002636 !(rdev->wiphy.interface_modes & (1 << type)))
2637 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002638
Ben Greeare8f479b2014-10-22 12:23:05 -07002639 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2640 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2641 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002642 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2643 ETH_ALEN);
2644 if (!is_valid_ether_addr(params.macaddr))
2645 return -EADDRNOTAVAIL;
2646 }
2647
Johannes Berg9bc383d2009-11-19 11:55:19 +01002648 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002649 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002650 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002651 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002652 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002653 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002654
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002655 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2656 if (!msg)
2657 return -ENOMEM;
2658
Michael Wu66f7ac52008-01-31 19:48:22 +01002659 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2660 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2661 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002662
Luciano Coelho18003292013-08-29 13:26:57 +03002663 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002664 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2665 return -EOPNOTSUPP;
2666
Hila Gonene35e4d22012-06-27 17:19:42 +03002667 wdev = rdev_add_virtual_intf(rdev,
2668 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2669 type, err ? NULL : &flags, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002670 if (WARN_ON(!wdev)) {
2671 nlmsg_free(msg);
2672 return -EPROTO;
2673 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002674 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002675 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002676 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002677
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002678 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002679 wdev->owner_nlportid = info->snd_portid;
2680
Johannes Berg98104fde2012-06-16 00:19:54 +02002681 switch (type) {
2682 case NL80211_IFTYPE_MESH_POINT:
2683 if (!info->attrs[NL80211_ATTR_MESH_ID])
2684 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002685 wdev_lock(wdev);
2686 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2687 IEEE80211_MAX_MESH_ID_LEN);
2688 wdev->mesh_id_up_len =
2689 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2690 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2691 wdev->mesh_id_up_len);
2692 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002693 break;
2694 case NL80211_IFTYPE_P2P_DEVICE:
2695 /*
2696 * P2P Device doesn't have a netdev, so doesn't go
2697 * through the netdev notifier and must be added here
2698 */
2699 mutex_init(&wdev->mtx);
2700 INIT_LIST_HEAD(&wdev->event_list);
2701 spin_lock_init(&wdev->event_lock);
2702 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2703 spin_lock_init(&wdev->mgmt_registrations_lock);
2704
Johannes Berg98104fde2012-06-16 00:19:54 +02002705 wdev->identifier = ++rdev->wdev_id;
2706 list_add_rcu(&wdev->list, &rdev->wdev_list);
2707 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002708 break;
2709 default:
2710 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002711 }
2712
Eric W. Biederman15e47302012-09-07 20:12:54 +00002713 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002714 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002715 nlmsg_free(msg);
2716 return -ENOBUFS;
2717 }
2718
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002719 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2720 if (event) {
2721 if (nl80211_send_iface(event, 0, 0, 0,
2722 rdev, wdev, false) < 0) {
2723 nlmsg_free(event);
2724 goto out;
2725 }
2726
2727 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2728 event, 0, NL80211_MCGRP_CONFIG,
2729 GFP_KERNEL);
2730 }
2731
2732out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002733 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002734}
2735
2736static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2737{
Johannes Berg4c476992010-10-04 21:36:35 +02002738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002739 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002740 struct sk_buff *msg;
2741 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002742
Johannes Berg4c476992010-10-04 21:36:35 +02002743 if (!rdev->ops->del_virtual_intf)
2744 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002745
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002746 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2747 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2748 nlmsg_free(msg);
2749 msg = NULL;
2750 }
2751
Johannes Berg84efbb82012-06-16 00:00:26 +02002752 /*
2753 * If we remove a wireless device without a netdev then clear
2754 * user_ptr[1] so that nl80211_post_doit won't dereference it
2755 * to check if it needs to do dev_put(). Otherwise it crashes
2756 * since the wdev has been freed, unlike with a netdev where
2757 * we need the dev_put() for the netdev to really be freed.
2758 */
2759 if (!wdev->netdev)
2760 info->user_ptr[1] = NULL;
2761
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002762 status = rdev_del_virtual_intf(rdev, wdev);
2763 if (status >= 0 && msg)
2764 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2765 msg, 0, NL80211_MCGRP_CONFIG,
2766 GFP_KERNEL);
2767 else
2768 nlmsg_free(msg);
2769
2770 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002771}
2772
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002773static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2774{
2775 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2776 struct net_device *dev = info->user_ptr[1];
2777 u16 noack_map;
2778
2779 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2780 return -EINVAL;
2781
2782 if (!rdev->ops->set_noack_map)
2783 return -EOPNOTSUPP;
2784
2785 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2786
Hila Gonene35e4d22012-06-27 17:19:42 +03002787 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002788}
2789
Johannes Berg41ade002007-12-19 02:03:29 +01002790struct get_key_cookie {
2791 struct sk_buff *msg;
2792 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002793 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002794};
2795
2796static void get_key_callback(void *c, struct key_params *params)
2797{
Johannes Bergb9454e82009-07-08 13:29:08 +02002798 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002799 struct get_key_cookie *cookie = c;
2800
David S. Miller9360ffd2012-03-29 04:41:26 -04002801 if ((params->key &&
2802 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2803 params->key_len, params->key)) ||
2804 (params->seq &&
2805 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2806 params->seq_len, params->seq)) ||
2807 (params->cipher &&
2808 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2809 params->cipher)))
2810 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002811
Johannes Bergb9454e82009-07-08 13:29:08 +02002812 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2813 if (!key)
2814 goto nla_put_failure;
2815
David S. Miller9360ffd2012-03-29 04:41:26 -04002816 if ((params->key &&
2817 nla_put(cookie->msg, NL80211_KEY_DATA,
2818 params->key_len, params->key)) ||
2819 (params->seq &&
2820 nla_put(cookie->msg, NL80211_KEY_SEQ,
2821 params->seq_len, params->seq)) ||
2822 (params->cipher &&
2823 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2824 params->cipher)))
2825 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002826
David S. Miller9360ffd2012-03-29 04:41:26 -04002827 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2828 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002829
2830 nla_nest_end(cookie->msg, key);
2831
Johannes Berg41ade002007-12-19 02:03:29 +01002832 return;
2833 nla_put_failure:
2834 cookie->error = 1;
2835}
2836
2837static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2838{
Johannes Berg4c476992010-10-04 21:36:35 +02002839 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002840 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002841 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002842 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002843 const u8 *mac_addr = NULL;
2844 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002845 struct get_key_cookie cookie = {
2846 .error = 0,
2847 };
2848 void *hdr;
2849 struct sk_buff *msg;
2850
2851 if (info->attrs[NL80211_ATTR_KEY_IDX])
2852 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2853
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002854 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002855 return -EINVAL;
2856
2857 if (info->attrs[NL80211_ATTR_MAC])
2858 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2859
Johannes Berge31b8212010-10-05 19:39:30 +02002860 pairwise = !!mac_addr;
2861 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2862 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2863 if (kt >= NUM_NL80211_KEYTYPES)
2864 return -EINVAL;
2865 if (kt != NL80211_KEYTYPE_GROUP &&
2866 kt != NL80211_KEYTYPE_PAIRWISE)
2867 return -EINVAL;
2868 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2869 }
2870
Johannes Berg4c476992010-10-04 21:36:35 +02002871 if (!rdev->ops->get_key)
2872 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002873
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002874 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002875 if (!msg)
2876 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002877
Eric W. Biederman15e47302012-09-07 20:12:54 +00002878 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002879 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002880 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002881 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002882
2883 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002884 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002885
David S. Miller9360ffd2012-03-29 04:41:26 -04002886 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2887 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2888 goto nla_put_failure;
2889 if (mac_addr &&
2890 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2891 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002892
Johannes Berge31b8212010-10-05 19:39:30 +02002893 if (pairwise && mac_addr &&
2894 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2895 return -ENOENT;
2896
Hila Gonene35e4d22012-06-27 17:19:42 +03002897 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2898 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002899
2900 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002901 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002902
2903 if (cookie.error)
2904 goto nla_put_failure;
2905
2906 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002907 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002908
2909 nla_put_failure:
2910 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002911 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002912 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002913 return err;
2914}
2915
2916static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2917{
Johannes Berg4c476992010-10-04 21:36:35 +02002918 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002919 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002920 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002921 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002922
Johannes Bergb9454e82009-07-08 13:29:08 +02002923 err = nl80211_parse_key(info, &key);
2924 if (err)
2925 return err;
2926
2927 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002928 return -EINVAL;
2929
Johannes Bergb9454e82009-07-08 13:29:08 +02002930 /* only support setting default key */
2931 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002932 return -EINVAL;
2933
Johannes Bergfffd0932009-07-08 14:22:54 +02002934 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002935
2936 if (key.def) {
2937 if (!rdev->ops->set_default_key) {
2938 err = -EOPNOTSUPP;
2939 goto out;
2940 }
2941
2942 err = nl80211_key_allowed(dev->ieee80211_ptr);
2943 if (err)
2944 goto out;
2945
Hila Gonene35e4d22012-06-27 17:19:42 +03002946 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002947 key.def_uni, key.def_multi);
2948
2949 if (err)
2950 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002951
Johannes Berg3d23e342009-09-29 23:27:28 +02002952#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002953 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002954#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002955 } else {
2956 if (key.def_uni || !key.def_multi) {
2957 err = -EINVAL;
2958 goto out;
2959 }
2960
2961 if (!rdev->ops->set_default_mgmt_key) {
2962 err = -EOPNOTSUPP;
2963 goto out;
2964 }
2965
2966 err = nl80211_key_allowed(dev->ieee80211_ptr);
2967 if (err)
2968 goto out;
2969
Hila Gonene35e4d22012-06-27 17:19:42 +03002970 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002971 if (err)
2972 goto out;
2973
2974#ifdef CONFIG_CFG80211_WEXT
2975 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2976#endif
2977 }
2978
2979 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002980 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002981
Johannes Berg41ade002007-12-19 02:03:29 +01002982 return err;
2983}
2984
2985static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2986{
Johannes Berg4c476992010-10-04 21:36:35 +02002987 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002988 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002989 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002990 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002991 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002992
Johannes Bergb9454e82009-07-08 13:29:08 +02002993 err = nl80211_parse_key(info, &key);
2994 if (err)
2995 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002996
Johannes Bergb9454e82009-07-08 13:29:08 +02002997 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002998 return -EINVAL;
2999
Johannes Berg41ade002007-12-19 02:03:29 +01003000 if (info->attrs[NL80211_ATTR_MAC])
3001 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3002
Johannes Berge31b8212010-10-05 19:39:30 +02003003 if (key.type == -1) {
3004 if (mac_addr)
3005 key.type = NL80211_KEYTYPE_PAIRWISE;
3006 else
3007 key.type = NL80211_KEYTYPE_GROUP;
3008 }
3009
3010 /* for now */
3011 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3012 key.type != NL80211_KEYTYPE_GROUP)
3013 return -EINVAL;
3014
Johannes Berg4c476992010-10-04 21:36:35 +02003015 if (!rdev->ops->add_key)
3016 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003017
Johannes Berge31b8212010-10-05 19:39:30 +02003018 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3019 key.type == NL80211_KEYTYPE_PAIRWISE,
3020 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003021 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003022
3023 wdev_lock(dev->ieee80211_ptr);
3024 err = nl80211_key_allowed(dev->ieee80211_ptr);
3025 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003026 err = rdev_add_key(rdev, dev, key.idx,
3027 key.type == NL80211_KEYTYPE_PAIRWISE,
3028 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003029 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003030
Johannes Berg41ade002007-12-19 02:03:29 +01003031 return err;
3032}
3033
3034static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3035{
Johannes Berg4c476992010-10-04 21:36:35 +02003036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003037 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003038 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003039 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003040 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003041
Johannes Bergb9454e82009-07-08 13:29:08 +02003042 err = nl80211_parse_key(info, &key);
3043 if (err)
3044 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003045
3046 if (info->attrs[NL80211_ATTR_MAC])
3047 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3048
Johannes Berge31b8212010-10-05 19:39:30 +02003049 if (key.type == -1) {
3050 if (mac_addr)
3051 key.type = NL80211_KEYTYPE_PAIRWISE;
3052 else
3053 key.type = NL80211_KEYTYPE_GROUP;
3054 }
3055
3056 /* for now */
3057 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3058 key.type != NL80211_KEYTYPE_GROUP)
3059 return -EINVAL;
3060
Johannes Berg4c476992010-10-04 21:36:35 +02003061 if (!rdev->ops->del_key)
3062 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003063
Johannes Bergfffd0932009-07-08 14:22:54 +02003064 wdev_lock(dev->ieee80211_ptr);
3065 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003066
3067 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3068 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3069 err = -ENOENT;
3070
Johannes Bergfffd0932009-07-08 14:22:54 +02003071 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003072 err = rdev_del_key(rdev, dev, key.idx,
3073 key.type == NL80211_KEYTYPE_PAIRWISE,
3074 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003075
Johannes Berg3d23e342009-09-29 23:27:28 +02003076#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003077 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003078 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003079 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003080 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003081 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3082 }
3083#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003084 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003085
Johannes Berg41ade002007-12-19 02:03:29 +01003086 return err;
3087}
3088
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303089/* This function returns an error or the number of nested attributes */
3090static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3091{
3092 struct nlattr *attr;
3093 int n_entries = 0, tmp;
3094
3095 nla_for_each_nested(attr, nl_attr, tmp) {
3096 if (nla_len(attr) != ETH_ALEN)
3097 return -EINVAL;
3098
3099 n_entries++;
3100 }
3101
3102 return n_entries;
3103}
3104
3105/*
3106 * This function parses ACL information and allocates memory for ACL data.
3107 * On successful return, the calling function is responsible to free the
3108 * ACL buffer returned by this function.
3109 */
3110static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3111 struct genl_info *info)
3112{
3113 enum nl80211_acl_policy acl_policy;
3114 struct nlattr *attr;
3115 struct cfg80211_acl_data *acl;
3116 int i = 0, n_entries, tmp;
3117
3118 if (!wiphy->max_acl_mac_addrs)
3119 return ERR_PTR(-EOPNOTSUPP);
3120
3121 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3122 return ERR_PTR(-EINVAL);
3123
3124 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3125 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3126 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3127 return ERR_PTR(-EINVAL);
3128
3129 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3130 return ERR_PTR(-EINVAL);
3131
3132 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3133 if (n_entries < 0)
3134 return ERR_PTR(n_entries);
3135
3136 if (n_entries > wiphy->max_acl_mac_addrs)
3137 return ERR_PTR(-ENOTSUPP);
3138
3139 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3140 GFP_KERNEL);
3141 if (!acl)
3142 return ERR_PTR(-ENOMEM);
3143
3144 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3145 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3146 i++;
3147 }
3148
3149 acl->n_acl_entries = n_entries;
3150 acl->acl_policy = acl_policy;
3151
3152 return acl;
3153}
3154
3155static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3156{
3157 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3158 struct net_device *dev = info->user_ptr[1];
3159 struct cfg80211_acl_data *acl;
3160 int err;
3161
3162 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3163 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3164 return -EOPNOTSUPP;
3165
3166 if (!dev->ieee80211_ptr->beacon_interval)
3167 return -EINVAL;
3168
3169 acl = parse_acl_data(&rdev->wiphy, info);
3170 if (IS_ERR(acl))
3171 return PTR_ERR(acl);
3172
3173 err = rdev_set_mac_acl(rdev, dev, acl);
3174
3175 kfree(acl);
3176
3177 return err;
3178}
3179
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003180static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003181 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003182{
Johannes Berg88600202012-02-13 15:17:18 +01003183 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003184
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003185 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3186 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3187 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3188 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003189 return -EINVAL;
3190
Johannes Berg88600202012-02-13 15:17:18 +01003191 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003192
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003193 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3194 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3195 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003196 if (!bcn->head_len)
3197 return -EINVAL;
3198 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003199 }
3200
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003201 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3202 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3203 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003204 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003205 }
3206
Johannes Berg4c476992010-10-04 21:36:35 +02003207 if (!haveinfo)
3208 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003209
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003210 if (attrs[NL80211_ATTR_IE]) {
3211 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3212 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003213 }
3214
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003215 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003216 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003217 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003218 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003219 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003220 }
3221
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003222 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003223 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003224 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003225 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003226 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003227 }
3228
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003229 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3230 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3231 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003232 }
3233
Johannes Berg88600202012-02-13 15:17:18 +01003234 return 0;
3235}
3236
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003237static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3238 struct cfg80211_ap_settings *params)
3239{
3240 struct wireless_dev *wdev;
3241 bool ret = false;
3242
Johannes Berg89a54e42012-06-15 14:33:17 +02003243 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003244 if (wdev->iftype != NL80211_IFTYPE_AP &&
3245 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3246 continue;
3247
Johannes Berg683b6d32012-11-08 21:25:48 +01003248 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003249 continue;
3250
Johannes Berg683b6d32012-11-08 21:25:48 +01003251 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003252 ret = true;
3253 break;
3254 }
3255
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003256 return ret;
3257}
3258
Jouni Malinene39e5b52012-09-30 19:29:39 +03003259static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3260 enum nl80211_auth_type auth_type,
3261 enum nl80211_commands cmd)
3262{
3263 if (auth_type > NL80211_AUTHTYPE_MAX)
3264 return false;
3265
3266 switch (cmd) {
3267 case NL80211_CMD_AUTHENTICATE:
3268 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3269 auth_type == NL80211_AUTHTYPE_SAE)
3270 return false;
3271 return true;
3272 case NL80211_CMD_CONNECT:
3273 case NL80211_CMD_START_AP:
3274 /* SAE not supported yet */
3275 if (auth_type == NL80211_AUTHTYPE_SAE)
3276 return false;
3277 return true;
3278 default:
3279 return false;
3280 }
3281}
3282
Johannes Berg88600202012-02-13 15:17:18 +01003283static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3284{
3285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3286 struct net_device *dev = info->user_ptr[1];
3287 struct wireless_dev *wdev = dev->ieee80211_ptr;
3288 struct cfg80211_ap_settings params;
3289 int err;
3290
3291 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3292 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3293 return -EOPNOTSUPP;
3294
3295 if (!rdev->ops->start_ap)
3296 return -EOPNOTSUPP;
3297
3298 if (wdev->beacon_interval)
3299 return -EALREADY;
3300
3301 memset(&params, 0, sizeof(params));
3302
3303 /* these are required for START_AP */
3304 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3305 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3306 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3307 return -EINVAL;
3308
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003309 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003310 if (err)
3311 return err;
3312
3313 params.beacon_interval =
3314 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3315 params.dtim_period =
3316 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3317
3318 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3319 if (err)
3320 return err;
3321
3322 /*
3323 * In theory, some of these attributes should be required here
3324 * but since they were not used when the command was originally
3325 * added, keep them optional for old user space programs to let
3326 * them continue to work with drivers that do not need the
3327 * additional information -- drivers must check!
3328 */
3329 if (info->attrs[NL80211_ATTR_SSID]) {
3330 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3331 params.ssid_len =
3332 nla_len(info->attrs[NL80211_ATTR_SSID]);
3333 if (params.ssid_len == 0 ||
3334 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3335 return -EINVAL;
3336 }
3337
3338 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3339 params.hidden_ssid = nla_get_u32(
3340 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3341 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3342 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3343 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3344 return -EINVAL;
3345 }
3346
3347 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3348
3349 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3350 params.auth_type = nla_get_u32(
3351 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003352 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3353 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003354 return -EINVAL;
3355 } else
3356 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3357
3358 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3359 NL80211_MAX_NR_CIPHER_SUITES);
3360 if (err)
3361 return err;
3362
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303363 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3364 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3365 return -EOPNOTSUPP;
3366 params.inactivity_timeout = nla_get_u16(
3367 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3368 }
3369
Johannes Berg53cabad2012-11-14 15:17:28 +01003370 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3371 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3372 return -EINVAL;
3373 params.p2p_ctwindow =
3374 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3375 if (params.p2p_ctwindow > 127)
3376 return -EINVAL;
3377 if (params.p2p_ctwindow != 0 &&
3378 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3379 return -EINVAL;
3380 }
3381
3382 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3383 u8 tmp;
3384
3385 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3386 return -EINVAL;
3387 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3388 if (tmp > 1)
3389 return -EINVAL;
3390 params.p2p_opp_ps = tmp;
3391 if (params.p2p_opp_ps != 0 &&
3392 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3393 return -EINVAL;
3394 }
3395
Johannes Bergaa430da2012-05-16 23:50:18 +02003396 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003397 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3398 if (err)
3399 return err;
3400 } else if (wdev->preset_chandef.chan) {
3401 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003402 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003403 return -EINVAL;
3404
Ilan Peer174e0cd2014-02-23 09:13:01 +02003405 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3406 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003407 return -EINVAL;
3408
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303409 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3410 params.acl = parse_acl_data(&rdev->wiphy, info);
3411 if (IS_ERR(params.acl))
3412 return PTR_ERR(params.acl);
3413 }
3414
Eliad Peller18998c32014-09-10 14:07:34 +03003415 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3416 params.smps_mode =
3417 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3418 switch (params.smps_mode) {
3419 case NL80211_SMPS_OFF:
3420 break;
3421 case NL80211_SMPS_STATIC:
3422 if (!(rdev->wiphy.features &
3423 NL80211_FEATURE_STATIC_SMPS))
3424 return -EINVAL;
3425 break;
3426 case NL80211_SMPS_DYNAMIC:
3427 if (!(rdev->wiphy.features &
3428 NL80211_FEATURE_DYNAMIC_SMPS))
3429 return -EINVAL;
3430 break;
3431 default:
3432 return -EINVAL;
3433 }
3434 } else {
3435 params.smps_mode = NL80211_SMPS_OFF;
3436 }
3437
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003438 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003439 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003440 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003441 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003442 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003443 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003444 wdev->ssid_len = params.ssid_len;
3445 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003446 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003447 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303448
3449 kfree(params.acl);
3450
Johannes Berg56d18932011-05-09 18:41:15 +02003451 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003452}
3453
Johannes Berg88600202012-02-13 15:17:18 +01003454static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3455{
3456 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3457 struct net_device *dev = info->user_ptr[1];
3458 struct wireless_dev *wdev = dev->ieee80211_ptr;
3459 struct cfg80211_beacon_data params;
3460 int err;
3461
3462 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3463 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3464 return -EOPNOTSUPP;
3465
3466 if (!rdev->ops->change_beacon)
3467 return -EOPNOTSUPP;
3468
3469 if (!wdev->beacon_interval)
3470 return -EINVAL;
3471
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003472 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003473 if (err)
3474 return err;
3475
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003476 wdev_lock(wdev);
3477 err = rdev_change_beacon(rdev, dev, &params);
3478 wdev_unlock(wdev);
3479
3480 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003481}
3482
3483static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003484{
Johannes Berg4c476992010-10-04 21:36:35 +02003485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3486 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003487
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003488 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003489}
3490
Johannes Berg5727ef12007-12-19 02:03:34 +01003491static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3492 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3493 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3494 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003495 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003496 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003497 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003498};
3499
Johannes Bergeccb8e82009-05-11 21:57:56 +03003500static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003501 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003502 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003503{
3504 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003505 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003506 int flag;
3507
Johannes Bergeccb8e82009-05-11 21:57:56 +03003508 /*
3509 * Try parsing the new attribute first so userspace
3510 * can specify both for older kernels.
3511 */
3512 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3513 if (nla) {
3514 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003515
Johannes Bergeccb8e82009-05-11 21:57:56 +03003516 sta_flags = nla_data(nla);
3517 params->sta_flags_mask = sta_flags->mask;
3518 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003519 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003520 if ((params->sta_flags_mask |
3521 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3522 return -EINVAL;
3523 return 0;
3524 }
3525
3526 /* if present, parse the old attribute */
3527
3528 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003529 if (!nla)
3530 return 0;
3531
3532 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3533 nla, sta_flags_policy))
3534 return -EINVAL;
3535
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003536 /*
3537 * Only allow certain flags for interface types so that
3538 * other attributes are silently ignored. Remember that
3539 * this is backward compatibility code with old userspace
3540 * and shouldn't be hit in other cases anyway.
3541 */
3542 switch (iftype) {
3543 case NL80211_IFTYPE_AP:
3544 case NL80211_IFTYPE_AP_VLAN:
3545 case NL80211_IFTYPE_P2P_GO:
3546 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3547 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3548 BIT(NL80211_STA_FLAG_WME) |
3549 BIT(NL80211_STA_FLAG_MFP);
3550 break;
3551 case NL80211_IFTYPE_P2P_CLIENT:
3552 case NL80211_IFTYPE_STATION:
3553 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3554 BIT(NL80211_STA_FLAG_TDLS_PEER);
3555 break;
3556 case NL80211_IFTYPE_MESH_POINT:
3557 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3558 BIT(NL80211_STA_FLAG_MFP) |
3559 BIT(NL80211_STA_FLAG_AUTHORIZED);
3560 default:
3561 return -EINVAL;
3562 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003563
Johannes Berg3383b5a2012-05-10 20:14:43 +02003564 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3565 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003566 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003567
Johannes Berg3383b5a2012-05-10 20:14:43 +02003568 /* no longer support new API additions in old API */
3569 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3570 return -EINVAL;
3571 }
3572 }
3573
Johannes Berg5727ef12007-12-19 02:03:34 +01003574 return 0;
3575}
3576
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003577static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3578 int attr)
3579{
3580 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003581 u32 bitrate;
3582 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003583 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003584
3585 rate = nla_nest_start(msg, attr);
3586 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003587 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003588
3589 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3590 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003591 /* report 16-bit bitrate only if we can */
3592 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003593 if (bitrate > 0 &&
3594 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3595 return false;
3596 if (bitrate_compat > 0 &&
3597 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3598 return false;
3599
Johannes Bergb51f3be2015-01-15 16:14:02 +01003600 switch (info->bw) {
3601 case RATE_INFO_BW_5:
3602 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3603 break;
3604 case RATE_INFO_BW_10:
3605 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3606 break;
3607 default:
3608 WARN_ON(1);
3609 /* fall through */
3610 case RATE_INFO_BW_20:
3611 rate_flg = 0;
3612 break;
3613 case RATE_INFO_BW_40:
3614 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3615 break;
3616 case RATE_INFO_BW_80:
3617 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3618 break;
3619 case RATE_INFO_BW_160:
3620 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3621 break;
3622 }
3623
3624 if (rate_flg && nla_put_flag(msg, rate_flg))
3625 return false;
3626
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003627 if (info->flags & RATE_INFO_FLAGS_MCS) {
3628 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3629 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003630 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3631 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3632 return false;
3633 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3634 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3635 return false;
3636 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3637 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003638 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3639 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3640 return false;
3641 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003642
3643 nla_nest_end(msg, rate);
3644 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003645}
3646
Felix Fietkau119363c2013-04-22 16:29:30 +02003647static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3648 int id)
3649{
3650 void *attr;
3651 int i = 0;
3652
3653 if (!mask)
3654 return true;
3655
3656 attr = nla_nest_start(msg, id);
3657 if (!attr)
3658 return false;
3659
3660 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3661 if (!(mask & BIT(i)))
3662 continue;
3663
3664 if (nla_put_u8(msg, i, signal[i]))
3665 return false;
3666 }
3667
3668 nla_nest_end(msg, attr);
3669
3670 return true;
3671}
3672
Johannes Bergcf5ead82014-11-14 17:14:00 +01003673static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3674 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003675 struct cfg80211_registered_device *rdev,
3676 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003677 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003678{
3679 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003680 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003681
Johannes Bergcf5ead82014-11-14 17:14:00 +01003682 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003683 if (!hdr)
3684 return -1;
3685
David S. Miller9360ffd2012-03-29 04:41:26 -04003686 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3687 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3688 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3689 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003690
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003691 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3692 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003693 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003694
3695#define PUT_SINFO(attr, memb, type) do { \
3696 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3697 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3698 sinfo->memb)) \
3699 goto nla_put_failure; \
3700 } while (0)
3701
3702 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3703 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3704
3705 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3706 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003707 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003708 (u32)sinfo->rx_bytes))
3709 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003710
3711 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3712 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003713 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3714 (u32)sinfo->tx_bytes))
3715 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003716
3717 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3718 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3719 PUT_SINFO(LLID, llid, u16);
3720 PUT_SINFO(PLID, plid, u16);
3721 PUT_SINFO(PLINK_STATE, plink_state, u8);
3722
John W. Linville66266b32012-03-15 13:25:41 -04003723 switch (rdev->wiphy.signal_type) {
3724 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003725 PUT_SINFO(SIGNAL, signal, u8);
3726 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003727 break;
3728 default:
3729 break;
3730 }
Johannes Berg319090b2014-11-17 14:08:11 +01003731 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003732 if (!nl80211_put_signal(msg, sinfo->chains,
3733 sinfo->chain_signal,
3734 NL80211_STA_INFO_CHAIN_SIGNAL))
3735 goto nla_put_failure;
3736 }
Johannes Berg319090b2014-11-17 14:08:11 +01003737 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003738 if (!nl80211_put_signal(msg, sinfo->chains,
3739 sinfo->chain_signal_avg,
3740 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3741 goto nla_put_failure;
3742 }
Johannes Berg319090b2014-11-17 14:08:11 +01003743 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003744 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3745 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003746 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003747 }
Johannes Berg319090b2014-11-17 14:08:11 +01003748 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003749 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3750 NL80211_STA_INFO_RX_BITRATE))
3751 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003752 }
Johannes Berg319090b2014-11-17 14:08:11 +01003753
3754 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3755 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3756 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3757 PUT_SINFO(TX_FAILED, tx_failed, u32);
3758 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3759 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3760 PUT_SINFO(LOCAL_PM, local_pm, u32);
3761 PUT_SINFO(PEER_PM, peer_pm, u32);
3762 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3763
3764 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003765 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3766 if (!bss_param)
3767 goto nla_put_failure;
3768
David S. Miller9360ffd2012-03-29 04:41:26 -04003769 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3770 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3771 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3772 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3773 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3774 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3775 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3776 sinfo->bss_param.dtim_period) ||
3777 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3778 sinfo->bss_param.beacon_interval))
3779 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003780
3781 nla_nest_end(msg, bss_param);
3782 }
Johannes Berg319090b2014-11-17 14:08:11 +01003783 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003784 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3785 sizeof(struct nl80211_sta_flag_update),
3786 &sinfo->sta_flags))
3787 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003788
3789 PUT_SINFO(T_OFFSET, t_offset, u64);
3790 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003791 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3792 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003793
3794#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003795
3796 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3797 struct nlattr *tidsattr;
3798 int tid;
3799
3800 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3801 if (!tidsattr)
3802 goto nla_put_failure;
3803
3804 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3805 struct cfg80211_tid_stats *tidstats;
3806 struct nlattr *tidattr;
3807
3808 tidstats = &sinfo->pertid[tid];
3809
3810 if (!tidstats->filled)
3811 continue;
3812
3813 tidattr = nla_nest_start(msg, tid + 1);
3814 if (!tidattr)
3815 goto nla_put_failure;
3816
3817#define PUT_TIDVAL(attr, memb, type) do { \
3818 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3819 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3820 tidstats->memb)) \
3821 goto nla_put_failure; \
3822 } while (0)
3823
3824 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3825 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3826 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3827 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3828
3829#undef PUT_TIDVAL
3830 nla_nest_end(msg, tidattr);
3831 }
3832
3833 nla_nest_end(msg, tidsattr);
3834 }
3835
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003836 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003837
Johannes Berg319090b2014-11-17 14:08:11 +01003838 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003839 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3840 sinfo->assoc_req_ies))
3841 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003842
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003843 return genlmsg_end(msg, hdr);
3844
3845 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003846 genlmsg_cancel(msg, hdr);
3847 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003848}
3849
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003850static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003851 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003852{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003853 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003854 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003855 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003856 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003857 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003858 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003859
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003860 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003861 if (err)
3862 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003863
Johannes Berg97990a02013-04-19 01:02:55 +02003864 if (!wdev->netdev) {
3865 err = -EINVAL;
3866 goto out_err;
3867 }
3868
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003869 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003870 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003871 goto out_err;
3872 }
3873
Johannes Bergbba95fe2008-07-29 13:22:51 +02003874 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003875 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003876 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003877 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003878 if (err == -ENOENT)
3879 break;
3880 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003881 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003882
Johannes Bergcf5ead82014-11-14 17:14:00 +01003883 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003884 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003885 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003886 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003887 &sinfo) < 0)
3888 goto out;
3889
3890 sta_idx++;
3891 }
3892
3893
3894 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003895 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003896 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003897 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003898 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003899
3900 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003901}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003902
Johannes Berg5727ef12007-12-19 02:03:34 +01003903static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3904{
Johannes Berg4c476992010-10-04 21:36:35 +02003905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3906 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003907 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003908 struct sk_buff *msg;
3909 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003910 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003911
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003912 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003913
3914 if (!info->attrs[NL80211_ATTR_MAC])
3915 return -EINVAL;
3916
3917 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3918
Johannes Berg4c476992010-10-04 21:36:35 +02003919 if (!rdev->ops->get_station)
3920 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003921
Hila Gonene35e4d22012-06-27 17:19:42 +03003922 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003923 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003924 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003925
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003926 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003927 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003928 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003929
Johannes Bergcf5ead82014-11-14 17:14:00 +01003930 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3931 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003932 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003933 nlmsg_free(msg);
3934 return -ENOBUFS;
3935 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003936
Johannes Berg4c476992010-10-04 21:36:35 +02003937 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003938}
3939
Johannes Berg77ee7c82013-02-15 00:48:33 +01003940int cfg80211_check_station_change(struct wiphy *wiphy,
3941 struct station_parameters *params,
3942 enum cfg80211_station_type statype)
3943{
3944 if (params->listen_interval != -1)
3945 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003946 if (params->aid &&
3947 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003948 return -EINVAL;
3949
3950 /* When you run into this, adjust the code below for the new flag */
3951 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3952
3953 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003954 case CFG80211_STA_MESH_PEER_KERNEL:
3955 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003956 /*
3957 * No ignoring the TDLS flag here -- the userspace mesh
3958 * code doesn't have the bug of including TDLS in the
3959 * mask everywhere.
3960 */
3961 if (params->sta_flags_mask &
3962 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3963 BIT(NL80211_STA_FLAG_MFP) |
3964 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3965 return -EINVAL;
3966 break;
3967 case CFG80211_STA_TDLS_PEER_SETUP:
3968 case CFG80211_STA_TDLS_PEER_ACTIVE:
3969 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3970 return -EINVAL;
3971 /* ignore since it can't change */
3972 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3973 break;
3974 default:
3975 /* disallow mesh-specific things */
3976 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3977 return -EINVAL;
3978 if (params->local_pm)
3979 return -EINVAL;
3980 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3981 return -EINVAL;
3982 }
3983
3984 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3985 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3986 /* TDLS can't be set, ... */
3987 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3988 return -EINVAL;
3989 /*
3990 * ... but don't bother the driver with it. This works around
3991 * a hostapd/wpa_supplicant issue -- it always includes the
3992 * TLDS_PEER flag in the mask even for AP mode.
3993 */
3994 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3995 }
3996
3997 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3998 /* reject other things that can't change */
3999 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4000 return -EINVAL;
4001 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4002 return -EINVAL;
4003 if (params->supported_rates)
4004 return -EINVAL;
4005 if (params->ext_capab || params->ht_capa || params->vht_capa)
4006 return -EINVAL;
4007 }
4008
4009 if (statype != CFG80211_STA_AP_CLIENT) {
4010 if (params->vlan)
4011 return -EINVAL;
4012 }
4013
4014 switch (statype) {
4015 case CFG80211_STA_AP_MLME_CLIENT:
4016 /* Use this only for authorizing/unauthorizing a station */
4017 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4018 return -EOPNOTSUPP;
4019 break;
4020 case CFG80211_STA_AP_CLIENT:
4021 /* accept only the listed bits */
4022 if (params->sta_flags_mask &
4023 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4024 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4025 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4026 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4027 BIT(NL80211_STA_FLAG_WME) |
4028 BIT(NL80211_STA_FLAG_MFP)))
4029 return -EINVAL;
4030
4031 /* but authenticated/associated only if driver handles it */
4032 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4033 params->sta_flags_mask &
4034 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4035 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4036 return -EINVAL;
4037 break;
4038 case CFG80211_STA_IBSS:
4039 case CFG80211_STA_AP_STA:
4040 /* reject any changes other than AUTHORIZED */
4041 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4042 return -EINVAL;
4043 break;
4044 case CFG80211_STA_TDLS_PEER_SETUP:
4045 /* reject any changes other than AUTHORIZED or WME */
4046 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4047 BIT(NL80211_STA_FLAG_WME)))
4048 return -EINVAL;
4049 /* force (at least) rates when authorizing */
4050 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4051 !params->supported_rates)
4052 return -EINVAL;
4053 break;
4054 case CFG80211_STA_TDLS_PEER_ACTIVE:
4055 /* reject any changes */
4056 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004057 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004058 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4059 return -EINVAL;
4060 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004061 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004062 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4063 return -EINVAL;
4064 break;
4065 }
4066
4067 return 0;
4068}
4069EXPORT_SYMBOL(cfg80211_check_station_change);
4070
Johannes Berg5727ef12007-12-19 02:03:34 +01004071/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004072 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004073 */
Johannes Berg80b99892011-11-18 16:23:01 +01004074static struct net_device *get_vlan(struct genl_info *info,
4075 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004076{
Johannes Berg463d0182009-07-14 00:33:35 +02004077 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004078 struct net_device *v;
4079 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004080
Johannes Berg80b99892011-11-18 16:23:01 +01004081 if (!vlanattr)
4082 return NULL;
4083
4084 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4085 if (!v)
4086 return ERR_PTR(-ENODEV);
4087
4088 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4089 ret = -EINVAL;
4090 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004091 }
Johannes Berg80b99892011-11-18 16:23:01 +01004092
Johannes Berg77ee7c82013-02-15 00:48:33 +01004093 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4094 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4095 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4096 ret = -EINVAL;
4097 goto error;
4098 }
4099
Johannes Berg80b99892011-11-18 16:23:01 +01004100 if (!netif_running(v)) {
4101 ret = -ENETDOWN;
4102 goto error;
4103 }
4104
4105 return v;
4106 error:
4107 dev_put(v);
4108 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004109}
4110
Johannes Berg94e860f2014-01-20 23:58:15 +01004111static const struct nla_policy
4112nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004113 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4114 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4115};
4116
Johannes Bergff276692013-02-15 00:09:01 +01004117static int nl80211_parse_sta_wme(struct genl_info *info,
4118 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004119{
Jouni Malinendf881292013-02-14 21:10:54 +02004120 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4121 struct nlattr *nla;
4122 int err;
4123
Jouni Malinendf881292013-02-14 21:10:54 +02004124 /* parse WME attributes if present */
4125 if (!info->attrs[NL80211_ATTR_STA_WME])
4126 return 0;
4127
4128 nla = info->attrs[NL80211_ATTR_STA_WME];
4129 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4130 nl80211_sta_wme_policy);
4131 if (err)
4132 return err;
4133
4134 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4135 params->uapsd_queues = nla_get_u8(
4136 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4137 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4138 return -EINVAL;
4139
4140 if (tb[NL80211_STA_WME_MAX_SP])
4141 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4142
4143 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4144 return -EINVAL;
4145
4146 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4147
4148 return 0;
4149}
4150
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304151static int nl80211_parse_sta_channel_info(struct genl_info *info,
4152 struct station_parameters *params)
4153{
4154 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4155 params->supported_channels =
4156 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4157 params->supported_channels_len =
4158 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4159 /*
4160 * Need to include at least one (first channel, number of
4161 * channels) tuple for each subband, and must have proper
4162 * tuples for the rest of the data as well.
4163 */
4164 if (params->supported_channels_len < 2)
4165 return -EINVAL;
4166 if (params->supported_channels_len % 2)
4167 return -EINVAL;
4168 }
4169
4170 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4171 params->supported_oper_classes =
4172 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4173 params->supported_oper_classes_len =
4174 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4175 /*
4176 * The value of the Length field of the Supported Operating
4177 * Classes element is between 2 and 253.
4178 */
4179 if (params->supported_oper_classes_len < 2 ||
4180 params->supported_oper_classes_len > 253)
4181 return -EINVAL;
4182 }
4183 return 0;
4184}
4185
Johannes Bergff276692013-02-15 00:09:01 +01004186static int nl80211_set_station_tdls(struct genl_info *info,
4187 struct station_parameters *params)
4188{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304189 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004190 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004191 if (info->attrs[NL80211_ATTR_PEER_AID])
4192 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004193 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4194 params->ht_capa =
4195 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4196 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4197 params->vht_capa =
4198 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4199
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304200 err = nl80211_parse_sta_channel_info(info, params);
4201 if (err)
4202 return err;
4203
Johannes Bergff276692013-02-15 00:09:01 +01004204 return nl80211_parse_sta_wme(info, params);
4205}
4206
Johannes Berg5727ef12007-12-19 02:03:34 +01004207static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4208{
Johannes Berg4c476992010-10-04 21:36:35 +02004209 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004210 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004211 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004212 u8 *mac_addr;
4213 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004214
4215 memset(&params, 0, sizeof(params));
4216
4217 params.listen_interval = -1;
4218
Johannes Berg77ee7c82013-02-15 00:48:33 +01004219 if (!rdev->ops->change_station)
4220 return -EOPNOTSUPP;
4221
Johannes Berg5727ef12007-12-19 02:03:34 +01004222 if (info->attrs[NL80211_ATTR_STA_AID])
4223 return -EINVAL;
4224
4225 if (!info->attrs[NL80211_ATTR_MAC])
4226 return -EINVAL;
4227
4228 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4229
4230 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4231 params.supported_rates =
4232 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4233 params.supported_rates_len =
4234 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4235 }
4236
Jouni Malinen9d62a982013-02-14 21:10:13 +02004237 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4238 params.capability =
4239 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4240 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4241 }
4242
4243 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4244 params.ext_capab =
4245 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4246 params.ext_capab_len =
4247 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4248 }
4249
Jouni Malinendf881292013-02-14 21:10:54 +02004250 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004251 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004252
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004253 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004254 return -EINVAL;
4255
Johannes Bergf8bacc22013-02-14 23:27:01 +01004256 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004257 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004258 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4259 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4260 return -EINVAL;
4261 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004262
Johannes Bergf8bacc22013-02-14 23:27:01 +01004263 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004264 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004265 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4266 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4267 return -EINVAL;
4268 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4269 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004270
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004271 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4272 enum nl80211_mesh_power_mode pm = nla_get_u32(
4273 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4274
4275 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4276 pm > NL80211_MESH_POWER_MAX)
4277 return -EINVAL;
4278
4279 params.local_pm = pm;
4280 }
4281
Johannes Berg77ee7c82013-02-15 00:48:33 +01004282 /* Include parameters for TDLS peer (will check later) */
4283 err = nl80211_set_station_tdls(info, &params);
4284 if (err)
4285 return err;
4286
4287 params.vlan = get_vlan(info, rdev);
4288 if (IS_ERR(params.vlan))
4289 return PTR_ERR(params.vlan);
4290
Johannes Berga97f4422009-06-18 17:23:43 +02004291 switch (dev->ieee80211_ptr->iftype) {
4292 case NL80211_IFTYPE_AP:
4293 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004294 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004295 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004296 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004297 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004298 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004299 break;
4300 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004301 err = -EOPNOTSUPP;
4302 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004303 }
4304
Johannes Berg77ee7c82013-02-15 00:48:33 +01004305 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004306 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004307
Johannes Berg77ee7c82013-02-15 00:48:33 +01004308 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004309 if (params.vlan)
4310 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004311
Johannes Berg5727ef12007-12-19 02:03:34 +01004312 return err;
4313}
4314
4315static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4316{
Johannes Berg4c476992010-10-04 21:36:35 +02004317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004318 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004319 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004320 struct station_parameters params;
4321 u8 *mac_addr = NULL;
4322
4323 memset(&params, 0, sizeof(params));
4324
Johannes Berg984c3112013-02-14 23:43:25 +01004325 if (!rdev->ops->add_station)
4326 return -EOPNOTSUPP;
4327
Johannes Berg5727ef12007-12-19 02:03:34 +01004328 if (!info->attrs[NL80211_ATTR_MAC])
4329 return -EINVAL;
4330
Johannes Berg5727ef12007-12-19 02:03:34 +01004331 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4332 return -EINVAL;
4333
4334 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4335 return -EINVAL;
4336
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004337 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4338 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004339 return -EINVAL;
4340
Johannes Berg5727ef12007-12-19 02:03:34 +01004341 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4342 params.supported_rates =
4343 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4344 params.supported_rates_len =
4345 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4346 params.listen_interval =
4347 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004348
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004349 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004350 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004351 else
4352 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004353 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4354 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004355
Jouni Malinen9d62a982013-02-14 21:10:13 +02004356 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4357 params.capability =
4358 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4359 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4360 }
4361
4362 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4363 params.ext_capab =
4364 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4365 params.ext_capab_len =
4366 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4367 }
4368
Jouni Malinen36aedc92008-08-25 11:58:58 +03004369 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4370 params.ht_capa =
4371 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004372
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004373 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4374 params.vht_capa =
4375 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4376
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004377 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4378 params.opmode_notif_used = true;
4379 params.opmode_notif =
4380 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4381 }
4382
Johannes Bergf8bacc22013-02-14 23:27:01 +01004383 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004384 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004385 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4386 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4387 return -EINVAL;
4388 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004389
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304390 err = nl80211_parse_sta_channel_info(info, &params);
4391 if (err)
4392 return err;
4393
Johannes Bergff276692013-02-15 00:09:01 +01004394 err = nl80211_parse_sta_wme(info, &params);
4395 if (err)
4396 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004397
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004398 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004399 return -EINVAL;
4400
Johannes Berg77ee7c82013-02-15 00:48:33 +01004401 /* When you run into this, adjust the code below for the new flag */
4402 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4403
Johannes Bergbdd90d52011-12-14 12:20:27 +01004404 switch (dev->ieee80211_ptr->iftype) {
4405 case NL80211_IFTYPE_AP:
4406 case NL80211_IFTYPE_AP_VLAN:
4407 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004408 /* ignore WME attributes if iface/sta is not capable */
4409 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4410 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4411 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004412
Johannes Bergbdd90d52011-12-14 12:20:27 +01004413 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004414 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4415 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004416 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004417 /* but don't bother the driver with it */
4418 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004419
Johannes Bergd582cff2012-10-26 17:53:44 +02004420 /* allow authenticated/associated only if driver handles it */
4421 if (!(rdev->wiphy.features &
4422 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4423 params.sta_flags_mask &
4424 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4425 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4426 return -EINVAL;
4427
Johannes Bergbdd90d52011-12-14 12:20:27 +01004428 /* must be last in here for error handling */
4429 params.vlan = get_vlan(info, rdev);
4430 if (IS_ERR(params.vlan))
4431 return PTR_ERR(params.vlan);
4432 break;
4433 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004434 /* ignore uAPSD data */
4435 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4436
Johannes Bergd582cff2012-10-26 17:53:44 +02004437 /* associated is disallowed */
4438 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4439 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004440 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004441 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4442 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004443 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004444 break;
4445 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004446 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004447 /* ignore uAPSD data */
4448 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4449
Johannes Berg77ee7c82013-02-15 00:48:33 +01004450 /* these are disallowed */
4451 if (params.sta_flags_mask &
4452 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4453 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004454 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004455 /* Only TDLS peers can be added */
4456 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4457 return -EINVAL;
4458 /* Can only add if TDLS ... */
4459 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4460 return -EOPNOTSUPP;
4461 /* ... with external setup is supported */
4462 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4463 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004464 /*
4465 * Older wpa_supplicant versions always mark the TDLS peer
4466 * as authorized, but it shouldn't yet be.
4467 */
4468 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004469 break;
4470 default:
4471 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004472 }
4473
Johannes Bergbdd90d52011-12-14 12:20:27 +01004474 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004475
Hila Gonene35e4d22012-06-27 17:19:42 +03004476 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004477
Johannes Berg5727ef12007-12-19 02:03:34 +01004478 if (params.vlan)
4479 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004480 return err;
4481}
4482
4483static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4484{
Johannes Berg4c476992010-10-04 21:36:35 +02004485 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4486 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004487 struct station_del_parameters params;
4488
4489 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004490
4491 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004492 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004493
Johannes Berge80cf852009-05-11 14:43:13 +02004494 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004495 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004496 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004497 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4498 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004499
Johannes Berg4c476992010-10-04 21:36:35 +02004500 if (!rdev->ops->del_station)
4501 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004502
Jouni Malinen98856862014-10-20 13:20:45 +03004503 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4504 params.subtype =
4505 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4506 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4507 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4508 return -EINVAL;
4509 } else {
4510 /* Default to Deauthentication frame */
4511 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4512 }
4513
4514 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4515 params.reason_code =
4516 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4517 if (params.reason_code == 0)
4518 return -EINVAL; /* 0 is reserved */
4519 } else {
4520 /* Default to reason code 2 */
4521 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4522 }
4523
Jouni Malinen89c771e2014-10-10 20:52:40 +03004524 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004525}
4526
Eric W. Biederman15e47302012-09-07 20:12:54 +00004527static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004528 int flags, struct net_device *dev,
4529 u8 *dst, u8 *next_hop,
4530 struct mpath_info *pinfo)
4531{
4532 void *hdr;
4533 struct nlattr *pinfoattr;
4534
Henning Rogge1ef4c852014-11-04 16:14:58 +01004535 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004536 if (!hdr)
4537 return -1;
4538
David S. Miller9360ffd2012-03-29 04:41:26 -04004539 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4540 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4541 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4542 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4543 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004544
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004545 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4546 if (!pinfoattr)
4547 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004548 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4549 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4550 pinfo->frame_qlen))
4551 goto nla_put_failure;
4552 if (((pinfo->filled & MPATH_INFO_SN) &&
4553 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4554 ((pinfo->filled & MPATH_INFO_METRIC) &&
4555 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4556 pinfo->metric)) ||
4557 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4558 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4559 pinfo->exptime)) ||
4560 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4561 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4562 pinfo->flags)) ||
4563 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4564 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4565 pinfo->discovery_timeout)) ||
4566 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4567 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4568 pinfo->discovery_retries)))
4569 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004570
4571 nla_nest_end(msg, pinfoattr);
4572
4573 return genlmsg_end(msg, hdr);
4574
4575 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004576 genlmsg_cancel(msg, hdr);
4577 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004578}
4579
4580static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004581 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004582{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004583 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004584 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004585 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004586 u8 dst[ETH_ALEN];
4587 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004588 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004589 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004590
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004591 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004592 if (err)
4593 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004594
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004595 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004596 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004597 goto out_err;
4598 }
4599
Johannes Berg97990a02013-04-19 01:02:55 +02004600 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004601 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004602 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004603 }
4604
Johannes Bergbba95fe2008-07-29 13:22:51 +02004605 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004606 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004607 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004608 if (err == -ENOENT)
4609 break;
4610 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004611 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004612
Eric W. Biederman15e47302012-09-07 20:12:54 +00004613 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004614 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004615 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004616 &pinfo) < 0)
4617 goto out;
4618
4619 path_idx++;
4620 }
4621
4622
4623 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004624 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004625 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004626 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004627 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004628 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004629}
4630
4631static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4632{
Johannes Berg4c476992010-10-04 21:36:35 +02004633 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004634 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004635 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004636 struct mpath_info pinfo;
4637 struct sk_buff *msg;
4638 u8 *dst = NULL;
4639 u8 next_hop[ETH_ALEN];
4640
4641 memset(&pinfo, 0, sizeof(pinfo));
4642
4643 if (!info->attrs[NL80211_ATTR_MAC])
4644 return -EINVAL;
4645
4646 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4647
Johannes Berg4c476992010-10-04 21:36:35 +02004648 if (!rdev->ops->get_mpath)
4649 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004650
Johannes Berg4c476992010-10-04 21:36:35 +02004651 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4652 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004653
Hila Gonene35e4d22012-06-27 17:19:42 +03004654 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004655 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004656 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004657
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004658 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004659 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004660 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004661
Eric W. Biederman15e47302012-09-07 20:12:54 +00004662 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004663 dev, dst, next_hop, &pinfo) < 0) {
4664 nlmsg_free(msg);
4665 return -ENOBUFS;
4666 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004667
Johannes Berg4c476992010-10-04 21:36:35 +02004668 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004669}
4670
4671static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4672{
Johannes Berg4c476992010-10-04 21:36:35 +02004673 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4674 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004675 u8 *dst = NULL;
4676 u8 *next_hop = NULL;
4677
4678 if (!info->attrs[NL80211_ATTR_MAC])
4679 return -EINVAL;
4680
4681 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4682 return -EINVAL;
4683
4684 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4685 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4686
Johannes Berg4c476992010-10-04 21:36:35 +02004687 if (!rdev->ops->change_mpath)
4688 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004689
Johannes Berg4c476992010-10-04 21:36:35 +02004690 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4691 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004692
Hila Gonene35e4d22012-06-27 17:19:42 +03004693 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004694}
Johannes Berg4c476992010-10-04 21:36:35 +02004695
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004696static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4697{
Johannes Berg4c476992010-10-04 21:36:35 +02004698 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4699 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004700 u8 *dst = NULL;
4701 u8 *next_hop = NULL;
4702
4703 if (!info->attrs[NL80211_ATTR_MAC])
4704 return -EINVAL;
4705
4706 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4707 return -EINVAL;
4708
4709 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4710 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4711
Johannes Berg4c476992010-10-04 21:36:35 +02004712 if (!rdev->ops->add_mpath)
4713 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004714
Johannes Berg4c476992010-10-04 21:36:35 +02004715 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4716 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004717
Hila Gonene35e4d22012-06-27 17:19:42 +03004718 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004719}
4720
4721static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4722{
Johannes Berg4c476992010-10-04 21:36:35 +02004723 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4724 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004725 u8 *dst = NULL;
4726
4727 if (info->attrs[NL80211_ATTR_MAC])
4728 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4729
Johannes Berg4c476992010-10-04 21:36:35 +02004730 if (!rdev->ops->del_mpath)
4731 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004732
Hila Gonene35e4d22012-06-27 17:19:42 +03004733 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004734}
4735
Henning Rogge66be7d22014-09-12 08:58:49 +02004736static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4737{
4738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4739 int err;
4740 struct net_device *dev = info->user_ptr[1];
4741 struct mpath_info pinfo;
4742 struct sk_buff *msg;
4743 u8 *dst = NULL;
4744 u8 mpp[ETH_ALEN];
4745
4746 memset(&pinfo, 0, sizeof(pinfo));
4747
4748 if (!info->attrs[NL80211_ATTR_MAC])
4749 return -EINVAL;
4750
4751 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4752
4753 if (!rdev->ops->get_mpp)
4754 return -EOPNOTSUPP;
4755
4756 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4757 return -EOPNOTSUPP;
4758
4759 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4760 if (err)
4761 return err;
4762
4763 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4764 if (!msg)
4765 return -ENOMEM;
4766
4767 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4768 dev, dst, mpp, &pinfo) < 0) {
4769 nlmsg_free(msg);
4770 return -ENOBUFS;
4771 }
4772
4773 return genlmsg_reply(msg, info);
4774}
4775
4776static int nl80211_dump_mpp(struct sk_buff *skb,
4777 struct netlink_callback *cb)
4778{
4779 struct mpath_info pinfo;
4780 struct cfg80211_registered_device *rdev;
4781 struct wireless_dev *wdev;
4782 u8 dst[ETH_ALEN];
4783 u8 mpp[ETH_ALEN];
4784 int path_idx = cb->args[2];
4785 int err;
4786
4787 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4788 if (err)
4789 return err;
4790
4791 if (!rdev->ops->dump_mpp) {
4792 err = -EOPNOTSUPP;
4793 goto out_err;
4794 }
4795
4796 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4797 err = -EOPNOTSUPP;
4798 goto out_err;
4799 }
4800
4801 while (1) {
4802 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4803 mpp, &pinfo);
4804 if (err == -ENOENT)
4805 break;
4806 if (err)
4807 goto out_err;
4808
4809 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4810 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4811 wdev->netdev, dst, mpp,
4812 &pinfo) < 0)
4813 goto out;
4814
4815 path_idx++;
4816 }
4817
4818 out:
4819 cb->args[2] = path_idx;
4820 err = skb->len;
4821 out_err:
4822 nl80211_finish_wdev_dump(rdev);
4823 return err;
4824}
4825
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004826static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4827{
Johannes Berg4c476992010-10-04 21:36:35 +02004828 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4829 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004830 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004831 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004832 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004833
4834 memset(&params, 0, sizeof(params));
4835 /* default to not changing parameters */
4836 params.use_cts_prot = -1;
4837 params.use_short_preamble = -1;
4838 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004839 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004840 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004841 params.p2p_ctwindow = -1;
4842 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004843
4844 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4845 params.use_cts_prot =
4846 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4847 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4848 params.use_short_preamble =
4849 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4850 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4851 params.use_short_slot_time =
4852 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004853 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4854 params.basic_rates =
4855 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4856 params.basic_rates_len =
4857 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4858 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004859 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4860 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004861 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4862 params.ht_opmode =
4863 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004864
Johannes Berg53cabad2012-11-14 15:17:28 +01004865 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4866 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4867 return -EINVAL;
4868 params.p2p_ctwindow =
4869 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4870 if (params.p2p_ctwindow < 0)
4871 return -EINVAL;
4872 if (params.p2p_ctwindow != 0 &&
4873 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4874 return -EINVAL;
4875 }
4876
4877 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4878 u8 tmp;
4879
4880 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4881 return -EINVAL;
4882 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4883 if (tmp > 1)
4884 return -EINVAL;
4885 params.p2p_opp_ps = tmp;
4886 if (params.p2p_opp_ps &&
4887 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4888 return -EINVAL;
4889 }
4890
Johannes Berg4c476992010-10-04 21:36:35 +02004891 if (!rdev->ops->change_bss)
4892 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004893
Johannes Berg074ac8d2010-09-16 14:58:22 +02004894 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004895 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4896 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004897
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004898 wdev_lock(wdev);
4899 err = rdev_change_bss(rdev, dev, &params);
4900 wdev_unlock(wdev);
4901
4902 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004903}
4904
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004905static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004906 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4907 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4908 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4909 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4910 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4911 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004912 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004913};
4914
4915static int parse_reg_rule(struct nlattr *tb[],
4916 struct ieee80211_reg_rule *reg_rule)
4917{
4918 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4919 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4920
4921 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4922 return -EINVAL;
4923 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4924 return -EINVAL;
4925 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4926 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004927 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4928 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004929 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4930 return -EINVAL;
4931
4932 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4933
4934 freq_range->start_freq_khz =
4935 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4936 freq_range->end_freq_khz =
4937 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004938 freq_range->max_bandwidth_khz =
4939 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004940
4941 power_rule->max_eirp =
4942 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4943
4944 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4945 power_rule->max_antenna_gain =
4946 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4947
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004948 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4949 reg_rule->dfs_cac_ms =
4950 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4951
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004952 return 0;
4953}
4954
4955static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4956{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004957 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004958 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004959
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004960 /*
4961 * You should only get this when cfg80211 hasn't yet initialized
4962 * completely when built-in to the kernel right between the time
4963 * window between nl80211_init() and regulatory_init(), if that is
4964 * even possible.
4965 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004966 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004967 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004968
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004969 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4970 user_reg_hint_type =
4971 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4972 else
4973 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4974
4975 switch (user_reg_hint_type) {
4976 case NL80211_USER_REG_HINT_USER:
4977 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004978 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4979 return -EINVAL;
4980
4981 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4982 return regulatory_hint_user(data, user_reg_hint_type);
4983 case NL80211_USER_REG_HINT_INDOOR:
4984 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004985 default:
4986 return -EINVAL;
4987 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004988}
4989
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004990static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004991 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004992{
Johannes Berg4c476992010-10-04 21:36:35 +02004993 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004994 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004995 struct wireless_dev *wdev = dev->ieee80211_ptr;
4996 struct mesh_config cur_params;
4997 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004998 void *hdr;
4999 struct nlattr *pinfoattr;
5000 struct sk_buff *msg;
5001
Johannes Berg29cbe682010-12-03 09:20:44 +01005002 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5003 return -EOPNOTSUPP;
5004
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005005 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005006 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005007
Johannes Berg29cbe682010-12-03 09:20:44 +01005008 wdev_lock(wdev);
5009 /* If not connected, get default parameters */
5010 if (!wdev->mesh_id_len)
5011 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5012 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005013 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005014 wdev_unlock(wdev);
5015
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005016 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005017 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005018
5019 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005020 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005021 if (!msg)
5022 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005023 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005024 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005025 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005026 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005027 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005028 if (!pinfoattr)
5029 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005030 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5031 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5032 cur_params.dot11MeshRetryTimeout) ||
5033 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5034 cur_params.dot11MeshConfirmTimeout) ||
5035 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5036 cur_params.dot11MeshHoldingTimeout) ||
5037 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5038 cur_params.dot11MeshMaxPeerLinks) ||
5039 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5040 cur_params.dot11MeshMaxRetries) ||
5041 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5042 cur_params.dot11MeshTTL) ||
5043 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5044 cur_params.element_ttl) ||
5045 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5046 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005047 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5048 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005049 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5050 cur_params.dot11MeshHWMPmaxPREQretries) ||
5051 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5052 cur_params.path_refresh_time) ||
5053 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5054 cur_params.min_discovery_timeout) ||
5055 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5056 cur_params.dot11MeshHWMPactivePathTimeout) ||
5057 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5058 cur_params.dot11MeshHWMPpreqMinInterval) ||
5059 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5060 cur_params.dot11MeshHWMPperrMinInterval) ||
5061 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5062 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5063 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5064 cur_params.dot11MeshHWMPRootMode) ||
5065 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5066 cur_params.dot11MeshHWMPRannInterval) ||
5067 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5068 cur_params.dot11MeshGateAnnouncementProtocol) ||
5069 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5070 cur_params.dot11MeshForwarding) ||
5071 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005072 cur_params.rssi_threshold) ||
5073 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005074 cur_params.ht_opmode) ||
5075 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5076 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5077 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005078 cur_params.dot11MeshHWMProotInterval) ||
5079 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005080 cur_params.dot11MeshHWMPconfirmationInterval) ||
5081 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5082 cur_params.power_mode) ||
5083 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005084 cur_params.dot11MeshAwakeWindowDuration) ||
5085 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5086 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005087 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005088 nla_nest_end(msg, pinfoattr);
5089 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005090 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005091
Johannes Berg3b858752009-03-12 09:55:09 +01005092 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005093 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005094 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005095 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005096 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005097}
5098
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005099static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005100 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5101 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5102 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5103 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5104 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5105 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005106 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005107 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005108 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005109 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5110 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5111 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5112 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5113 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005114 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005115 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005116 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005117 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005118 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005119 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005120 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5121 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005122 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5123 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005124 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005125 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5126 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005127 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005128};
5129
Javier Cardonac80d5452010-12-16 17:37:49 -08005130static const struct nla_policy
5131 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005132 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005133 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5134 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005135 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005136 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005137 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005138 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005139 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005140 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005141};
5142
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005143static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005144 struct mesh_config *cfg,
5145 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005146{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005147 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005148 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005149
Marco Porschea54fba2013-01-07 16:04:48 +01005150#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5151do { \
5152 if (tb[attr]) { \
5153 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5154 return -EINVAL; \
5155 cfg->param = fn(tb[attr]); \
5156 mask |= (1 << (attr - 1)); \
5157 } \
5158} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005159
5160
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005161 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005162 return -EINVAL;
5163 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005164 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005165 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005166 return -EINVAL;
5167
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005168 /* This makes sure that there aren't more than 32 mesh config
5169 * parameters (otherwise our bitfield scheme would not work.) */
5170 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5171
5172 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005173 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005174 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5175 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005176 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005177 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5178 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005179 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005180 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5181 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005182 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005183 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5184 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005185 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005186 mask, NL80211_MESHCONF_MAX_RETRIES,
5187 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005188 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005189 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005190 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005191 mask, NL80211_MESHCONF_ELEMENT_TTL,
5192 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005193 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005194 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5195 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005196 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5197 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005198 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5199 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005200 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005201 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5202 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005203 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005204 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5205 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005206 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005207 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5208 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005209 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5210 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005211 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5212 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005213 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005214 1, 65535, mask,
5215 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005216 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005217 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005218 1, 65535, mask,
5219 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005220 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005221 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005222 dot11MeshHWMPnetDiameterTraversalTime,
5223 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005224 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5225 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5227 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5228 nla_get_u8);
5229 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5230 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005231 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005233 dot11MeshGateAnnouncementProtocol, 0, 1,
5234 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005235 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005236 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005237 mask, NL80211_MESHCONF_FORWARDING,
5238 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005239 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005240 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005241 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005242 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005243 mask, NL80211_MESHCONF_HT_OPMODE,
5244 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005245 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005246 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005247 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5248 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005249 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005250 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5251 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005252 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005253 dot11MeshHWMPconfirmationInterval,
5254 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005255 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5256 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005257 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5258 NL80211_MESH_POWER_ACTIVE,
5259 NL80211_MESH_POWER_MAX,
5260 mask, NL80211_MESHCONF_POWER_MODE,
5261 nla_get_u32);
5262 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5263 0, 65535, mask,
5264 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005265 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5266 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5267 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005268 if (mask_out)
5269 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005270
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005271 return 0;
5272
5273#undef FILL_IN_MESH_PARAM_IF_SET
5274}
5275
Javier Cardonac80d5452010-12-16 17:37:49 -08005276static int nl80211_parse_mesh_setup(struct genl_info *info,
5277 struct mesh_setup *setup)
5278{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005280 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5281
5282 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5283 return -EINVAL;
5284 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5285 info->attrs[NL80211_ATTR_MESH_SETUP],
5286 nl80211_mesh_setup_params_policy))
5287 return -EINVAL;
5288
Javier Cardonad299a1f2012-03-31 11:31:33 -07005289 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5290 setup->sync_method =
5291 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5292 IEEE80211_SYNC_METHOD_VENDOR :
5293 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5294
Javier Cardonac80d5452010-12-16 17:37:49 -08005295 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5296 setup->path_sel_proto =
5297 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5298 IEEE80211_PATH_PROTOCOL_VENDOR :
5299 IEEE80211_PATH_PROTOCOL_HWMP;
5300
5301 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5302 setup->path_metric =
5303 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5304 IEEE80211_PATH_METRIC_VENDOR :
5305 IEEE80211_PATH_METRIC_AIRTIME;
5306
Javier Cardona581a8b02011-04-07 15:08:27 -07005307
5308 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005309 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005310 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005311 if (!is_valid_ie_attr(ieattr))
5312 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005313 setup->ie = nla_data(ieattr);
5314 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005315 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005316 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5317 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5318 return -EINVAL;
5319 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005320 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5321 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005322 if (setup->is_secure)
5323 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005324
Colleen Twitty6e16d902013-05-08 11:45:59 -07005325 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5326 if (!setup->user_mpm)
5327 return -EINVAL;
5328 setup->auth_id =
5329 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5330 }
5331
Javier Cardonac80d5452010-12-16 17:37:49 -08005332 return 0;
5333}
5334
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005335static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005336 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005337{
5338 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5339 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005340 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005341 struct mesh_config cfg;
5342 u32 mask;
5343 int err;
5344
Johannes Berg29cbe682010-12-03 09:20:44 +01005345 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5346 return -EOPNOTSUPP;
5347
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005348 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005349 return -EOPNOTSUPP;
5350
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005351 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005352 if (err)
5353 return err;
5354
Johannes Berg29cbe682010-12-03 09:20:44 +01005355 wdev_lock(wdev);
5356 if (!wdev->mesh_id_len)
5357 err = -ENOLINK;
5358
5359 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005360 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005361
5362 wdev_unlock(wdev);
5363
5364 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005365}
5366
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005367static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5368 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005369{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005370 struct nlattr *nl_reg_rules;
5371 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005372
Johannes Berg458f4f92012-12-06 15:47:38 +01005373 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5374 (regdom->dfs_region &&
5375 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005376 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005377
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005378 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5379 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005380 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005381
Johannes Berg458f4f92012-12-06 15:47:38 +01005382 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005383 struct nlattr *nl_reg_rule;
5384 const struct ieee80211_reg_rule *reg_rule;
5385 const struct ieee80211_freq_range *freq_range;
5386 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005387 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005388
Johannes Berg458f4f92012-12-06 15:47:38 +01005389 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005390 freq_range = &reg_rule->freq_range;
5391 power_rule = &reg_rule->power_rule;
5392
5393 nl_reg_rule = nla_nest_start(msg, i);
5394 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005395 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005396
Janusz Dziedzic97524822014-01-30 09:52:20 +01005397 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5398 if (!max_bandwidth_khz)
5399 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5400 reg_rule);
5401
David S. Miller9360ffd2012-03-29 04:41:26 -04005402 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5403 reg_rule->flags) ||
5404 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5405 freq_range->start_freq_khz) ||
5406 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5407 freq_range->end_freq_khz) ||
5408 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005409 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005410 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5411 power_rule->max_antenna_gain) ||
5412 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005413 power_rule->max_eirp) ||
5414 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5415 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005416 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005417
5418 nla_nest_end(msg, nl_reg_rule);
5419 }
5420
5421 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005422 return 0;
5423
5424nla_put_failure:
5425 return -EMSGSIZE;
5426}
5427
5428static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5429{
5430 const struct ieee80211_regdomain *regdom = NULL;
5431 struct cfg80211_registered_device *rdev;
5432 struct wiphy *wiphy = NULL;
5433 struct sk_buff *msg;
5434 void *hdr;
5435
5436 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5437 if (!msg)
5438 return -ENOBUFS;
5439
5440 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5441 NL80211_CMD_GET_REG);
5442 if (!hdr)
5443 goto put_failure;
5444
5445 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005446 bool self_managed;
5447
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005448 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5449 if (IS_ERR(rdev)) {
5450 nlmsg_free(msg);
5451 return PTR_ERR(rdev);
5452 }
5453
5454 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005455 self_managed = wiphy->regulatory_flags &
5456 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005457 regdom = get_wiphy_regdom(wiphy);
5458
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005459 /* a self-managed-reg device must have a private regdom */
5460 if (WARN_ON(!regdom && self_managed)) {
5461 nlmsg_free(msg);
5462 return -EINVAL;
5463 }
5464
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005465 if (regdom &&
5466 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5467 goto nla_put_failure;
5468 }
5469
5470 if (!wiphy && reg_last_request_cell_base() &&
5471 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5472 NL80211_USER_REG_HINT_CELL_BASE))
5473 goto nla_put_failure;
5474
5475 rcu_read_lock();
5476
5477 if (!regdom)
5478 regdom = rcu_dereference(cfg80211_regdomain);
5479
5480 if (nl80211_put_regdom(regdom, msg))
5481 goto nla_put_failure_rcu;
5482
5483 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005484
5485 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005486 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005487
Johannes Berg458f4f92012-12-06 15:47:38 +01005488nla_put_failure_rcu:
5489 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005490nla_put_failure:
5491 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005492put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005493 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005494 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005495}
5496
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005497static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5498 u32 seq, int flags, struct wiphy *wiphy,
5499 const struct ieee80211_regdomain *regdom)
5500{
5501 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5502 NL80211_CMD_GET_REG);
5503
5504 if (!hdr)
5505 return -1;
5506
5507 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5508
5509 if (nl80211_put_regdom(regdom, msg))
5510 goto nla_put_failure;
5511
5512 if (!wiphy && reg_last_request_cell_base() &&
5513 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5514 NL80211_USER_REG_HINT_CELL_BASE))
5515 goto nla_put_failure;
5516
5517 if (wiphy &&
5518 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5519 goto nla_put_failure;
5520
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005521 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5522 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5523 goto nla_put_failure;
5524
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005525 return genlmsg_end(msg, hdr);
5526
5527nla_put_failure:
5528 genlmsg_cancel(msg, hdr);
5529 return -EMSGSIZE;
5530}
5531
5532static int nl80211_get_reg_dump(struct sk_buff *skb,
5533 struct netlink_callback *cb)
5534{
5535 const struct ieee80211_regdomain *regdom = NULL;
5536 struct cfg80211_registered_device *rdev;
5537 int err, reg_idx, start = cb->args[2];
5538
5539 rtnl_lock();
5540
5541 if (cfg80211_regdomain && start == 0) {
5542 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5543 NLM_F_MULTI, NULL,
5544 rtnl_dereference(cfg80211_regdomain));
5545 if (err < 0)
5546 goto out_err;
5547 }
5548
5549 /* the global regdom is idx 0 */
5550 reg_idx = 1;
5551 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5552 regdom = get_wiphy_regdom(&rdev->wiphy);
5553 if (!regdom)
5554 continue;
5555
5556 if (++reg_idx <= start)
5557 continue;
5558
5559 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5560 NLM_F_MULTI, &rdev->wiphy, regdom);
5561 if (err < 0) {
5562 reg_idx--;
5563 break;
5564 }
5565 }
5566
5567 cb->args[2] = reg_idx;
5568 err = skb->len;
5569out_err:
5570 rtnl_unlock();
5571 return err;
5572}
5573
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005574static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5575{
5576 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5577 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005578 char *alpha2;
5579 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005580 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005581 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005582 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005583
5584 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5585 return -EINVAL;
5586
5587 if (!info->attrs[NL80211_ATTR_REG_RULES])
5588 return -EINVAL;
5589
5590 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5591
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005592 if (info->attrs[NL80211_ATTR_DFS_REGION])
5593 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5594
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005595 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005596 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005597 num_rules++;
5598 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005599 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005600 }
5601
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005602 if (!reg_is_valid_request(alpha2))
5603 return -EINVAL;
5604
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005605 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005606 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005607
5608 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005609 if (!rd)
5610 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005611
5612 rd->n_reg_rules = num_rules;
5613 rd->alpha2[0] = alpha2[0];
5614 rd->alpha2[1] = alpha2[1];
5615
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005616 /*
5617 * Disable DFS master mode if the DFS region was
5618 * not supported or known on this kernel.
5619 */
5620 if (reg_supported_dfs_region(dfs_region))
5621 rd->dfs_region = dfs_region;
5622
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005623 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005624 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005625 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5626 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5627 reg_rule_policy);
5628 if (r)
5629 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005630 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5631 if (r)
5632 goto bad_reg;
5633
5634 rule_idx++;
5635
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005636 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5637 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005638 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005639 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005640 }
5641
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005642 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005643 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005644 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005645
Johannes Bergd2372b32008-10-24 20:32:20 +02005646 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005647 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005648 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005649}
5650
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005651static int validate_scan_freqs(struct nlattr *freqs)
5652{
5653 struct nlattr *attr1, *attr2;
5654 int n_channels = 0, tmp1, tmp2;
5655
5656 nla_for_each_nested(attr1, freqs, tmp1) {
5657 n_channels++;
5658 /*
5659 * Some hardware has a limited channel list for
5660 * scanning, and it is pretty much nonsensical
5661 * to scan for a channel twice, so disallow that
5662 * and don't require drivers to check that the
5663 * channel list they get isn't longer than what
5664 * they can scan, as long as they can scan all
5665 * the channels they registered at once.
5666 */
5667 nla_for_each_nested(attr2, freqs, tmp2)
5668 if (attr1 != attr2 &&
5669 nla_get_u32(attr1) == nla_get_u32(attr2))
5670 return 0;
5671 }
5672
5673 return n_channels;
5674}
5675
Johannes Bergad2b26a2014-06-12 21:39:05 +02005676static int nl80211_parse_random_mac(struct nlattr **attrs,
5677 u8 *mac_addr, u8 *mac_addr_mask)
5678{
5679 int i;
5680
5681 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
5682 memset(mac_addr, 0, ETH_ALEN);
5683 memset(mac_addr_mask, 0, ETH_ALEN);
5684 mac_addr[0] = 0x2;
5685 mac_addr_mask[0] = 0x3;
5686
5687 return 0;
5688 }
5689
5690 /* need both or none */
5691 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5692 return -EINVAL;
5693
5694 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5695 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5696
5697 /* don't allow or configure an mcast address */
5698 if (!is_multicast_ether_addr(mac_addr_mask) ||
5699 is_multicast_ether_addr(mac_addr))
5700 return -EINVAL;
5701
5702 /*
5703 * allow users to pass a MAC address that has bits set outside
5704 * of the mask, but don't bother drivers with having to deal
5705 * with such bits
5706 */
5707 for (i = 0; i < ETH_ALEN; i++)
5708 mac_addr[i] &= mac_addr_mask[i];
5709
5710 return 0;
5711}
5712
Johannes Berg2a519312009-02-10 21:25:55 +01005713static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5714{
Johannes Berg4c476992010-10-04 21:36:35 +02005715 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005716 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005717 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005718 struct nlattr *attr;
5719 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005720 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005721 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005722
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005723 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5724 return -EINVAL;
5725
Johannes Berg79c97e92009-07-07 03:56:12 +02005726 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005727
Johannes Berg4c476992010-10-04 21:36:35 +02005728 if (!rdev->ops->scan)
5729 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005730
Johannes Bergf9d15d12014-01-22 11:14:19 +02005731 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005732 err = -EBUSY;
5733 goto unlock;
5734 }
Johannes Berg2a519312009-02-10 21:25:55 +01005735
5736 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005737 n_channels = validate_scan_freqs(
5738 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005739 if (!n_channels) {
5740 err = -EINVAL;
5741 goto unlock;
5742 }
Johannes Berg2a519312009-02-10 21:25:55 +01005743 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005744 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005745 }
5746
5747 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5748 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5749 n_ssids++;
5750
Johannes Bergf9f47522013-03-19 15:04:07 +01005751 if (n_ssids > wiphy->max_scan_ssids) {
5752 err = -EINVAL;
5753 goto unlock;
5754 }
Johannes Berg2a519312009-02-10 21:25:55 +01005755
Jouni Malinen70692ad2009-02-16 19:39:13 +02005756 if (info->attrs[NL80211_ATTR_IE])
5757 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5758 else
5759 ie_len = 0;
5760
Johannes Bergf9f47522013-03-19 15:04:07 +01005761 if (ie_len > wiphy->max_scan_ie_len) {
5762 err = -EINVAL;
5763 goto unlock;
5764 }
Johannes Berg18a83652009-03-31 12:12:05 +02005765
Johannes Berg2a519312009-02-10 21:25:55 +01005766 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005767 + sizeof(*request->ssids) * n_ssids
5768 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005769 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005770 if (!request) {
5771 err = -ENOMEM;
5772 goto unlock;
5773 }
Johannes Berg2a519312009-02-10 21:25:55 +01005774
Johannes Berg2a519312009-02-10 21:25:55 +01005775 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005776 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005777 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005778 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005779 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005780 request->ie = (void *)(request->ssids + n_ssids);
5781 else
5782 request->ie = (void *)(request->channels + n_channels);
5783 }
Johannes Berg2a519312009-02-10 21:25:55 +01005784
Johannes Berg584991d2009-11-02 13:32:03 +01005785 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005786 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5787 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005788 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005789 struct ieee80211_channel *chan;
5790
5791 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5792
5793 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005794 err = -EINVAL;
5795 goto out_free;
5796 }
Johannes Berg584991d2009-11-02 13:32:03 +01005797
5798 /* ignore disabled channels */
5799 if (chan->flags & IEEE80211_CHAN_DISABLED)
5800 continue;
5801
5802 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005803 i++;
5804 }
5805 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005806 enum ieee80211_band band;
5807
Johannes Berg2a519312009-02-10 21:25:55 +01005808 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005809 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5810 int j;
5811 if (!wiphy->bands[band])
5812 continue;
5813 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005814 struct ieee80211_channel *chan;
5815
5816 chan = &wiphy->bands[band]->channels[j];
5817
5818 if (chan->flags & IEEE80211_CHAN_DISABLED)
5819 continue;
5820
5821 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005822 i++;
5823 }
5824 }
5825 }
5826
Johannes Berg584991d2009-11-02 13:32:03 +01005827 if (!i) {
5828 err = -EINVAL;
5829 goto out_free;
5830 }
5831
5832 request->n_channels = i;
5833
Johannes Berg2a519312009-02-10 21:25:55 +01005834 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005835 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005836 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005837 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005838 err = -EINVAL;
5839 goto out_free;
5840 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005841 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005842 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005843 i++;
5844 }
5845 }
5846
Jouni Malinen70692ad2009-02-16 19:39:13 +02005847 if (info->attrs[NL80211_ATTR_IE]) {
5848 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a54b2009-04-01 11:58:36 +02005849 memcpy((void *)request->ie,
5850 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005851 request->ie_len);
5852 }
5853
Johannes Berg34850ab2011-07-18 18:08:35 +02005854 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005855 if (wiphy->bands[i])
5856 request->rates[i] =
5857 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005858
5859 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5860 nla_for_each_nested(attr,
5861 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5862 tmp) {
5863 enum ieee80211_band band = nla_type(attr);
5864
Dan Carpenter84404622011-07-29 11:52:18 +03005865 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005866 err = -EINVAL;
5867 goto out_free;
5868 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005869
5870 if (!wiphy->bands[band])
5871 continue;
5872
Johannes Berg34850ab2011-07-18 18:08:35 +02005873 err = ieee80211_get_ratemask(wiphy->bands[band],
5874 nla_data(attr),
5875 nla_len(attr),
5876 &request->rates[band]);
5877 if (err)
5878 goto out_free;
5879 }
5880 }
5881
Sam Leffler46856bb2012-10-11 21:03:32 -07005882 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005883 request->flags = nla_get_u32(
5884 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005885 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5886 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005887 err = -EOPNOTSUPP;
5888 goto out_free;
5889 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005890
5891 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5892 if (!(wiphy->features &
5893 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5894 err = -EOPNOTSUPP;
5895 goto out_free;
5896 }
5897
5898 if (wdev->current_bss) {
5899 err = -EOPNOTSUPP;
5900 goto out_free;
5901 }
5902
5903 err = nl80211_parse_random_mac(info->attrs,
5904 request->mac_addr,
5905 request->mac_addr_mask);
5906 if (err)
5907 goto out_free;
5908 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005909 }
Sam Lefflered4737712012-10-11 21:03:31 -07005910
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305911 request->no_cck =
5912 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5913
Johannes Bergfd014282012-06-18 19:17:03 +02005914 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005915 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005916 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005917
Johannes Berg79c97e92009-07-07 03:56:12 +02005918 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005919 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005920
Johannes Berg463d0182009-07-14 00:33:35 +02005921 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005922 nl80211_send_scan_start(rdev, wdev);
5923 if (wdev->netdev)
5924 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005925 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005926 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005927 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005928 kfree(request);
5929 }
Johannes Berg3b858752009-03-12 09:55:09 +01005930
Johannes Bergf9f47522013-03-19 15:04:07 +01005931 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005932 return err;
5933}
5934
Luciano Coelho256da022014-11-10 16:13:46 +02005935static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005936nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005937 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005938{
5939 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005940 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005941 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005942 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005943 enum ieee80211_band band;
5944 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005945 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005946 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005947
Luciano Coelho256da022014-11-10 16:13:46 +02005948 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5949 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005950
Luciano Coelho256da022014-11-10 16:13:46 +02005951 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5952 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005953
Luciano Coelho256da022014-11-10 16:13:46 +02005954 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005955 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005956 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005957
Luciano Coelho256da022014-11-10 16:13:46 +02005958 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005959 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005960 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005961 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005962 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005963 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005964 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005965 }
5966
Luciano Coelho256da022014-11-10 16:13:46 +02005967 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5968 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005969 tmp)
5970 n_ssids++;
5971
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005972 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005973 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005974
Johannes Bergea73cbc2014-01-24 10:53:53 +01005975 /*
5976 * First, count the number of 'real' matchsets. Due to an issue with
5977 * the old implementation, matchsets containing only the RSSI attribute
5978 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5979 * RSSI for all matchsets, rather than their own matchset for reporting
5980 * all APs with a strong RSSI. This is needed to be compatible with
5981 * older userspace that treated a matchset with only the RSSI as the
5982 * global RSSI for all other matchsets - if there are other matchsets.
5983 */
Luciano Coelho256da022014-11-10 16:13:46 +02005984 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005985 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005986 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005987 tmp) {
5988 struct nlattr *rssi;
5989
5990 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5991 nla_data(attr), nla_len(attr),
5992 nl80211_match_policy);
5993 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02005994 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005995 /* add other standalone attributes here */
5996 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5997 n_match_sets++;
5998 continue;
5999 }
6000 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6001 if (rssi)
6002 default_match_rssi = nla_get_s32(rssi);
6003 }
6004 }
6005
6006 /* However, if there's no other matchset, add the RSSI one */
6007 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6008 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006009
6010 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006011 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006012
Luciano Coelho256da022014-11-10 16:13:46 +02006013 if (attrs[NL80211_ATTR_IE])
6014 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006015 else
6016 ie_len = 0;
6017
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006018 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006019 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006020
Luciano Coelho807f8a82011-05-11 17:09:35 +03006021 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006022 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006023 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006024 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006025 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006026 if (!request)
6027 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006028
6029 if (n_ssids)
6030 request->ssids = (void *)&request->channels[n_channels];
6031 request->n_ssids = n_ssids;
6032 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006033 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006034 request->ie = (void *)(request->ssids + n_ssids);
6035 else
6036 request->ie = (void *)(request->channels + n_channels);
6037 }
6038
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006039 if (n_match_sets) {
6040 if (request->ie)
6041 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006042 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006043 request->match_sets =
6044 (void *)(request->ssids + n_ssids);
6045 else
6046 request->match_sets =
6047 (void *)(request->channels + n_channels);
6048 }
6049 request->n_match_sets = n_match_sets;
6050
Luciano Coelho807f8a82011-05-11 17:09:35 +03006051 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006052 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006053 /* user specified, bail out if channel not found */
6054 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006055 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006056 tmp) {
6057 struct ieee80211_channel *chan;
6058
6059 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6060
6061 if (!chan) {
6062 err = -EINVAL;
6063 goto out_free;
6064 }
6065
6066 /* ignore disabled channels */
6067 if (chan->flags & IEEE80211_CHAN_DISABLED)
6068 continue;
6069
6070 request->channels[i] = chan;
6071 i++;
6072 }
6073 } else {
6074 /* all channels */
6075 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6076 int j;
6077 if (!wiphy->bands[band])
6078 continue;
6079 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6080 struct ieee80211_channel *chan;
6081
6082 chan = &wiphy->bands[band]->channels[j];
6083
6084 if (chan->flags & IEEE80211_CHAN_DISABLED)
6085 continue;
6086
6087 request->channels[i] = chan;
6088 i++;
6089 }
6090 }
6091 }
6092
6093 if (!i) {
6094 err = -EINVAL;
6095 goto out_free;
6096 }
6097
6098 request->n_channels = i;
6099
6100 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006101 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006102 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006103 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006104 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006105 err = -EINVAL;
6106 goto out_free;
6107 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006108 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006109 memcpy(request->ssids[i].ssid, nla_data(attr),
6110 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006111 i++;
6112 }
6113 }
6114
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006115 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006116 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006117 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006118 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006119 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006120 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006121
Johannes Bergae811e22014-01-24 10:17:47 +01006122 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6123 nla_data(attr), nla_len(attr),
6124 nl80211_match_policy);
6125 if (err)
6126 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006127 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006128 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006129 if (WARN_ON(i >= n_match_sets)) {
6130 /* this indicates a programming error,
6131 * the loop above should have verified
6132 * things properly
6133 */
6134 err = -EINVAL;
6135 goto out_free;
6136 }
6137
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006138 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6139 err = -EINVAL;
6140 goto out_free;
6141 }
6142 memcpy(request->match_sets[i].ssid.ssid,
6143 nla_data(ssid), nla_len(ssid));
6144 request->match_sets[i].ssid.ssid_len =
6145 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006146 /* special attribute - old implemenation w/a */
6147 request->match_sets[i].rssi_thold =
6148 default_match_rssi;
6149 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6150 if (rssi)
6151 request->match_sets[i].rssi_thold =
6152 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006153 }
6154 i++;
6155 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006156
6157 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006158 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006159 request->match_sets[0].rssi_thold = default_match_rssi;
6160
6161 request->min_rssi_thold = INT_MAX;
6162 for (i = 0; i < n_match_sets; i++)
6163 request->min_rssi_thold =
6164 min(request->match_sets[i].rssi_thold,
6165 request->min_rssi_thold);
6166 } else {
6167 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006168 }
6169
Johannes Berg9900e482014-02-04 21:01:25 +01006170 if (ie_len) {
6171 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006172 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006173 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006174 request->ie_len);
6175 }
6176
Luciano Coelho256da022014-11-10 16:13:46 +02006177 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006178 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006179 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006180 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6181 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006182 err = -EOPNOTSUPP;
6183 goto out_free;
6184 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006185
6186 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6187 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6188
6189 if (!wdev) /* must be net-detect */
6190 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6191
6192 if (!(wiphy->features & flg)) {
6193 err = -EOPNOTSUPP;
6194 goto out_free;
6195 }
6196
6197 if (wdev && wdev->current_bss) {
6198 err = -EOPNOTSUPP;
6199 goto out_free;
6200 }
6201
6202 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6203 request->mac_addr_mask);
6204 if (err)
6205 goto out_free;
6206 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006207 }
Sam Lefflered4737712012-10-11 21:03:31 -07006208
Luciano Coelho9c748932015-01-16 16:04:09 +02006209 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6210 request->delay =
6211 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6212
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006213 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006214 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006215
Luciano Coelho256da022014-11-10 16:13:46 +02006216 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006217
6218out_free:
6219 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006220 return ERR_PTR(err);
6221}
6222
6223static int nl80211_start_sched_scan(struct sk_buff *skb,
6224 struct genl_info *info)
6225{
6226 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6227 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006228 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006229 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006230 int err;
6231
6232 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6233 !rdev->ops->sched_scan_start)
6234 return -EOPNOTSUPP;
6235
6236 if (rdev->sched_scan_req)
6237 return -EINPROGRESS;
6238
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006239 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6240 info->attrs);
6241
6242 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006243 if (err)
6244 goto out_err;
6245
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006246 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006247 if (err)
6248 goto out_free;
6249
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006250 sched_scan_req->dev = dev;
6251 sched_scan_req->wiphy = &rdev->wiphy;
6252
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006253 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6254 sched_scan_req->owner_nlportid = info->snd_portid;
6255
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006256 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006257
6258 nl80211_send_sched_scan(rdev, dev,
6259 NL80211_CMD_START_SCHED_SCAN);
6260 return 0;
6261
6262out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006263 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006264out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006265 return err;
6266}
6267
6268static int nl80211_stop_sched_scan(struct sk_buff *skb,
6269 struct genl_info *info)
6270{
6271 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6272
6273 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6274 !rdev->ops->sched_scan_stop)
6275 return -EOPNOTSUPP;
6276
Johannes Berg5fe231e2013-05-08 21:45:15 +02006277 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006278}
6279
Simon Wunderlich04f39042013-02-08 18:16:19 +01006280static int nl80211_start_radar_detection(struct sk_buff *skb,
6281 struct genl_info *info)
6282{
6283 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6284 struct net_device *dev = info->user_ptr[1];
6285 struct wireless_dev *wdev = dev->ieee80211_ptr;
6286 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006287 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006288 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006289 int err;
6290
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006291 dfs_region = reg_get_dfs_region(wdev->wiphy);
6292 if (dfs_region == NL80211_DFS_UNSET)
6293 return -EINVAL;
6294
Simon Wunderlich04f39042013-02-08 18:16:19 +01006295 err = nl80211_parse_chandef(rdev, info, &chandef);
6296 if (err)
6297 return err;
6298
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006299 if (netif_carrier_ok(dev))
6300 return -EBUSY;
6301
Simon Wunderlich04f39042013-02-08 18:16:19 +01006302 if (wdev->cac_started)
6303 return -EBUSY;
6304
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006305 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006306 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006307 if (err < 0)
6308 return err;
6309
6310 if (err == 0)
6311 return -EINVAL;
6312
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006313 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006314 return -EINVAL;
6315
6316 if (!rdev->ops->start_radar_detection)
6317 return -EOPNOTSUPP;
6318
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006319 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6320 if (WARN_ON(!cac_time_ms))
6321 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6322
6323 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6324 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006325 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006326 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006327 wdev->cac_started = true;
6328 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006329 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006330 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006331 return err;
6332}
6333
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006334static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6335{
6336 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6337 struct net_device *dev = info->user_ptr[1];
6338 struct wireless_dev *wdev = dev->ieee80211_ptr;
6339 struct cfg80211_csa_settings params;
6340 /* csa_attrs is defined static to avoid waste of stack size - this
6341 * function is called under RTNL lock, so this should not be a problem.
6342 */
6343 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006344 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006345 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006346 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006347 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006348
6349 if (!rdev->ops->channel_switch ||
6350 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6351 return -EOPNOTSUPP;
6352
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006353 switch (dev->ieee80211_ptr->iftype) {
6354 case NL80211_IFTYPE_AP:
6355 case NL80211_IFTYPE_P2P_GO:
6356 need_new_beacon = true;
6357
6358 /* useless if AP is not running */
6359 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006360 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006361 break;
6362 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006363 if (!wdev->ssid_len)
6364 return -ENOTCONN;
6365 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006366 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006367 if (!wdev->mesh_id_len)
6368 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006369 break;
6370 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006371 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006372 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006373
6374 memset(&params, 0, sizeof(params));
6375
6376 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6377 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6378 return -EINVAL;
6379
6380 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006381 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006382 return -EINVAL;
6383
Luciano Coelho252e07c2014-10-08 09:48:34 +03006384 /* Even though the attribute is u32, the specification says
6385 * u8, so let's make sure we don't overflow.
6386 */
6387 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6388 if (cs_count > 255)
6389 return -EINVAL;
6390
6391 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006392
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006393 if (!need_new_beacon)
6394 goto skip_beacons;
6395
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006396 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6397 if (err)
6398 return err;
6399
6400 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6401 info->attrs[NL80211_ATTR_CSA_IES],
6402 nl80211_policy);
6403 if (err)
6404 return err;
6405
6406 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6407 if (err)
6408 return err;
6409
6410 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6411 return -EINVAL;
6412
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006413 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6414 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006415 return -EINVAL;
6416
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006417 params.n_counter_offsets_beacon = len / sizeof(u16);
6418 if (rdev->wiphy.max_num_csa_counters &&
6419 (params.n_counter_offsets_beacon >
6420 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006421 return -EINVAL;
6422
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006423 params.counter_offsets_beacon =
6424 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6425
6426 /* sanity checks - counters should fit and be the same */
6427 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6428 u16 offset = params.counter_offsets_beacon[i];
6429
6430 if (offset >= params.beacon_csa.tail_len)
6431 return -EINVAL;
6432
6433 if (params.beacon_csa.tail[offset] != params.count)
6434 return -EINVAL;
6435 }
6436
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006437 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006438 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6439 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006440 return -EINVAL;
6441
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006442 params.n_counter_offsets_presp = len / sizeof(u16);
6443 if (rdev->wiphy.max_num_csa_counters &&
6444 (params.n_counter_offsets_beacon >
6445 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006446 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006447
6448 params.counter_offsets_presp =
6449 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6450
6451 /* sanity checks - counters should fit and be the same */
6452 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6453 u16 offset = params.counter_offsets_presp[i];
6454
6455 if (offset >= params.beacon_csa.probe_resp_len)
6456 return -EINVAL;
6457
6458 if (params.beacon_csa.probe_resp[offset] !=
6459 params.count)
6460 return -EINVAL;
6461 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006462 }
6463
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006464skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006465 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6466 if (err)
6467 return err;
6468
Ilan Peer174e0cd2014-02-23 09:13:01 +02006469 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6470 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006471 return -EINVAL;
6472
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006473 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6474 &params.chandef,
6475 wdev->iftype);
6476 if (err < 0)
6477 return err;
6478
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006479 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006480 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006481
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006482 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6483 params.block_tx = true;
6484
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006485 wdev_lock(wdev);
6486 err = rdev_channel_switch(rdev, dev, &params);
6487 wdev_unlock(wdev);
6488
6489 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006490}
6491
Johannes Berg9720bb32011-06-21 09:45:33 +02006492static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6493 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006494 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006495 struct wireless_dev *wdev,
6496 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006497{
Johannes Berg48ab9052009-07-10 18:42:31 +02006498 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006499 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006500 void *hdr;
6501 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006502
6503 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006504
Eric W. Biederman15e47302012-09-07 20:12:54 +00006505 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006506 NL80211_CMD_NEW_SCAN_RESULTS);
6507 if (!hdr)
6508 return -1;
6509
Johannes Berg9720bb32011-06-21 09:45:33 +02006510 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6511
Johannes Berg97990a02013-04-19 01:02:55 +02006512 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6513 goto nla_put_failure;
6514 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006515 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6516 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006517 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6518 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006519
6520 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6521 if (!bss)
6522 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006523 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006524 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006525 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006526
6527 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006528 /* indicate whether we have probe response data or not */
6529 if (rcu_access_pointer(res->proberesp_ies) &&
6530 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6531 goto fail_unlock_rcu;
6532
6533 /* this pointer prefers to be pointed to probe response data
6534 * but is always valid
6535 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006536 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006537 if (ies) {
6538 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6539 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006540 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6541 ies->len, ies->data))
6542 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006543 }
Johannes Berg0e227082014-08-12 20:34:30 +02006544
6545 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006546 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006547 if (ies && ies->from_beacon) {
6548 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006549 goto fail_unlock_rcu;
6550 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6551 ies->len, ies->data))
6552 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006553 }
6554 rcu_read_unlock();
6555
David S. Miller9360ffd2012-03-29 04:41:26 -04006556 if (res->beacon_interval &&
6557 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6558 goto nla_put_failure;
6559 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6560 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006561 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006562 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6563 jiffies_to_msecs(jiffies - intbss->ts)))
6564 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006565
Johannes Berg77965c972009-02-18 18:45:06 +01006566 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006567 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006568 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6569 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006570 break;
6571 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006572 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6573 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006574 break;
6575 default:
6576 break;
6577 }
6578
Johannes Berg48ab9052009-07-10 18:42:31 +02006579 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006580 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006581 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006582 if (intbss == wdev->current_bss &&
6583 nla_put_u32(msg, NL80211_BSS_STATUS,
6584 NL80211_BSS_STATUS_ASSOCIATED))
6585 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006586 break;
6587 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006588 if (intbss == wdev->current_bss &&
6589 nla_put_u32(msg, NL80211_BSS_STATUS,
6590 NL80211_BSS_STATUS_IBSS_JOINED))
6591 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006592 break;
6593 default:
6594 break;
6595 }
6596
Johannes Berg2a519312009-02-10 21:25:55 +01006597 nla_nest_end(msg, bss);
6598
6599 return genlmsg_end(msg, hdr);
6600
Johannes Berg8cef2c92013-02-05 16:54:31 +01006601 fail_unlock_rcu:
6602 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006603 nla_put_failure:
6604 genlmsg_cancel(msg, hdr);
6605 return -EMSGSIZE;
6606}
6607
Johannes Berg97990a02013-04-19 01:02:55 +02006608static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006609{
Johannes Berg48ab9052009-07-10 18:42:31 +02006610 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006611 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006612 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006613 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006614 int err;
6615
Johannes Berg97990a02013-04-19 01:02:55 +02006616 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006617 if (err)
6618 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006619
Johannes Berg48ab9052009-07-10 18:42:31 +02006620 wdev_lock(wdev);
6621 spin_lock_bh(&rdev->bss_lock);
6622 cfg80211_bss_expire(rdev);
6623
Johannes Berg9720bb32011-06-21 09:45:33 +02006624 cb->seq = rdev->bss_generation;
6625
Johannes Berg48ab9052009-07-10 18:42:31 +02006626 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006627 if (++idx <= start)
6628 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006629 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006630 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006631 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006632 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006633 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006634 }
6635 }
6636
Johannes Berg48ab9052009-07-10 18:42:31 +02006637 spin_unlock_bh(&rdev->bss_lock);
6638 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006639
Johannes Berg97990a02013-04-19 01:02:55 +02006640 cb->args[2] = idx;
6641 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006642
Johannes Berg67748892010-10-04 21:14:06 +02006643 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006644}
6645
Eric W. Biederman15e47302012-09-07 20:12:54 +00006646static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006647 int flags, struct net_device *dev,
6648 bool allow_radio_stats,
6649 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006650{
6651 void *hdr;
6652 struct nlattr *infoattr;
6653
Johannes Berg11f78ac2014-11-14 16:43:50 +01006654 /* skip radio stats if userspace didn't request them */
6655 if (!survey->channel && !allow_radio_stats)
6656 return 0;
6657
Eric W. Biederman15e47302012-09-07 20:12:54 +00006658 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006659 NL80211_CMD_NEW_SURVEY_RESULTS);
6660 if (!hdr)
6661 return -ENOMEM;
6662
David S. Miller9360ffd2012-03-29 04:41:26 -04006663 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6664 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006665
6666 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6667 if (!infoattr)
6668 goto nla_put_failure;
6669
Johannes Berg11f78ac2014-11-14 16:43:50 +01006670 if (survey->channel &&
6671 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006672 survey->channel->center_freq))
6673 goto nla_put_failure;
6674
6675 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6676 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6677 goto nla_put_failure;
6678 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6679 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6680 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006681 if ((survey->filled & SURVEY_INFO_TIME) &&
6682 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6683 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006684 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006685 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6686 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6687 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006688 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006689 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6690 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6691 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006692 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006693 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6694 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6695 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006696 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006697 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6698 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6699 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006700 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006701 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6702 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6703 survey->time_scan))
6704 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006705
6706 nla_nest_end(msg, infoattr);
6707
6708 return genlmsg_end(msg, hdr);
6709
6710 nla_put_failure:
6711 genlmsg_cancel(msg, hdr);
6712 return -EMSGSIZE;
6713}
6714
Johannes Berg11f78ac2014-11-14 16:43:50 +01006715static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006716{
6717 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006718 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006719 struct wireless_dev *wdev;
6720 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006721 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006722 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006723
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006724 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006725 if (res)
6726 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006727
Johannes Berg11f78ac2014-11-14 16:43:50 +01006728 /* prepare_wdev_dump parsed the attributes */
6729 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6730
Johannes Berg97990a02013-04-19 01:02:55 +02006731 if (!wdev->netdev) {
6732 res = -EINVAL;
6733 goto out_err;
6734 }
6735
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006736 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006737 res = -EOPNOTSUPP;
6738 goto out_err;
6739 }
6740
6741 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006742 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006743 if (res == -ENOENT)
6744 break;
6745 if (res)
6746 goto out_err;
6747
Johannes Berg11f78ac2014-11-14 16:43:50 +01006748 /* don't send disabled channels, but do send non-channel data */
6749 if (survey.channel &&
6750 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006751 survey_idx++;
6752 continue;
6753 }
6754
Holger Schurig61fa7132009-11-11 12:25:40 +01006755 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006756 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006757 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006758 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006759 goto out;
6760 survey_idx++;
6761 }
6762
6763 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006764 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006765 res = skb->len;
6766 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006767 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006768 return res;
6769}
6770
Samuel Ortizb23aa672009-07-01 21:26:54 +02006771static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6772{
6773 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6774 NL80211_WPA_VERSION_2));
6775}
6776
Jouni Malinen636a5d32009-03-19 13:39:22 +02006777static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6778{
Johannes Berg4c476992010-10-04 21:36:35 +02006779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6780 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006781 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006782 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6783 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006784 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006785 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006786 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006787
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006788 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6789 return -EINVAL;
6790
6791 if (!info->attrs[NL80211_ATTR_MAC])
6792 return -EINVAL;
6793
Jouni Malinen17780922009-03-27 20:52:47 +02006794 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6795 return -EINVAL;
6796
Johannes Berg19957bb2009-07-02 17:20:43 +02006797 if (!info->attrs[NL80211_ATTR_SSID])
6798 return -EINVAL;
6799
6800 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6801 return -EINVAL;
6802
Johannes Bergfffd0932009-07-08 14:22:54 +02006803 err = nl80211_parse_key(info, &key);
6804 if (err)
6805 return err;
6806
6807 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006808 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6809 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006810 if (!key.p.key || !key.p.key_len)
6811 return -EINVAL;
6812 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6813 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6814 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6815 key.p.key_len != WLAN_KEY_LEN_WEP104))
6816 return -EINVAL;
6817 if (key.idx > 4)
6818 return -EINVAL;
6819 } else {
6820 key.p.key_len = 0;
6821 key.p.key = NULL;
6822 }
6823
Johannes Bergafea0b72010-08-10 09:46:42 +02006824 if (key.idx >= 0) {
6825 int i;
6826 bool ok = false;
6827 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6828 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6829 ok = true;
6830 break;
6831 }
6832 }
Johannes Berg4c476992010-10-04 21:36:35 +02006833 if (!ok)
6834 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006835 }
6836
Johannes Berg4c476992010-10-04 21:36:35 +02006837 if (!rdev->ops->auth)
6838 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006839
Johannes Berg074ac8d2010-09-16 14:58:22 +02006840 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006841 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6842 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006843
Johannes Berg19957bb2009-07-02 17:20:43 +02006844 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006845 chan = nl80211_get_valid_chan(&rdev->wiphy,
6846 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6847 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006848 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006849
Johannes Berg19957bb2009-07-02 17:20:43 +02006850 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6851 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6852
6853 if (info->attrs[NL80211_ATTR_IE]) {
6854 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6855 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6856 }
6857
6858 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006859 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006860 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006861
Jouni Malinene39e5b52012-09-30 19:29:39 +03006862 if (auth_type == NL80211_AUTHTYPE_SAE &&
6863 !info->attrs[NL80211_ATTR_SAE_DATA])
6864 return -EINVAL;
6865
6866 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6867 if (auth_type != NL80211_AUTHTYPE_SAE)
6868 return -EINVAL;
6869 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6870 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6871 /* need to include at least Auth Transaction and Status Code */
6872 if (sae_data_len < 4)
6873 return -EINVAL;
6874 }
6875
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006876 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6877
Johannes Berg95de8172012-01-20 13:55:25 +01006878 /*
6879 * Since we no longer track auth state, ignore
6880 * requests to only change local state.
6881 */
6882 if (local_state_change)
6883 return 0;
6884
Johannes Berg91bf9b22013-05-15 17:44:01 +02006885 wdev_lock(dev->ieee80211_ptr);
6886 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6887 ssid, ssid_len, ie, ie_len,
6888 key.p.key, key.p.key_len, key.idx,
6889 sae_data, sae_data_len);
6890 wdev_unlock(dev->ieee80211_ptr);
6891 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006892}
6893
Johannes Bergc0692b82010-08-27 14:26:53 +03006894static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6895 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006896 struct cfg80211_crypto_settings *settings,
6897 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006898{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006899 memset(settings, 0, sizeof(*settings));
6900
Samuel Ortizb23aa672009-07-01 21:26:54 +02006901 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6902
Johannes Bergc0692b82010-08-27 14:26:53 +03006903 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6904 u16 proto;
6905 proto = nla_get_u16(
6906 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6907 settings->control_port_ethertype = cpu_to_be16(proto);
6908 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6909 proto != ETH_P_PAE)
6910 return -EINVAL;
6911 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6912 settings->control_port_no_encrypt = true;
6913 } else
6914 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6915
Samuel Ortizb23aa672009-07-01 21:26:54 +02006916 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6917 void *data;
6918 int len, i;
6919
6920 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6921 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6922 settings->n_ciphers_pairwise = len / sizeof(u32);
6923
6924 if (len % sizeof(u32))
6925 return -EINVAL;
6926
Johannes Berg3dc27d22009-07-02 21:36:37 +02006927 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006928 return -EINVAL;
6929
6930 memcpy(settings->ciphers_pairwise, data, len);
6931
6932 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006933 if (!cfg80211_supported_cipher_suite(
6934 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006935 settings->ciphers_pairwise[i]))
6936 return -EINVAL;
6937 }
6938
6939 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6940 settings->cipher_group =
6941 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006942 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6943 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006944 return -EINVAL;
6945 }
6946
6947 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6948 settings->wpa_versions =
6949 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6950 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6951 return -EINVAL;
6952 }
6953
6954 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6955 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006956 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006957
6958 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6959 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6960 settings->n_akm_suites = len / sizeof(u32);
6961
6962 if (len % sizeof(u32))
6963 return -EINVAL;
6964
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006965 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6966 return -EINVAL;
6967
Samuel Ortizb23aa672009-07-01 21:26:54 +02006968 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006969 }
6970
6971 return 0;
6972}
6973
Jouni Malinen636a5d32009-03-19 13:39:22 +02006974static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6975{
Johannes Berg4c476992010-10-04 21:36:35 +02006976 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6977 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006978 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006979 struct cfg80211_assoc_request req = {};
6980 const u8 *bssid, *ssid;
6981 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006982
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006983 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6984 return -EINVAL;
6985
6986 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006987 !info->attrs[NL80211_ATTR_SSID] ||
6988 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006989 return -EINVAL;
6990
Johannes Berg4c476992010-10-04 21:36:35 +02006991 if (!rdev->ops->assoc)
6992 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006993
Johannes Berg074ac8d2010-09-16 14:58:22 +02006994 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006995 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6996 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006997
Johannes Berg19957bb2009-07-02 17:20:43 +02006998 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006999
Jouni Malinen664834d2014-01-15 00:01:44 +02007000 chan = nl80211_get_valid_chan(&rdev->wiphy,
7001 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7002 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007003 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007004
Johannes Berg19957bb2009-07-02 17:20:43 +02007005 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7006 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007007
7008 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007009 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7010 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007011 }
7012
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007013 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007014 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007015 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007016 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007017 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007018 else if (mfp != NL80211_MFP_NO)
7019 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007020 }
7021
Johannes Berg3e5d7642009-07-07 14:37:26 +02007022 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007023 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007024
Ben Greear7e7c8922011-11-18 11:31:59 -08007025 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007026 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007027
7028 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007029 memcpy(&req.ht_capa_mask,
7030 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7031 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007032
7033 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007034 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007035 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007036 memcpy(&req.ht_capa,
7037 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7038 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007039 }
7040
Johannes Bergee2aca32013-02-21 17:36:01 +01007041 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007042 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007043
7044 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007045 memcpy(&req.vht_capa_mask,
7046 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7047 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007048
7049 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007050 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007051 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007052 memcpy(&req.vht_capa,
7053 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7054 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007055 }
7056
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007057 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7058 if (!(rdev->wiphy.features &
7059 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7060 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7061 return -EINVAL;
7062 req.flags |= ASSOC_REQ_USE_RRM;
7063 }
7064
Johannes Bergf62fab72013-02-21 20:09:09 +01007065 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007066 if (!err) {
7067 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007068 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7069 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007070 wdev_unlock(dev->ieee80211_ptr);
7071 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007072
Jouni Malinen636a5d32009-03-19 13:39:22 +02007073 return err;
7074}
7075
7076static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7077{
Johannes Berg4c476992010-10-04 21:36:35 +02007078 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7079 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007080 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007081 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007082 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007083 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007084
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007085 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7086 return -EINVAL;
7087
7088 if (!info->attrs[NL80211_ATTR_MAC])
7089 return -EINVAL;
7090
7091 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7092 return -EINVAL;
7093
Johannes Berg4c476992010-10-04 21:36:35 +02007094 if (!rdev->ops->deauth)
7095 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007096
Johannes Berg074ac8d2010-09-16 14:58:22 +02007097 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007098 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7099 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007100
Johannes Berg19957bb2009-07-02 17:20:43 +02007101 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007102
Johannes Berg19957bb2009-07-02 17:20:43 +02007103 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7104 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007105 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007106 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007107 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007108
7109 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007110 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7111 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007112 }
7113
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007114 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7115
Johannes Berg91bf9b22013-05-15 17:44:01 +02007116 wdev_lock(dev->ieee80211_ptr);
7117 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7118 local_state_change);
7119 wdev_unlock(dev->ieee80211_ptr);
7120 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007121}
7122
7123static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7124{
Johannes Berg4c476992010-10-04 21:36:35 +02007125 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7126 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007127 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007128 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007129 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007130 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007131
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007132 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7133 return -EINVAL;
7134
7135 if (!info->attrs[NL80211_ATTR_MAC])
7136 return -EINVAL;
7137
7138 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7139 return -EINVAL;
7140
Johannes Berg4c476992010-10-04 21:36:35 +02007141 if (!rdev->ops->disassoc)
7142 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007143
Johannes Berg074ac8d2010-09-16 14:58:22 +02007144 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007145 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7146 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007147
Johannes Berg19957bb2009-07-02 17:20:43 +02007148 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007149
Johannes Berg19957bb2009-07-02 17:20:43 +02007150 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7151 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007152 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007153 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007154 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007155
7156 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007157 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7158 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007159 }
7160
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007161 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7162
Johannes Berg91bf9b22013-05-15 17:44:01 +02007163 wdev_lock(dev->ieee80211_ptr);
7164 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7165 local_state_change);
7166 wdev_unlock(dev->ieee80211_ptr);
7167 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007168}
7169
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007170static bool
7171nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7172 int mcast_rate[IEEE80211_NUM_BANDS],
7173 int rateval)
7174{
7175 struct wiphy *wiphy = &rdev->wiphy;
7176 bool found = false;
7177 int band, i;
7178
7179 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7180 struct ieee80211_supported_band *sband;
7181
7182 sband = wiphy->bands[band];
7183 if (!sband)
7184 continue;
7185
7186 for (i = 0; i < sband->n_bitrates; i++) {
7187 if (sband->bitrates[i].bitrate == rateval) {
7188 mcast_rate[band] = i + 1;
7189 found = true;
7190 break;
7191 }
7192 }
7193 }
7194
7195 return found;
7196}
7197
Johannes Berg04a773a2009-04-19 21:24:32 +02007198static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7199{
Johannes Berg4c476992010-10-04 21:36:35 +02007200 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7201 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007202 struct cfg80211_ibss_params ibss;
7203 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007204 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007205 int err;
7206
Johannes Berg8e30bc52009-04-22 17:45:38 +02007207 memset(&ibss, 0, sizeof(ibss));
7208
Johannes Berg04a773a2009-04-19 21:24:32 +02007209 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7210 return -EINVAL;
7211
Johannes Berg683b6d32012-11-08 21:25:48 +01007212 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007213 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7214 return -EINVAL;
7215
Johannes Berg8e30bc52009-04-22 17:45:38 +02007216 ibss.beacon_interval = 100;
7217
7218 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7219 ibss.beacon_interval =
7220 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7221 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7222 return -EINVAL;
7223 }
7224
Johannes Berg4c476992010-10-04 21:36:35 +02007225 if (!rdev->ops->join_ibss)
7226 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007227
Johannes Berg4c476992010-10-04 21:36:35 +02007228 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7229 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007230
Johannes Berg79c97e92009-07-07 03:56:12 +02007231 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007232
Johannes Berg39193492011-09-16 13:45:25 +02007233 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007234 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007235
7236 if (!is_valid_ether_addr(ibss.bssid))
7237 return -EINVAL;
7238 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007239 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7240 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7241
7242 if (info->attrs[NL80211_ATTR_IE]) {
7243 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7244 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7245 }
7246
Johannes Berg683b6d32012-11-08 21:25:48 +01007247 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7248 if (err)
7249 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007250
Ilan Peer174e0cd2014-02-23 09:13:01 +02007251 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7252 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007253 return -EINVAL;
7254
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007255 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007256 case NL80211_CHAN_WIDTH_5:
7257 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007258 case NL80211_CHAN_WIDTH_20_NOHT:
7259 break;
7260 case NL80211_CHAN_WIDTH_20:
7261 case NL80211_CHAN_WIDTH_40:
7262 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
7263 break;
7264 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007265 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007266 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007267
Johannes Berg04a773a2009-04-19 21:24:32 +02007268 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007269 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007270
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007271 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7272 u8 *rates =
7273 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7274 int n_rates =
7275 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7276 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007277 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007278
Johannes Berg34850ab2011-07-18 18:08:35 +02007279 err = ieee80211_get_ratemask(sband, rates, n_rates,
7280 &ibss.basic_rates);
7281 if (err)
7282 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007283 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007284
Simon Wunderlich803768f2013-06-28 10:39:58 +02007285 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7286 memcpy(&ibss.ht_capa_mask,
7287 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7288 sizeof(ibss.ht_capa_mask));
7289
7290 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7291 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7292 return -EINVAL;
7293 memcpy(&ibss.ht_capa,
7294 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7295 sizeof(ibss.ht_capa));
7296 }
7297
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007298 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7299 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7300 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7301 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007302
Johannes Berg4c476992010-10-04 21:36:35 +02007303 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307304 bool no_ht = false;
7305
Johannes Berg4c476992010-10-04 21:36:35 +02007306 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307307 info->attrs[NL80211_ATTR_KEYS],
7308 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007309 if (IS_ERR(connkeys))
7310 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307311
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007312 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7313 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307314 kfree(connkeys);
7315 return -EINVAL;
7316 }
Johannes Berg4c476992010-10-04 21:36:35 +02007317 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007318
Antonio Quartulli267335d2012-01-31 20:25:47 +01007319 ibss.control_port =
7320 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7321
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007322 ibss.userspace_handles_dfs =
7323 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7324
Johannes Berg4c476992010-10-04 21:36:35 +02007325 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007326 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007327 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007328 return err;
7329}
7330
7331static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7332{
Johannes Berg4c476992010-10-04 21:36:35 +02007333 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7334 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007335
Johannes Berg4c476992010-10-04 21:36:35 +02007336 if (!rdev->ops->leave_ibss)
7337 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007338
Johannes Berg4c476992010-10-04 21:36:35 +02007339 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7340 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007341
Johannes Berg4c476992010-10-04 21:36:35 +02007342 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007343}
7344
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007345static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7346{
7347 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7348 struct net_device *dev = info->user_ptr[1];
7349 int mcast_rate[IEEE80211_NUM_BANDS];
7350 u32 nla_rate;
7351 int err;
7352
7353 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7354 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7355 return -EOPNOTSUPP;
7356
7357 if (!rdev->ops->set_mcast_rate)
7358 return -EOPNOTSUPP;
7359
7360 memset(mcast_rate, 0, sizeof(mcast_rate));
7361
7362 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7363 return -EINVAL;
7364
7365 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7366 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7367 return -EINVAL;
7368
7369 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7370
7371 return err;
7372}
7373
Johannes Bergad7e7182013-11-13 13:37:47 +01007374static struct sk_buff *
7375__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7376 int approxlen, u32 portid, u32 seq,
7377 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007378 enum nl80211_attrs attr,
7379 const struct nl80211_vendor_cmd_info *info,
7380 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007381{
7382 struct sk_buff *skb;
7383 void *hdr;
7384 struct nlattr *data;
7385
7386 skb = nlmsg_new(approxlen + 100, gfp);
7387 if (!skb)
7388 return NULL;
7389
7390 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7391 if (!hdr) {
7392 kfree_skb(skb);
7393 return NULL;
7394 }
7395
7396 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7397 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007398
7399 if (info) {
7400 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7401 info->vendor_id))
7402 goto nla_put_failure;
7403 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7404 info->subcmd))
7405 goto nla_put_failure;
7406 }
7407
Johannes Bergad7e7182013-11-13 13:37:47 +01007408 data = nla_nest_start(skb, attr);
7409
7410 ((void **)skb->cb)[0] = rdev;
7411 ((void **)skb->cb)[1] = hdr;
7412 ((void **)skb->cb)[2] = data;
7413
7414 return skb;
7415
7416 nla_put_failure:
7417 kfree_skb(skb);
7418 return NULL;
7419}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007420
Johannes Berge03ad6e2014-01-01 17:22:30 +01007421struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7422 enum nl80211_commands cmd,
7423 enum nl80211_attrs attr,
7424 int vendor_event_idx,
7425 int approxlen, gfp_t gfp)
7426{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007427 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007428 const struct nl80211_vendor_cmd_info *info;
7429
7430 switch (cmd) {
7431 case NL80211_CMD_TESTMODE:
7432 if (WARN_ON(vendor_event_idx != -1))
7433 return NULL;
7434 info = NULL;
7435 break;
7436 case NL80211_CMD_VENDOR:
7437 if (WARN_ON(vendor_event_idx < 0 ||
7438 vendor_event_idx >= wiphy->n_vendor_events))
7439 return NULL;
7440 info = &wiphy->vendor_events[vendor_event_idx];
7441 break;
7442 default:
7443 WARN_ON(1);
7444 return NULL;
7445 }
7446
7447 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7448 cmd, attr, info, gfp);
7449}
7450EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7451
7452void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7453{
7454 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7455 void *hdr = ((void **)skb->cb)[1];
7456 struct nlattr *data = ((void **)skb->cb)[2];
7457 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7458
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007459 /* clear CB data for netlink core to own from now on */
7460 memset(skb->cb, 0, sizeof(skb->cb));
7461
Johannes Berge03ad6e2014-01-01 17:22:30 +01007462 nla_nest_end(skb, data);
7463 genlmsg_end(skb, hdr);
7464
7465 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7466 mcgrp = NL80211_MCGRP_VENDOR;
7467
7468 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7469 mcgrp, gfp);
7470}
7471EXPORT_SYMBOL(__cfg80211_send_event_skb);
7472
Johannes Bergaff89a92009-07-01 21:26:51 +02007473#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007474static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7475{
Johannes Berg4c476992010-10-04 21:36:35 +02007476 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007477 struct wireless_dev *wdev =
7478 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007479 int err;
7480
David Spinadelfc73f112013-07-31 18:04:15 +03007481 if (!rdev->ops->testmode_cmd)
7482 return -EOPNOTSUPP;
7483
7484 if (IS_ERR(wdev)) {
7485 err = PTR_ERR(wdev);
7486 if (err != -EINVAL)
7487 return err;
7488 wdev = NULL;
7489 } else if (wdev->wiphy != &rdev->wiphy) {
7490 return -EINVAL;
7491 }
7492
Johannes Bergaff89a92009-07-01 21:26:51 +02007493 if (!info->attrs[NL80211_ATTR_TESTDATA])
7494 return -EINVAL;
7495
Johannes Bergad7e7182013-11-13 13:37:47 +01007496 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007497 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007498 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7499 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007500 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007501
Johannes Bergaff89a92009-07-01 21:26:51 +02007502 return err;
7503}
7504
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007505static int nl80211_testmode_dump(struct sk_buff *skb,
7506 struct netlink_callback *cb)
7507{
Johannes Berg00918d32011-12-13 17:22:05 +01007508 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007509 int err;
7510 long phy_idx;
7511 void *data = NULL;
7512 int data_len = 0;
7513
Johannes Berg5fe231e2013-05-08 21:45:15 +02007514 rtnl_lock();
7515
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007516 if (cb->args[0]) {
7517 /*
7518 * 0 is a valid index, but not valid for args[0],
7519 * so we need to offset by 1.
7520 */
7521 phy_idx = cb->args[0] - 1;
7522 } else {
7523 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7524 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7525 nl80211_policy);
7526 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007527 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007528
Johannes Berg2bd7e352012-06-15 14:23:16 +02007529 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7530 nl80211_fam.attrbuf);
7531 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007532 err = PTR_ERR(rdev);
7533 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007534 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007535 phy_idx = rdev->wiphy_idx;
7536 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007537
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007538 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7539 cb->args[1] =
7540 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7541 }
7542
7543 if (cb->args[1]) {
7544 data = nla_data((void *)cb->args[1]);
7545 data_len = nla_len((void *)cb->args[1]);
7546 }
7547
Johannes Berg00918d32011-12-13 17:22:05 +01007548 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7549 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007550 err = -ENOENT;
7551 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007552 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007553
Johannes Berg00918d32011-12-13 17:22:05 +01007554 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007555 err = -EOPNOTSUPP;
7556 goto out_err;
7557 }
7558
7559 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007560 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007561 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7562 NL80211_CMD_TESTMODE);
7563 struct nlattr *tmdata;
7564
Dan Carpentercb35fba2013-08-14 14:50:01 +03007565 if (!hdr)
7566 break;
7567
David S. Miller9360ffd2012-03-29 04:41:26 -04007568 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007569 genlmsg_cancel(skb, hdr);
7570 break;
7571 }
7572
7573 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7574 if (!tmdata) {
7575 genlmsg_cancel(skb, hdr);
7576 break;
7577 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007578 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007579 nla_nest_end(skb, tmdata);
7580
7581 if (err == -ENOBUFS || err == -ENOENT) {
7582 genlmsg_cancel(skb, hdr);
7583 break;
7584 } else if (err) {
7585 genlmsg_cancel(skb, hdr);
7586 goto out_err;
7587 }
7588
7589 genlmsg_end(skb, hdr);
7590 }
7591
7592 err = skb->len;
7593 /* see above */
7594 cb->args[0] = phy_idx + 1;
7595 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007596 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007597 return err;
7598}
Johannes Bergaff89a92009-07-01 21:26:51 +02007599#endif
7600
Samuel Ortizb23aa672009-07-01 21:26:54 +02007601static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7602{
Johannes Berg4c476992010-10-04 21:36:35 +02007603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7604 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007605 struct cfg80211_connect_params connect;
7606 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007607 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007608 int err;
7609
7610 memset(&connect, 0, sizeof(connect));
7611
7612 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7613 return -EINVAL;
7614
7615 if (!info->attrs[NL80211_ATTR_SSID] ||
7616 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7617 return -EINVAL;
7618
7619 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7620 connect.auth_type =
7621 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007622 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7623 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007624 return -EINVAL;
7625 } else
7626 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7627
7628 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7629
Johannes Bergc0692b82010-08-27 14:26:53 +03007630 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007631 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007632 if (err)
7633 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007634
Johannes Berg074ac8d2010-09-16 14:58:22 +02007635 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007636 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7637 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007638
Johannes Berg79c97e92009-07-07 03:56:12 +02007639 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007640
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307641 connect.bg_scan_period = -1;
7642 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7643 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7644 connect.bg_scan_period =
7645 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7646 }
7647
Samuel Ortizb23aa672009-07-01 21:26:54 +02007648 if (info->attrs[NL80211_ATTR_MAC])
7649 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007650 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7651 connect.bssid_hint =
7652 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007653 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7654 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7655
7656 if (info->attrs[NL80211_ATTR_IE]) {
7657 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7658 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7659 }
7660
Jouni Malinencee00a92013-01-15 17:15:57 +02007661 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7662 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7663 if (connect.mfp != NL80211_MFP_REQUIRED &&
7664 connect.mfp != NL80211_MFP_NO)
7665 return -EINVAL;
7666 } else {
7667 connect.mfp = NL80211_MFP_NO;
7668 }
7669
Samuel Ortizb23aa672009-07-01 21:26:54 +02007670 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007671 connect.channel = nl80211_get_valid_chan(
7672 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7673 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007674 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007675 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007676 connect.channel_hint = nl80211_get_valid_chan(
7677 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7678 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007679 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007680 }
7681
Johannes Bergfffd0932009-07-08 14:22:54 +02007682 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7683 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307684 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007685 if (IS_ERR(connkeys))
7686 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007687 }
7688
Ben Greear7e7c8922011-11-18 11:31:59 -08007689 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7690 connect.flags |= ASSOC_REQ_DISABLE_HT;
7691
7692 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7693 memcpy(&connect.ht_capa_mask,
7694 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7695 sizeof(connect.ht_capa_mask));
7696
7697 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007698 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007699 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007700 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007701 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007702 memcpy(&connect.ht_capa,
7703 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7704 sizeof(connect.ht_capa));
7705 }
7706
Johannes Bergee2aca32013-02-21 17:36:01 +01007707 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7708 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7709
7710 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7711 memcpy(&connect.vht_capa_mask,
7712 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7713 sizeof(connect.vht_capa_mask));
7714
7715 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7716 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007717 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007718 return -EINVAL;
7719 }
7720 memcpy(&connect.vht_capa,
7721 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7722 sizeof(connect.vht_capa));
7723 }
7724
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007725 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7726 if (!(rdev->wiphy.features &
7727 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7728 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7729 return -EINVAL;
7730 connect.flags |= ASSOC_REQ_USE_RRM;
7731 }
7732
Johannes Berg83739b02013-05-15 17:44:01 +02007733 wdev_lock(dev->ieee80211_ptr);
7734 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7735 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007736 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007737 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007738 return err;
7739}
7740
7741static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7742{
Johannes Berg4c476992010-10-04 21:36:35 +02007743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7744 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007745 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007746 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007747
7748 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7749 reason = WLAN_REASON_DEAUTH_LEAVING;
7750 else
7751 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7752
7753 if (reason == 0)
7754 return -EINVAL;
7755
Johannes Berg074ac8d2010-09-16 14:58:22 +02007756 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007757 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7758 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007759
Johannes Berg83739b02013-05-15 17:44:01 +02007760 wdev_lock(dev->ieee80211_ptr);
7761 ret = cfg80211_disconnect(rdev, dev, reason, true);
7762 wdev_unlock(dev->ieee80211_ptr);
7763 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007764}
7765
Johannes Berg463d0182009-07-14 00:33:35 +02007766static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7767{
Johannes Berg4c476992010-10-04 21:36:35 +02007768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007769 struct net *net;
7770 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007771
Vadim Kochan4b681c82015-01-12 16:34:05 +02007772 if (info->attrs[NL80211_ATTR_PID]) {
7773 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7774
7775 net = get_net_ns_by_pid(pid);
7776 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7777 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7778
7779 net = get_net_ns_by_fd(fd);
7780 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007781 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007782 }
Johannes Berg463d0182009-07-14 00:33:35 +02007783
Johannes Berg4c476992010-10-04 21:36:35 +02007784 if (IS_ERR(net))
7785 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007786
7787 err = 0;
7788
7789 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007790 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7791 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007792
Johannes Berg463d0182009-07-14 00:33:35 +02007793 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007794 return err;
7795}
7796
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007797static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7798{
Johannes Berg4c476992010-10-04 21:36:35 +02007799 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007800 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7801 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007802 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007803 struct cfg80211_pmksa pmksa;
7804
7805 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7806
7807 if (!info->attrs[NL80211_ATTR_MAC])
7808 return -EINVAL;
7809
7810 if (!info->attrs[NL80211_ATTR_PMKID])
7811 return -EINVAL;
7812
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007813 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7814 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7815
Johannes Berg074ac8d2010-09-16 14:58:22 +02007816 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007817 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7818 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007819
7820 switch (info->genlhdr->cmd) {
7821 case NL80211_CMD_SET_PMKSA:
7822 rdev_ops = rdev->ops->set_pmksa;
7823 break;
7824 case NL80211_CMD_DEL_PMKSA:
7825 rdev_ops = rdev->ops->del_pmksa;
7826 break;
7827 default:
7828 WARN_ON(1);
7829 break;
7830 }
7831
Johannes Berg4c476992010-10-04 21:36:35 +02007832 if (!rdev_ops)
7833 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007834
Johannes Berg4c476992010-10-04 21:36:35 +02007835 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007836}
7837
7838static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7839{
Johannes Berg4c476992010-10-04 21:36:35 +02007840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7841 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007842
Johannes Berg074ac8d2010-09-16 14:58:22 +02007843 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007844 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7845 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007846
Johannes Berg4c476992010-10-04 21:36:35 +02007847 if (!rdev->ops->flush_pmksa)
7848 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007849
Hila Gonene35e4d22012-06-27 17:19:42 +03007850 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007851}
7852
Arik Nemtsov109086c2011-09-28 14:12:50 +03007853static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7854{
7855 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7856 struct net_device *dev = info->user_ptr[1];
7857 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307858 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007859 u16 status_code;
7860 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007861 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007862
7863 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7864 !rdev->ops->tdls_mgmt)
7865 return -EOPNOTSUPP;
7866
7867 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7868 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7869 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7870 !info->attrs[NL80211_ATTR_IE] ||
7871 !info->attrs[NL80211_ATTR_MAC])
7872 return -EINVAL;
7873
7874 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7875 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7876 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7877 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007878 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307879 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7880 peer_capability =
7881 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007882
Hila Gonene35e4d22012-06-27 17:19:42 +03007883 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307884 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007885 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007886 nla_data(info->attrs[NL80211_ATTR_IE]),
7887 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007888}
7889
7890static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7891{
7892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7893 struct net_device *dev = info->user_ptr[1];
7894 enum nl80211_tdls_operation operation;
7895 u8 *peer;
7896
7897 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7898 !rdev->ops->tdls_oper)
7899 return -EOPNOTSUPP;
7900
7901 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7902 !info->attrs[NL80211_ATTR_MAC])
7903 return -EINVAL;
7904
7905 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7906 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7907
Hila Gonene35e4d22012-06-27 17:19:42 +03007908 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007909}
7910
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007911static int nl80211_remain_on_channel(struct sk_buff *skb,
7912 struct genl_info *info)
7913{
Johannes Berg4c476992010-10-04 21:36:35 +02007914 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007915 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007916 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007917 struct sk_buff *msg;
7918 void *hdr;
7919 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007920 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007921 int err;
7922
7923 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7924 !info->attrs[NL80211_ATTR_DURATION])
7925 return -EINVAL;
7926
7927 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7928
Johannes Berg7c4ef712011-11-18 15:33:48 +01007929 if (!rdev->ops->remain_on_channel ||
7930 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007931 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007932
Johannes Bergebf348f2012-06-01 12:50:54 +02007933 /*
7934 * We should be on that channel for at least a minimum amount of
7935 * time (10ms) but no longer than the driver supports.
7936 */
7937 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7938 duration > rdev->wiphy.max_remain_on_channel_duration)
7939 return -EINVAL;
7940
Johannes Berg683b6d32012-11-08 21:25:48 +01007941 err = nl80211_parse_chandef(rdev, info, &chandef);
7942 if (err)
7943 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007944
7945 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007946 if (!msg)
7947 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007948
Eric W. Biederman15e47302012-09-07 20:12:54 +00007949 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007950 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007951 if (!hdr) {
7952 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007953 goto free_msg;
7954 }
7955
Johannes Berg683b6d32012-11-08 21:25:48 +01007956 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7957 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007958
7959 if (err)
7960 goto free_msg;
7961
David S. Miller9360ffd2012-03-29 04:41:26 -04007962 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7963 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007964
7965 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007966
7967 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007968
7969 nla_put_failure:
7970 err = -ENOBUFS;
7971 free_msg:
7972 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007973 return err;
7974}
7975
7976static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7977 struct genl_info *info)
7978{
Johannes Berg4c476992010-10-04 21:36:35 +02007979 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007980 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007981 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007982
7983 if (!info->attrs[NL80211_ATTR_COOKIE])
7984 return -EINVAL;
7985
Johannes Berg4c476992010-10-04 21:36:35 +02007986 if (!rdev->ops->cancel_remain_on_channel)
7987 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007988
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007989 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7990
Hila Gonene35e4d22012-06-27 17:19:42 +03007991 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007992}
7993
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007994static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7995 u8 *rates, u8 rates_len)
7996{
7997 u8 i;
7998 u32 mask = 0;
7999
8000 for (i = 0; i < rates_len; i++) {
8001 int rate = (rates[i] & 0x7f) * 5;
8002 int ridx;
8003 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8004 struct ieee80211_rate *srate =
8005 &sband->bitrates[ridx];
8006 if (rate == srate->bitrate) {
8007 mask |= 1 << ridx;
8008 break;
8009 }
8010 }
8011 if (ridx == sband->n_bitrates)
8012 return 0; /* rate not found */
8013 }
8014
8015 return mask;
8016}
8017
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008018static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8019 u8 *rates, u8 rates_len,
8020 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8021{
8022 u8 i;
8023
8024 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8025
8026 for (i = 0; i < rates_len; i++) {
8027 int ridx, rbit;
8028
8029 ridx = rates[i] / 8;
8030 rbit = BIT(rates[i] % 8);
8031
8032 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008033 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008034 return false;
8035
8036 /* check availability */
8037 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8038 mcs[ridx] |= rbit;
8039 else
8040 return false;
8041 }
8042
8043 return true;
8044}
8045
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008046static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8047{
8048 u16 mcs_mask = 0;
8049
8050 switch (vht_mcs_map) {
8051 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8052 break;
8053 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8054 mcs_mask = 0x00FF;
8055 break;
8056 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8057 mcs_mask = 0x01FF;
8058 break;
8059 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8060 mcs_mask = 0x03FF;
8061 break;
8062 default:
8063 break;
8064 }
8065
8066 return mcs_mask;
8067}
8068
8069static void vht_build_mcs_mask(u16 vht_mcs_map,
8070 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8071{
8072 u8 nss;
8073
8074 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8075 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8076 vht_mcs_map >>= 2;
8077 }
8078}
8079
8080static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8081 struct nl80211_txrate_vht *txrate,
8082 u16 mcs[NL80211_VHT_NSS_MAX])
8083{
8084 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8085 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8086 u8 i;
8087
8088 if (!sband->vht_cap.vht_supported)
8089 return false;
8090
8091 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8092
8093 /* Build vht_mcs_mask from VHT capabilities */
8094 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8095
8096 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8097 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8098 mcs[i] = txrate->mcs[i];
8099 else
8100 return false;
8101 }
8102
8103 return true;
8104}
8105
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008106static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008107 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8108 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008109 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8110 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008111 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008112 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008113};
8114
8115static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8116 struct genl_info *info)
8117{
8118 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008120 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008121 int rem, i;
8122 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008123 struct nlattr *tx_rates;
8124 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008125 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008126
Johannes Berg4c476992010-10-04 21:36:35 +02008127 if (!rdev->ops->set_bitrate_mask)
8128 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008129
8130 memset(&mask, 0, sizeof(mask));
8131 /* Default to all rates enabled */
8132 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8133 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008134
8135 if (!sband)
8136 continue;
8137
8138 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008139 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008140 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008141 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008142
8143 if (!sband->vht_cap.vht_supported)
8144 continue;
8145
8146 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8147 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008148 }
8149
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008150 /* if no rates are given set it back to the defaults */
8151 if (!info->attrs[NL80211_ATTR_TX_RATES])
8152 goto out;
8153
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008154 /*
8155 * The nested attribute uses enum nl80211_band as the index. This maps
8156 * directly to the enum ieee80211_band values used in cfg80211.
8157 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008158 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008159 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008160 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008161 int err;
8162
Johannes Berg4c476992010-10-04 21:36:35 +02008163 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8164 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008165 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008166 if (sband == NULL)
8167 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008168 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8169 nla_len(tx_rates), nl80211_txattr_policy);
8170 if (err)
8171 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008172 if (tb[NL80211_TXRATE_LEGACY]) {
8173 mask.control[band].legacy = rateset_to_mask(
8174 sband,
8175 nla_data(tb[NL80211_TXRATE_LEGACY]),
8176 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308177 if ((mask.control[band].legacy == 0) &&
8178 nla_len(tb[NL80211_TXRATE_LEGACY]))
8179 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008180 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008181 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008182 if (!ht_rateset_to_mask(
8183 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008184 nla_data(tb[NL80211_TXRATE_HT]),
8185 nla_len(tb[NL80211_TXRATE_HT]),
8186 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008187 return -EINVAL;
8188 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008189 if (tb[NL80211_TXRATE_VHT]) {
8190 if (!vht_set_mcs_mask(
8191 sband,
8192 nla_data(tb[NL80211_TXRATE_VHT]),
8193 mask.control[band].vht_mcs))
8194 return -EINVAL;
8195 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008196 if (tb[NL80211_TXRATE_GI]) {
8197 mask.control[band].gi =
8198 nla_get_u8(tb[NL80211_TXRATE_GI]);
8199 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8200 return -EINVAL;
8201 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008202
8203 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008204 /* don't allow empty legacy rates if HT or VHT
8205 * are not even supported.
8206 */
8207 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8208 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008209 return -EINVAL;
8210
8211 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008212 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008213 goto out;
8214
8215 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8216 if (mask.control[band].vht_mcs[i])
8217 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008218
8219 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008220 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008221 }
8222 }
8223
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008224out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008225 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008226}
8227
Johannes Berg2e161f782010-08-12 15:38:38 +02008228static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008229{
Johannes Berg4c476992010-10-04 21:36:35 +02008230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008231 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f782010-08-12 15:38:38 +02008232 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008233
8234 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8235 return -EINVAL;
8236
Johannes Berg2e161f782010-08-12 15:38:38 +02008237 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8238 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008239
Johannes Berg71bbc992012-06-15 15:30:18 +02008240 switch (wdev->iftype) {
8241 case NL80211_IFTYPE_STATION:
8242 case NL80211_IFTYPE_ADHOC:
8243 case NL80211_IFTYPE_P2P_CLIENT:
8244 case NL80211_IFTYPE_AP:
8245 case NL80211_IFTYPE_AP_VLAN:
8246 case NL80211_IFTYPE_MESH_POINT:
8247 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008248 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008249 break;
8250 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008251 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008252 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008253
8254 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008255 if (!rdev->ops->mgmt_tx)
8256 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008257
Eric W. Biederman15e47302012-09-07 20:12:54 +00008258 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008259 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8260 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008261}
8262
Johannes Berg2e161f782010-08-12 15:38:38 +02008263static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008264{
Johannes Berg4c476992010-10-04 21:36:35 +02008265 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008266 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008267 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008268 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008269 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008270 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008271 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008272 struct cfg80211_mgmt_tx_params params = {
8273 .dont_wait_for_ack =
8274 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8275 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008276
Johannes Berg683b6d32012-11-08 21:25:48 +01008277 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008278 return -EINVAL;
8279
Johannes Berg4c476992010-10-04 21:36:35 +02008280 if (!rdev->ops->mgmt_tx)
8281 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008282
Johannes Berg71bbc992012-06-15 15:30:18 +02008283 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008284 case NL80211_IFTYPE_P2P_DEVICE:
8285 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8286 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008287 case NL80211_IFTYPE_STATION:
8288 case NL80211_IFTYPE_ADHOC:
8289 case NL80211_IFTYPE_P2P_CLIENT:
8290 case NL80211_IFTYPE_AP:
8291 case NL80211_IFTYPE_AP_VLAN:
8292 case NL80211_IFTYPE_MESH_POINT:
8293 case NL80211_IFTYPE_P2P_GO:
8294 break;
8295 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008296 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008297 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008298
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008299 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008300 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008301 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008302 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008303
8304 /*
8305 * We should wait on the channel for at least a minimum amount
8306 * of time (10ms) but no longer than the driver supports.
8307 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008308 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8309 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008310 return -EINVAL;
8311
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008312 }
8313
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008314 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008315
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008316 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008317 return -EINVAL;
8318
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008319 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308320
Antonio Quartulliea141b752013-06-11 14:20:03 +02008321 /* get the channel if any has been specified, otherwise pass NULL to
8322 * the driver. The latter will use the current one
8323 */
8324 chandef.chan = NULL;
8325 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8326 err = nl80211_parse_chandef(rdev, info, &chandef);
8327 if (err)
8328 return err;
8329 }
8330
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008331 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008332 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008333
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008334 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8335 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8336
8337 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8338 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8339 int i;
8340
8341 if (len % sizeof(u16))
8342 return -EINVAL;
8343
8344 params.n_csa_offsets = len / sizeof(u16);
8345 params.csa_offsets =
8346 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8347
8348 /* check that all the offsets fit the frame */
8349 for (i = 0; i < params.n_csa_offsets; i++) {
8350 if (params.csa_offsets[i] >= params.len)
8351 return -EINVAL;
8352 }
8353 }
8354
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008355 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008356 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8357 if (!msg)
8358 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008359
Eric W. Biederman15e47302012-09-07 20:12:54 +00008360 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008361 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008362 if (!hdr) {
8363 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008364 goto free_msg;
8365 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008366 }
Johannes Berge247bd902011-11-04 11:18:21 +01008367
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008368 params.chan = chandef.chan;
8369 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008370 if (err)
8371 goto free_msg;
8372
Johannes Berge247bd902011-11-04 11:18:21 +01008373 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008374 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8375 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008376
Johannes Berge247bd902011-11-04 11:18:21 +01008377 genlmsg_end(msg, hdr);
8378 return genlmsg_reply(msg, info);
8379 }
8380
8381 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008382
8383 nla_put_failure:
8384 err = -ENOBUFS;
8385 free_msg:
8386 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008387 return err;
8388}
8389
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008390static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8391{
8392 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008393 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008394 u64 cookie;
8395
8396 if (!info->attrs[NL80211_ATTR_COOKIE])
8397 return -EINVAL;
8398
8399 if (!rdev->ops->mgmt_tx_cancel_wait)
8400 return -EOPNOTSUPP;
8401
Johannes Berg71bbc992012-06-15 15:30:18 +02008402 switch (wdev->iftype) {
8403 case NL80211_IFTYPE_STATION:
8404 case NL80211_IFTYPE_ADHOC:
8405 case NL80211_IFTYPE_P2P_CLIENT:
8406 case NL80211_IFTYPE_AP:
8407 case NL80211_IFTYPE_AP_VLAN:
8408 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008409 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008410 break;
8411 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008412 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008413 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008414
8415 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8416
Hila Gonene35e4d22012-06-27 17:19:42 +03008417 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008418}
8419
Kalle Valoffb9eb32010-02-17 17:58:10 +02008420static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8421{
Johannes Berg4c476992010-10-04 21:36:35 +02008422 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008423 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008424 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008425 u8 ps_state;
8426 bool state;
8427 int err;
8428
Johannes Berg4c476992010-10-04 21:36:35 +02008429 if (!info->attrs[NL80211_ATTR_PS_STATE])
8430 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008431
8432 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8433
Johannes Berg4c476992010-10-04 21:36:35 +02008434 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8435 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008436
8437 wdev = dev->ieee80211_ptr;
8438
Johannes Berg4c476992010-10-04 21:36:35 +02008439 if (!rdev->ops->set_power_mgmt)
8440 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008441
8442 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8443
8444 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008445 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008446
Hila Gonene35e4d22012-06-27 17:19:42 +03008447 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008448 if (!err)
8449 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008450 return err;
8451}
8452
8453static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8454{
Johannes Berg4c476992010-10-04 21:36:35 +02008455 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008456 enum nl80211_ps_state ps_state;
8457 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008458 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008459 struct sk_buff *msg;
8460 void *hdr;
8461 int err;
8462
Kalle Valoffb9eb32010-02-17 17:58:10 +02008463 wdev = dev->ieee80211_ptr;
8464
Johannes Berg4c476992010-10-04 21:36:35 +02008465 if (!rdev->ops->set_power_mgmt)
8466 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008467
8468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008469 if (!msg)
8470 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008471
Eric W. Biederman15e47302012-09-07 20:12:54 +00008472 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008473 NL80211_CMD_GET_POWER_SAVE);
8474 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008475 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008476 goto free_msg;
8477 }
8478
8479 if (wdev->ps)
8480 ps_state = NL80211_PS_ENABLED;
8481 else
8482 ps_state = NL80211_PS_DISABLED;
8483
David S. Miller9360ffd2012-03-29 04:41:26 -04008484 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8485 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008486
8487 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008488 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008489
Johannes Berg4c476992010-10-04 21:36:35 +02008490 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008491 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008492 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008493 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008494 return err;
8495}
8496
Johannes Berg94e860f2014-01-20 23:58:15 +01008497static const struct nla_policy
8498nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008499 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8500 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8501 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008502 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8503 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8504 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008505};
8506
Thomas Pedersen84f10702012-07-12 16:17:33 -07008507static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008508 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008509{
8510 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008511 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008512 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008513
Johannes Bergd9d8b012012-11-26 12:51:52 +01008514 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008515 return -EINVAL;
8516
Thomas Pedersen84f10702012-07-12 16:17:33 -07008517 if (!rdev->ops->set_cqm_txe_config)
8518 return -EOPNOTSUPP;
8519
8520 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8521 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8522 return -EOPNOTSUPP;
8523
Hila Gonene35e4d22012-06-27 17:19:42 +03008524 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008525}
8526
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008527static int nl80211_set_cqm_rssi(struct genl_info *info,
8528 s32 threshold, u32 hysteresis)
8529{
Johannes Berg4c476992010-10-04 21:36:35 +02008530 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008531 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008532 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008533
8534 if (threshold > 0)
8535 return -EINVAL;
8536
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008537 /* disabling - hysteresis should also be zero then */
8538 if (threshold == 0)
8539 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008540
Johannes Berg4c476992010-10-04 21:36:35 +02008541 if (!rdev->ops->set_cqm_rssi_config)
8542 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008543
Johannes Berg074ac8d2010-09-16 14:58:22 +02008544 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008545 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8546 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008547
Hila Gonene35e4d22012-06-27 17:19:42 +03008548 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008549}
8550
8551static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8552{
8553 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8554 struct nlattr *cqm;
8555 int err;
8556
8557 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008558 if (!cqm)
8559 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008560
8561 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8562 nl80211_attr_cqm_policy);
8563 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008564 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008565
8566 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8567 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008568 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8569 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008570
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008571 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8572 }
8573
8574 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8575 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8576 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8577 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8578 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8579 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8580
8581 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8582 }
8583
8584 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008585}
8586
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008587static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8588{
8589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8590 struct net_device *dev = info->user_ptr[1];
8591 struct ocb_setup setup = {};
8592 int err;
8593
8594 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8595 if (err)
8596 return err;
8597
8598 return cfg80211_join_ocb(rdev, dev, &setup);
8599}
8600
8601static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8602{
8603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8604 struct net_device *dev = info->user_ptr[1];
8605
8606 return cfg80211_leave_ocb(rdev, dev);
8607}
8608
Johannes Berg29cbe682010-12-03 09:20:44 +01008609static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8610{
8611 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8612 struct net_device *dev = info->user_ptr[1];
8613 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008614 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008615 int err;
8616
8617 /* start with default */
8618 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008619 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008620
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008621 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008622 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008623 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008624 if (err)
8625 return err;
8626 }
8627
8628 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8629 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8630 return -EINVAL;
8631
Javier Cardonac80d5452010-12-16 17:37:49 -08008632 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8633 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8634
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008635 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8636 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8637 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8638 return -EINVAL;
8639
Marco Porsch9bdbf042013-01-07 16:04:51 +01008640 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8641 setup.beacon_interval =
8642 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8643 if (setup.beacon_interval < 10 ||
8644 setup.beacon_interval > 10000)
8645 return -EINVAL;
8646 }
8647
8648 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8649 setup.dtim_period =
8650 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8651 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8652 return -EINVAL;
8653 }
8654
Javier Cardonac80d5452010-12-16 17:37:49 -08008655 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8656 /* parse additional setup parameters if given */
8657 err = nl80211_parse_mesh_setup(info, &setup);
8658 if (err)
8659 return err;
8660 }
8661
Thomas Pedersend37bb182013-03-04 13:06:13 -08008662 if (setup.user_mpm)
8663 cfg.auto_open_plinks = false;
8664
Johannes Bergcc1d2802012-05-16 23:50:20 +02008665 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008666 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8667 if (err)
8668 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008669 } else {
8670 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008671 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008672 }
8673
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008674 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8675 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8676 int n_rates =
8677 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8678 struct ieee80211_supported_band *sband;
8679
8680 if (!setup.chandef.chan)
8681 return -EINVAL;
8682
8683 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8684
8685 err = ieee80211_get_ratemask(sband, rates, n_rates,
8686 &setup.basic_rates);
8687 if (err)
8688 return err;
8689 }
8690
Javier Cardonac80d5452010-12-16 17:37:49 -08008691 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008692}
8693
8694static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8695{
8696 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8697 struct net_device *dev = info->user_ptr[1];
8698
8699 return cfg80211_leave_mesh(rdev, dev);
8700}
8701
Johannes Bergdfb89c52012-06-27 09:23:48 +02008702#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008703static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8704 struct cfg80211_registered_device *rdev)
8705{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008706 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008707 struct nlattr *nl_pats, *nl_pat;
8708 int i, pat_len;
8709
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008710 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008711 return 0;
8712
8713 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8714 if (!nl_pats)
8715 return -ENOBUFS;
8716
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008717 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008718 nl_pat = nla_nest_start(msg, i + 1);
8719 if (!nl_pat)
8720 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008721 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008722 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008723 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008724 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8725 wowlan->patterns[i].pattern) ||
8726 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008727 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008728 return -ENOBUFS;
8729 nla_nest_end(msg, nl_pat);
8730 }
8731 nla_nest_end(msg, nl_pats);
8732
8733 return 0;
8734}
8735
Johannes Berg2a0e0472013-01-23 22:57:40 +01008736static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8737 struct cfg80211_wowlan_tcp *tcp)
8738{
8739 struct nlattr *nl_tcp;
8740
8741 if (!tcp)
8742 return 0;
8743
8744 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8745 if (!nl_tcp)
8746 return -ENOBUFS;
8747
8748 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8749 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8750 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8751 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8752 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8753 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8754 tcp->payload_len, tcp->payload) ||
8755 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8756 tcp->data_interval) ||
8757 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8758 tcp->wake_len, tcp->wake_data) ||
8759 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8760 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8761 return -ENOBUFS;
8762
8763 if (tcp->payload_seq.len &&
8764 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8765 sizeof(tcp->payload_seq), &tcp->payload_seq))
8766 return -ENOBUFS;
8767
8768 if (tcp->payload_tok.len &&
8769 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8770 sizeof(tcp->payload_tok) + tcp->tokens_size,
8771 &tcp->payload_tok))
8772 return -ENOBUFS;
8773
Johannes Berge248ad32013-05-16 10:24:28 +02008774 nla_nest_end(msg, nl_tcp);
8775
Johannes Berg2a0e0472013-01-23 22:57:40 +01008776 return 0;
8777}
8778
Luciano Coelho75453cc2015-01-09 14:06:37 +02008779static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8780 struct cfg80211_sched_scan_request *req)
8781{
8782 struct nlattr *nd, *freqs, *matches, *match;
8783 int i;
8784
8785 if (!req)
8786 return 0;
8787
8788 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
8789 if (!nd)
8790 return -ENOBUFS;
8791
8792 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval))
8793 return -ENOBUFS;
8794
8795 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8796 if (!freqs)
8797 return -ENOBUFS;
8798
8799 for (i = 0; i < req->n_channels; i++)
8800 nla_put_u32(msg, i, req->channels[i]->center_freq);
8801
8802 nla_nest_end(msg, freqs);
8803
8804 if (req->n_match_sets) {
8805 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
8806 for (i = 0; i < req->n_match_sets; i++) {
8807 match = nla_nest_start(msg, i);
8808 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
8809 req->match_sets[i].ssid.ssid_len,
8810 req->match_sets[i].ssid.ssid);
8811 nla_nest_end(msg, match);
8812 }
8813 nla_nest_end(msg, matches);
8814 }
8815
8816 nla_nest_end(msg, nd);
8817
8818 return 0;
8819}
8820
Johannes Bergff1b6e62011-05-04 15:37:28 +02008821static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8822{
8823 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8824 struct sk_buff *msg;
8825 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008826 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008827
Johannes Berg964dc9e2013-06-03 17:25:34 +02008828 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008829 return -EOPNOTSUPP;
8830
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008831 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008832 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008833 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8834 rdev->wiphy.wowlan_config->tcp->payload_len +
8835 rdev->wiphy.wowlan_config->tcp->wake_len +
8836 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008837 }
8838
8839 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008840 if (!msg)
8841 return -ENOMEM;
8842
Eric W. Biederman15e47302012-09-07 20:12:54 +00008843 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008844 NL80211_CMD_GET_WOWLAN);
8845 if (!hdr)
8846 goto nla_put_failure;
8847
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008848 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008849 struct nlattr *nl_wowlan;
8850
8851 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8852 if (!nl_wowlan)
8853 goto nla_put_failure;
8854
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008855 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008856 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008857 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008858 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008859 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008860 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008861 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008862 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008863 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008864 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008865 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008866 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008867 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008868 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8869 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008870
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008871 if (nl80211_send_wowlan_patterns(msg, rdev))
8872 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008873
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008874 if (nl80211_send_wowlan_tcp(msg,
8875 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008876 goto nla_put_failure;
8877
Luciano Coelho75453cc2015-01-09 14:06:37 +02008878 if (nl80211_send_wowlan_nd(
8879 msg,
8880 rdev->wiphy.wowlan_config->nd_config))
8881 goto nla_put_failure;
8882
Johannes Bergff1b6e62011-05-04 15:37:28 +02008883 nla_nest_end(msg, nl_wowlan);
8884 }
8885
8886 genlmsg_end(msg, hdr);
8887 return genlmsg_reply(msg, info);
8888
8889nla_put_failure:
8890 nlmsg_free(msg);
8891 return -ENOBUFS;
8892}
8893
Johannes Berg2a0e0472013-01-23 22:57:40 +01008894static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8895 struct nlattr *attr,
8896 struct cfg80211_wowlan *trig)
8897{
8898 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8899 struct cfg80211_wowlan_tcp *cfg;
8900 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8901 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8902 u32 size;
8903 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8904 int err, port;
8905
Johannes Berg964dc9e2013-06-03 17:25:34 +02008906 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008907 return -EINVAL;
8908
8909 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8910 nla_data(attr), nla_len(attr),
8911 nl80211_wowlan_tcp_policy);
8912 if (err)
8913 return err;
8914
8915 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8916 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8917 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8918 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8919 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8920 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8921 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8922 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8923 return -EINVAL;
8924
8925 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008926 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008927 return -EINVAL;
8928
8929 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008930 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008931 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008932 return -EINVAL;
8933
8934 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008935 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008936 return -EINVAL;
8937
8938 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8939 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8940 return -EINVAL;
8941
8942 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8943 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8944
8945 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8946 tokens_size = tokln - sizeof(*tok);
8947
8948 if (!tok->len || tokens_size % tok->len)
8949 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008950 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008951 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008952 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008953 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008954 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008955 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008956 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008957 return -EINVAL;
8958 if (tok->offset + tok->len > data_size)
8959 return -EINVAL;
8960 }
8961
8962 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8963 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008964 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008965 return -EINVAL;
8966 if (seq->len == 0 || seq->len > 4)
8967 return -EINVAL;
8968 if (seq->len + seq->offset > data_size)
8969 return -EINVAL;
8970 }
8971
8972 size = sizeof(*cfg);
8973 size += data_size;
8974 size += wake_size + wake_mask_size;
8975 size += tokens_size;
8976
8977 cfg = kzalloc(size, GFP_KERNEL);
8978 if (!cfg)
8979 return -ENOMEM;
8980 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8981 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8982 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8983 ETH_ALEN);
8984 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8985 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8986 else
8987 port = 0;
8988#ifdef CONFIG_INET
8989 /* allocate a socket and port for it and use it */
8990 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8991 IPPROTO_TCP, &cfg->sock, 1);
8992 if (err) {
8993 kfree(cfg);
8994 return err;
8995 }
8996 if (inet_csk_get_port(cfg->sock->sk, port)) {
8997 sock_release(cfg->sock);
8998 kfree(cfg);
8999 return -EADDRINUSE;
9000 }
9001 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9002#else
9003 if (!port) {
9004 kfree(cfg);
9005 return -EINVAL;
9006 }
9007 cfg->src_port = port;
9008#endif
9009
9010 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9011 cfg->payload_len = data_size;
9012 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9013 memcpy((void *)cfg->payload,
9014 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9015 data_size);
9016 if (seq)
9017 cfg->payload_seq = *seq;
9018 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9019 cfg->wake_len = wake_size;
9020 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9021 memcpy((void *)cfg->wake_data,
9022 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9023 wake_size);
9024 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9025 data_size + wake_size;
9026 memcpy((void *)cfg->wake_mask,
9027 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9028 wake_mask_size);
9029 if (tok) {
9030 cfg->tokens_size = tokens_size;
9031 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9032 }
9033
9034 trig->tcp = cfg;
9035
9036 return 0;
9037}
9038
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009039static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9040 const struct wiphy_wowlan_support *wowlan,
9041 struct nlattr *attr,
9042 struct cfg80211_wowlan *trig)
9043{
9044 struct nlattr **tb;
9045 int err;
9046
9047 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9048 if (!tb)
9049 return -ENOMEM;
9050
9051 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9052 err = -EOPNOTSUPP;
9053 goto out;
9054 }
9055
9056 err = nla_parse(tb, NL80211_ATTR_MAX,
9057 nla_data(attr), nla_len(attr),
9058 nl80211_policy);
9059 if (err)
9060 goto out;
9061
Johannes Bergad2b26a2014-06-12 21:39:05 +02009062 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009063 err = PTR_ERR_OR_ZERO(trig->nd_config);
9064 if (err)
9065 trig->nd_config = NULL;
9066
9067out:
9068 kfree(tb);
9069 return err;
9070}
9071
Johannes Bergff1b6e62011-05-04 15:37:28 +02009072static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9073{
9074 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9075 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009076 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009077 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009078 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009079 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009080 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009081
Johannes Berg964dc9e2013-06-03 17:25:34 +02009082 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009083 return -EOPNOTSUPP;
9084
Johannes Bergae33bd82012-07-12 16:25:02 +02009085 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9086 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009087 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009088 goto set_wakeup;
9089 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009090
9091 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9092 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9093 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9094 nl80211_wowlan_policy);
9095 if (err)
9096 return err;
9097
9098 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9099 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9100 return -EINVAL;
9101 new_triggers.any = true;
9102 }
9103
9104 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9105 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9106 return -EINVAL;
9107 new_triggers.disconnect = true;
9108 }
9109
9110 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9111 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9112 return -EINVAL;
9113 new_triggers.magic_pkt = true;
9114 }
9115
Johannes Berg77dbbb12011-07-13 10:48:55 +02009116 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9117 return -EINVAL;
9118
9119 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9120 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9121 return -EINVAL;
9122 new_triggers.gtk_rekey_failure = true;
9123 }
9124
9125 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9126 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9127 return -EINVAL;
9128 new_triggers.eap_identity_req = true;
9129 }
9130
9131 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9132 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9133 return -EINVAL;
9134 new_triggers.four_way_handshake = true;
9135 }
9136
9137 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9138 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9139 return -EINVAL;
9140 new_triggers.rfkill_release = true;
9141 }
9142
Johannes Bergff1b6e62011-05-04 15:37:28 +02009143 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9144 struct nlattr *pat;
9145 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009146 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009147 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009148
9149 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9150 rem)
9151 n_patterns++;
9152 if (n_patterns > wowlan->n_patterns)
9153 return -EINVAL;
9154
9155 new_triggers.patterns = kcalloc(n_patterns,
9156 sizeof(new_triggers.patterns[0]),
9157 GFP_KERNEL);
9158 if (!new_triggers.patterns)
9159 return -ENOMEM;
9160
9161 new_triggers.n_patterns = n_patterns;
9162 i = 0;
9163
9164 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9165 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009166 u8 *mask_pat;
9167
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009168 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9169 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009170 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009171 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9172 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009173 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009174 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009175 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009176 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009177 goto error;
9178 if (pat_len > wowlan->pattern_max_len ||
9179 pat_len < wowlan->pattern_min_len)
9180 goto error;
9181
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009182 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009183 pkt_offset = 0;
9184 else
9185 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009186 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009187 if (pkt_offset > wowlan->max_pkt_offset)
9188 goto error;
9189 new_triggers.patterns[i].pkt_offset = pkt_offset;
9190
Johannes Berg922bd802014-05-19 17:59:50 +02009191 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9192 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009193 err = -ENOMEM;
9194 goto error;
9195 }
Johannes Berg922bd802014-05-19 17:59:50 +02009196 new_triggers.patterns[i].mask = mask_pat;
9197 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009198 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009199 mask_pat += mask_len;
9200 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009201 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009202 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009203 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009204 pat_len);
9205 i++;
9206 }
9207 }
9208
Johannes Berg2a0e0472013-01-23 22:57:40 +01009209 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
9210 err = nl80211_parse_wowlan_tcp(
9211 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9212 &new_triggers);
9213 if (err)
9214 goto error;
9215 }
9216
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009217 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
9218 err = nl80211_parse_wowlan_nd(
9219 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9220 &new_triggers);
9221 if (err)
9222 goto error;
9223 }
9224
Johannes Bergae33bd82012-07-12 16:25:02 +02009225 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9226 if (!ntrig) {
9227 err = -ENOMEM;
9228 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009229 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009230 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009231 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009232
Johannes Bergae33bd82012-07-12 16:25:02 +02009233 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009234 if (rdev->ops->set_wakeup &&
9235 prev_enabled != !!rdev->wiphy.wowlan_config)
9236 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009237
Johannes Bergff1b6e62011-05-04 15:37:28 +02009238 return 0;
9239 error:
9240 for (i = 0; i < new_triggers.n_patterns; i++)
9241 kfree(new_triggers.patterns[i].mask);
9242 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009243 if (new_triggers.tcp && new_triggers.tcp->sock)
9244 sock_release(new_triggers.tcp->sock);
9245 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009246 return err;
9247}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009248#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009249
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009250static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9251 struct cfg80211_registered_device *rdev)
9252{
9253 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9254 int i, j, pat_len;
9255 struct cfg80211_coalesce_rules *rule;
9256
9257 if (!rdev->coalesce->n_rules)
9258 return 0;
9259
9260 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9261 if (!nl_rules)
9262 return -ENOBUFS;
9263
9264 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9265 nl_rule = nla_nest_start(msg, i + 1);
9266 if (!nl_rule)
9267 return -ENOBUFS;
9268
9269 rule = &rdev->coalesce->rules[i];
9270 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9271 rule->delay))
9272 return -ENOBUFS;
9273
9274 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9275 rule->condition))
9276 return -ENOBUFS;
9277
9278 nl_pats = nla_nest_start(msg,
9279 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9280 if (!nl_pats)
9281 return -ENOBUFS;
9282
9283 for (j = 0; j < rule->n_patterns; j++) {
9284 nl_pat = nla_nest_start(msg, j + 1);
9285 if (!nl_pat)
9286 return -ENOBUFS;
9287 pat_len = rule->patterns[j].pattern_len;
9288 if (nla_put(msg, NL80211_PKTPAT_MASK,
9289 DIV_ROUND_UP(pat_len, 8),
9290 rule->patterns[j].mask) ||
9291 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9292 rule->patterns[j].pattern) ||
9293 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9294 rule->patterns[j].pkt_offset))
9295 return -ENOBUFS;
9296 nla_nest_end(msg, nl_pat);
9297 }
9298 nla_nest_end(msg, nl_pats);
9299 nla_nest_end(msg, nl_rule);
9300 }
9301 nla_nest_end(msg, nl_rules);
9302
9303 return 0;
9304}
9305
9306static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9307{
9308 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9309 struct sk_buff *msg;
9310 void *hdr;
9311
9312 if (!rdev->wiphy.coalesce)
9313 return -EOPNOTSUPP;
9314
9315 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9316 if (!msg)
9317 return -ENOMEM;
9318
9319 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9320 NL80211_CMD_GET_COALESCE);
9321 if (!hdr)
9322 goto nla_put_failure;
9323
9324 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9325 goto nla_put_failure;
9326
9327 genlmsg_end(msg, hdr);
9328 return genlmsg_reply(msg, info);
9329
9330nla_put_failure:
9331 nlmsg_free(msg);
9332 return -ENOBUFS;
9333}
9334
9335void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9336{
9337 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9338 int i, j;
9339 struct cfg80211_coalesce_rules *rule;
9340
9341 if (!coalesce)
9342 return;
9343
9344 for (i = 0; i < coalesce->n_rules; i++) {
9345 rule = &coalesce->rules[i];
9346 for (j = 0; j < rule->n_patterns; j++)
9347 kfree(rule->patterns[j].mask);
9348 kfree(rule->patterns);
9349 }
9350 kfree(coalesce->rules);
9351 kfree(coalesce);
9352 rdev->coalesce = NULL;
9353}
9354
9355static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9356 struct nlattr *rule,
9357 struct cfg80211_coalesce_rules *new_rule)
9358{
9359 int err, i;
9360 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9361 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9362 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9363 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9364
9365 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9366 nla_len(rule), nl80211_coalesce_policy);
9367 if (err)
9368 return err;
9369
9370 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9371 new_rule->delay =
9372 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9373 if (new_rule->delay > coalesce->max_delay)
9374 return -EINVAL;
9375
9376 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9377 new_rule->condition =
9378 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9379 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9380 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9381 return -EINVAL;
9382
9383 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9384 return -EINVAL;
9385
9386 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9387 rem)
9388 n_patterns++;
9389 if (n_patterns > coalesce->n_patterns)
9390 return -EINVAL;
9391
9392 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9393 GFP_KERNEL);
9394 if (!new_rule->patterns)
9395 return -ENOMEM;
9396
9397 new_rule->n_patterns = n_patterns;
9398 i = 0;
9399
9400 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9401 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009402 u8 *mask_pat;
9403
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009404 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9405 nla_len(pat), NULL);
9406 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9407 !pat_tb[NL80211_PKTPAT_PATTERN])
9408 return -EINVAL;
9409 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9410 mask_len = DIV_ROUND_UP(pat_len, 8);
9411 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9412 return -EINVAL;
9413 if (pat_len > coalesce->pattern_max_len ||
9414 pat_len < coalesce->pattern_min_len)
9415 return -EINVAL;
9416
9417 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9418 pkt_offset = 0;
9419 else
9420 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9421 if (pkt_offset > coalesce->max_pkt_offset)
9422 return -EINVAL;
9423 new_rule->patterns[i].pkt_offset = pkt_offset;
9424
Johannes Berg922bd802014-05-19 17:59:50 +02009425 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9426 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009427 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009428
9429 new_rule->patterns[i].mask = mask_pat;
9430 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9431 mask_len);
9432
9433 mask_pat += mask_len;
9434 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009435 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009436 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9437 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009438 i++;
9439 }
9440
9441 return 0;
9442}
9443
9444static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9445{
9446 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9447 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9448 struct cfg80211_coalesce new_coalesce = {};
9449 struct cfg80211_coalesce *n_coalesce;
9450 int err, rem_rule, n_rules = 0, i, j;
9451 struct nlattr *rule;
9452 struct cfg80211_coalesce_rules *tmp_rule;
9453
9454 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9455 return -EOPNOTSUPP;
9456
9457 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9458 cfg80211_rdev_free_coalesce(rdev);
9459 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9460 return 0;
9461 }
9462
9463 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9464 rem_rule)
9465 n_rules++;
9466 if (n_rules > coalesce->n_rules)
9467 return -EINVAL;
9468
9469 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9470 GFP_KERNEL);
9471 if (!new_coalesce.rules)
9472 return -ENOMEM;
9473
9474 new_coalesce.n_rules = n_rules;
9475 i = 0;
9476
9477 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9478 rem_rule) {
9479 err = nl80211_parse_coalesce_rule(rdev, rule,
9480 &new_coalesce.rules[i]);
9481 if (err)
9482 goto error;
9483
9484 i++;
9485 }
9486
9487 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9488 if (err)
9489 goto error;
9490
9491 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9492 if (!n_coalesce) {
9493 err = -ENOMEM;
9494 goto error;
9495 }
9496 cfg80211_rdev_free_coalesce(rdev);
9497 rdev->coalesce = n_coalesce;
9498
9499 return 0;
9500error:
9501 for (i = 0; i < new_coalesce.n_rules; i++) {
9502 tmp_rule = &new_coalesce.rules[i];
9503 for (j = 0; j < tmp_rule->n_patterns; j++)
9504 kfree(tmp_rule->patterns[j].mask);
9505 kfree(tmp_rule->patterns);
9506 }
9507 kfree(new_coalesce.rules);
9508
9509 return err;
9510}
9511
Johannes Berge5497d72011-07-05 16:35:40 +02009512static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9513{
9514 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9515 struct net_device *dev = info->user_ptr[1];
9516 struct wireless_dev *wdev = dev->ieee80211_ptr;
9517 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9518 struct cfg80211_gtk_rekey_data rekey_data;
9519 int err;
9520
9521 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9522 return -EINVAL;
9523
9524 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9525 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9526 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9527 nl80211_rekey_policy);
9528 if (err)
9529 return err;
9530
9531 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9532 return -ERANGE;
9533 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9534 return -ERANGE;
9535 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9536 return -ERANGE;
9537
Johannes Berg78f686c2014-09-10 22:28:06 +03009538 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9539 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9540 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009541
9542 wdev_lock(wdev);
9543 if (!wdev->current_bss) {
9544 err = -ENOTCONN;
9545 goto out;
9546 }
9547
9548 if (!rdev->ops->set_rekey_data) {
9549 err = -EOPNOTSUPP;
9550 goto out;
9551 }
9552
Hila Gonene35e4d22012-06-27 17:19:42 +03009553 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009554 out:
9555 wdev_unlock(wdev);
9556 return err;
9557}
9558
Johannes Berg28946da2011-11-04 11:18:12 +01009559static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9560 struct genl_info *info)
9561{
9562 struct net_device *dev = info->user_ptr[1];
9563 struct wireless_dev *wdev = dev->ieee80211_ptr;
9564
9565 if (wdev->iftype != NL80211_IFTYPE_AP &&
9566 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9567 return -EINVAL;
9568
Eric W. Biederman15e47302012-09-07 20:12:54 +00009569 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009570 return -EBUSY;
9571
Eric W. Biederman15e47302012-09-07 20:12:54 +00009572 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009573 return 0;
9574}
9575
Johannes Berg7f6cf312011-11-04 11:18:15 +01009576static int nl80211_probe_client(struct sk_buff *skb,
9577 struct genl_info *info)
9578{
9579 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9580 struct net_device *dev = info->user_ptr[1];
9581 struct wireless_dev *wdev = dev->ieee80211_ptr;
9582 struct sk_buff *msg;
9583 void *hdr;
9584 const u8 *addr;
9585 u64 cookie;
9586 int err;
9587
9588 if (wdev->iftype != NL80211_IFTYPE_AP &&
9589 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9590 return -EOPNOTSUPP;
9591
9592 if (!info->attrs[NL80211_ATTR_MAC])
9593 return -EINVAL;
9594
9595 if (!rdev->ops->probe_client)
9596 return -EOPNOTSUPP;
9597
9598 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9599 if (!msg)
9600 return -ENOMEM;
9601
Eric W. Biederman15e47302012-09-07 20:12:54 +00009602 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009603 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009604 if (!hdr) {
9605 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009606 goto free_msg;
9607 }
9608
9609 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9610
Hila Gonene35e4d22012-06-27 17:19:42 +03009611 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009612 if (err)
9613 goto free_msg;
9614
David S. Miller9360ffd2012-03-29 04:41:26 -04009615 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9616 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009617
9618 genlmsg_end(msg, hdr);
9619
9620 return genlmsg_reply(msg, info);
9621
9622 nla_put_failure:
9623 err = -ENOBUFS;
9624 free_msg:
9625 nlmsg_free(msg);
9626 return err;
9627}
9628
Johannes Berg5e760232011-11-04 11:18:17 +01009629static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9630{
9631 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009632 struct cfg80211_beacon_registration *reg, *nreg;
9633 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009634
9635 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9636 return -EOPNOTSUPP;
9637
Ben Greear37c73b52012-10-26 14:49:25 -07009638 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9639 if (!nreg)
9640 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009641
Ben Greear37c73b52012-10-26 14:49:25 -07009642 /* First, check if already registered. */
9643 spin_lock_bh(&rdev->beacon_registrations_lock);
9644 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9645 if (reg->nlportid == info->snd_portid) {
9646 rv = -EALREADY;
9647 goto out_err;
9648 }
9649 }
9650 /* Add it to the list */
9651 nreg->nlportid = info->snd_portid;
9652 list_add(&nreg->list, &rdev->beacon_registrations);
9653
9654 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009655
9656 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009657out_err:
9658 spin_unlock_bh(&rdev->beacon_registrations_lock);
9659 kfree(nreg);
9660 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009661}
9662
Johannes Berg98104fde2012-06-16 00:19:54 +02009663static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9664{
9665 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9666 struct wireless_dev *wdev = info->user_ptr[1];
9667 int err;
9668
9669 if (!rdev->ops->start_p2p_device)
9670 return -EOPNOTSUPP;
9671
9672 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9673 return -EOPNOTSUPP;
9674
9675 if (wdev->p2p_started)
9676 return 0;
9677
Luciano Coelhob6a55012014-02-27 11:07:21 +02009678 if (rfkill_blocked(rdev->rfkill))
9679 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009680
Johannes Bergeeb126e2012-10-23 15:16:50 +02009681 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009682 if (err)
9683 return err;
9684
9685 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009686 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009687
9688 return 0;
9689}
9690
9691static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9692{
9693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9694 struct wireless_dev *wdev = info->user_ptr[1];
9695
9696 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9697 return -EOPNOTSUPP;
9698
9699 if (!rdev->ops->stop_p2p_device)
9700 return -EOPNOTSUPP;
9701
Johannes Bergf9f47522013-03-19 15:04:07 +01009702 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009703
9704 return 0;
9705}
9706
Johannes Berg3713b4e2013-02-14 16:19:38 +01009707static int nl80211_get_protocol_features(struct sk_buff *skb,
9708 struct genl_info *info)
9709{
9710 void *hdr;
9711 struct sk_buff *msg;
9712
9713 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9714 if (!msg)
9715 return -ENOMEM;
9716
9717 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9718 NL80211_CMD_GET_PROTOCOL_FEATURES);
9719 if (!hdr)
9720 goto nla_put_failure;
9721
9722 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9723 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9724 goto nla_put_failure;
9725
9726 genlmsg_end(msg, hdr);
9727 return genlmsg_reply(msg, info);
9728
9729 nla_put_failure:
9730 kfree_skb(msg);
9731 return -ENOBUFS;
9732}
9733
Jouni Malinen355199e2013-02-27 17:14:27 +02009734static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9735{
9736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9737 struct cfg80211_update_ft_ies_params ft_params;
9738 struct net_device *dev = info->user_ptr[1];
9739
9740 if (!rdev->ops->update_ft_ies)
9741 return -EOPNOTSUPP;
9742
9743 if (!info->attrs[NL80211_ATTR_MDID] ||
9744 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9745 return -EINVAL;
9746
9747 memset(&ft_params, 0, sizeof(ft_params));
9748 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9749 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9750 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9751
9752 return rdev_update_ft_ies(rdev, dev, &ft_params);
9753}
9754
Arend van Spriel5de17982013-04-18 15:49:00 +02009755static int nl80211_crit_protocol_start(struct sk_buff *skb,
9756 struct genl_info *info)
9757{
9758 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9759 struct wireless_dev *wdev = info->user_ptr[1];
9760 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9761 u16 duration;
9762 int ret;
9763
9764 if (!rdev->ops->crit_proto_start)
9765 return -EOPNOTSUPP;
9766
9767 if (WARN_ON(!rdev->ops->crit_proto_stop))
9768 return -EINVAL;
9769
9770 if (rdev->crit_proto_nlportid)
9771 return -EBUSY;
9772
9773 /* determine protocol if provided */
9774 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9775 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9776
9777 if (proto >= NUM_NL80211_CRIT_PROTO)
9778 return -EINVAL;
9779
9780 /* timeout must be provided */
9781 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9782 return -EINVAL;
9783
9784 duration =
9785 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9786
9787 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9788 return -ERANGE;
9789
9790 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9791 if (!ret)
9792 rdev->crit_proto_nlportid = info->snd_portid;
9793
9794 return ret;
9795}
9796
9797static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9798 struct genl_info *info)
9799{
9800 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9801 struct wireless_dev *wdev = info->user_ptr[1];
9802
9803 if (!rdev->ops->crit_proto_stop)
9804 return -EOPNOTSUPP;
9805
9806 if (rdev->crit_proto_nlportid) {
9807 rdev->crit_proto_nlportid = 0;
9808 rdev_crit_proto_stop(rdev, wdev);
9809 }
9810 return 0;
9811}
9812
Johannes Bergad7e7182013-11-13 13:37:47 +01009813static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9814{
9815 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9816 struct wireless_dev *wdev =
9817 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9818 int i, err;
9819 u32 vid, subcmd;
9820
9821 if (!rdev->wiphy.vendor_commands)
9822 return -EOPNOTSUPP;
9823
9824 if (IS_ERR(wdev)) {
9825 err = PTR_ERR(wdev);
9826 if (err != -EINVAL)
9827 return err;
9828 wdev = NULL;
9829 } else if (wdev->wiphy != &rdev->wiphy) {
9830 return -EINVAL;
9831 }
9832
9833 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9834 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9835 return -EINVAL;
9836
9837 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9838 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9839 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9840 const struct wiphy_vendor_command *vcmd;
9841 void *data = NULL;
9842 int len = 0;
9843
9844 vcmd = &rdev->wiphy.vendor_commands[i];
9845
9846 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9847 continue;
9848
9849 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9850 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9851 if (!wdev)
9852 return -EINVAL;
9853 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9854 !wdev->netdev)
9855 return -EINVAL;
9856
9857 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9858 if (wdev->netdev &&
9859 !netif_running(wdev->netdev))
9860 return -ENETDOWN;
9861 if (!wdev->netdev && !wdev->p2p_started)
9862 return -ENETDOWN;
9863 }
9864 } else {
9865 wdev = NULL;
9866 }
9867
9868 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9869 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9870 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9871 }
9872
9873 rdev->cur_cmd_info = info;
9874 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9875 data, len);
9876 rdev->cur_cmd_info = NULL;
9877 return err;
9878 }
9879
9880 return -EOPNOTSUPP;
9881}
9882
9883struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9884 enum nl80211_commands cmd,
9885 enum nl80211_attrs attr,
9886 int approxlen)
9887{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009888 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009889
9890 if (WARN_ON(!rdev->cur_cmd_info))
9891 return NULL;
9892
9893 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9894 rdev->cur_cmd_info->snd_portid,
9895 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009896 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009897}
9898EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9899
9900int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9901{
9902 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9903 void *hdr = ((void **)skb->cb)[1];
9904 struct nlattr *data = ((void **)skb->cb)[2];
9905
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009906 /* clear CB data for netlink core to own from now on */
9907 memset(skb->cb, 0, sizeof(skb->cb));
9908
Johannes Bergad7e7182013-11-13 13:37:47 +01009909 if (WARN_ON(!rdev->cur_cmd_info)) {
9910 kfree_skb(skb);
9911 return -EINVAL;
9912 }
9913
9914 nla_nest_end(skb, data);
9915 genlmsg_end(skb, hdr);
9916 return genlmsg_reply(skb, rdev->cur_cmd_info);
9917}
9918EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9919
9920
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009921static int nl80211_set_qos_map(struct sk_buff *skb,
9922 struct genl_info *info)
9923{
9924 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9925 struct cfg80211_qos_map *qos_map = NULL;
9926 struct net_device *dev = info->user_ptr[1];
9927 u8 *pos, len, num_des, des_len, des;
9928 int ret;
9929
9930 if (!rdev->ops->set_qos_map)
9931 return -EOPNOTSUPP;
9932
9933 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9934 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9935 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9936
9937 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9938 len > IEEE80211_QOS_MAP_LEN_MAX)
9939 return -EINVAL;
9940
9941 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9942 if (!qos_map)
9943 return -ENOMEM;
9944
9945 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9946 if (num_des) {
9947 des_len = num_des *
9948 sizeof(struct cfg80211_dscp_exception);
9949 memcpy(qos_map->dscp_exception, pos, des_len);
9950 qos_map->num_des = num_des;
9951 for (des = 0; des < num_des; des++) {
9952 if (qos_map->dscp_exception[des].up > 7) {
9953 kfree(qos_map);
9954 return -EINVAL;
9955 }
9956 }
9957 pos += des_len;
9958 }
9959 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9960 }
9961
9962 wdev_lock(dev->ieee80211_ptr);
9963 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9964 if (!ret)
9965 ret = rdev_set_qos_map(rdev, dev, qos_map);
9966 wdev_unlock(dev->ieee80211_ptr);
9967
9968 kfree(qos_map);
9969 return ret;
9970}
9971
Johannes Berg960d01a2014-09-09 22:55:35 +03009972static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9973{
9974 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9975 struct net_device *dev = info->user_ptr[1];
9976 struct wireless_dev *wdev = dev->ieee80211_ptr;
9977 const u8 *peer;
9978 u8 tsid, up;
9979 u16 admitted_time = 0;
9980 int err;
9981
Johannes Berg723e73a2014-10-22 09:25:06 +02009982 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009983 return -EOPNOTSUPP;
9984
9985 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9986 !info->attrs[NL80211_ATTR_USER_PRIO])
9987 return -EINVAL;
9988
9989 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9990 if (tsid >= IEEE80211_NUM_TIDS)
9991 return -EINVAL;
9992
9993 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9994 if (up >= IEEE80211_NUM_UPS)
9995 return -EINVAL;
9996
9997 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009998 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009999 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010000 * need more attributes for that (e.g. BA session requirement);
10001 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010002 */
10003 return -EINVAL;
10004 }
10005
10006 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10007
10008 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10009 admitted_time =
10010 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10011 if (!admitted_time)
10012 return -EINVAL;
10013 }
10014
10015 wdev_lock(wdev);
10016 switch (wdev->iftype) {
10017 case NL80211_IFTYPE_STATION:
10018 case NL80211_IFTYPE_P2P_CLIENT:
10019 if (wdev->current_bss)
10020 break;
10021 err = -ENOTCONN;
10022 goto out;
10023 default:
10024 err = -EOPNOTSUPP;
10025 goto out;
10026 }
10027
10028 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10029
10030 out:
10031 wdev_unlock(wdev);
10032 return err;
10033}
10034
10035static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10036{
10037 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10038 struct net_device *dev = info->user_ptr[1];
10039 struct wireless_dev *wdev = dev->ieee80211_ptr;
10040 const u8 *peer;
10041 u8 tsid;
10042 int err;
10043
10044 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10045 return -EINVAL;
10046
10047 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10048 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10049
10050 wdev_lock(wdev);
10051 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10052 wdev_unlock(wdev);
10053
10054 return err;
10055}
10056
Arik Nemtsov1057d352014-11-19 12:54:26 +020010057static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10058 struct genl_info *info)
10059{
10060 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10061 struct net_device *dev = info->user_ptr[1];
10062 struct wireless_dev *wdev = dev->ieee80211_ptr;
10063 struct cfg80211_chan_def chandef = {};
10064 const u8 *addr;
10065 u8 oper_class;
10066 int err;
10067
10068 if (!rdev->ops->tdls_channel_switch ||
10069 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10070 return -EOPNOTSUPP;
10071
10072 switch (dev->ieee80211_ptr->iftype) {
10073 case NL80211_IFTYPE_STATION:
10074 case NL80211_IFTYPE_P2P_CLIENT:
10075 break;
10076 default:
10077 return -EOPNOTSUPP;
10078 }
10079
10080 if (!info->attrs[NL80211_ATTR_MAC] ||
10081 !info->attrs[NL80211_ATTR_OPER_CLASS])
10082 return -EINVAL;
10083
10084 err = nl80211_parse_chandef(rdev, info, &chandef);
10085 if (err)
10086 return err;
10087
10088 /*
10089 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10090 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10091 * specification is not defined for them.
10092 */
10093 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10094 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10095 chandef.width != NL80211_CHAN_WIDTH_20)
10096 return -EINVAL;
10097
10098 /* we will be active on the TDLS link */
10099 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
10100 return -EINVAL;
10101
10102 /* don't allow switching to DFS channels */
10103 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10104 return -EINVAL;
10105
10106 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10107 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10108
10109 wdev_lock(wdev);
10110 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10111 wdev_unlock(wdev);
10112
10113 return err;
10114}
10115
10116static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10117 struct genl_info *info)
10118{
10119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10120 struct net_device *dev = info->user_ptr[1];
10121 struct wireless_dev *wdev = dev->ieee80211_ptr;
10122 const u8 *addr;
10123
10124 if (!rdev->ops->tdls_channel_switch ||
10125 !rdev->ops->tdls_cancel_channel_switch ||
10126 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10127 return -EOPNOTSUPP;
10128
10129 switch (dev->ieee80211_ptr->iftype) {
10130 case NL80211_IFTYPE_STATION:
10131 case NL80211_IFTYPE_P2P_CLIENT:
10132 break;
10133 default:
10134 return -EOPNOTSUPP;
10135 }
10136
10137 if (!info->attrs[NL80211_ATTR_MAC])
10138 return -EINVAL;
10139
10140 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10141
10142 wdev_lock(wdev);
10143 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10144 wdev_unlock(wdev);
10145
10146 return 0;
10147}
10148
Johannes Berg4c476992010-10-04 21:36:35 +020010149#define NL80211_FLAG_NEED_WIPHY 0x01
10150#define NL80211_FLAG_NEED_NETDEV 0x02
10151#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010152#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10153#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10154 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010155#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010156/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010157#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10158 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010159#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010160
Johannes Bergf84f7712013-11-14 17:14:45 +010010161static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010162 struct genl_info *info)
10163{
10164 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010165 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010166 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010167 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10168
10169 if (rtnl)
10170 rtnl_lock();
10171
10172 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010173 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010174 if (IS_ERR(rdev)) {
10175 if (rtnl)
10176 rtnl_unlock();
10177 return PTR_ERR(rdev);
10178 }
10179 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010180 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10181 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010182 ASSERT_RTNL();
10183
Johannes Berg89a54e42012-06-15 14:33:17 +020010184 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10185 info->attrs);
10186 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010187 if (rtnl)
10188 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010189 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010190 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010191
Johannes Berg89a54e42012-06-15 14:33:17 +020010192 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010193 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010194
Johannes Berg1bf614e2012-06-15 15:23:36 +020010195 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10196 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010197 if (rtnl)
10198 rtnl_unlock();
10199 return -EINVAL;
10200 }
10201
10202 info->user_ptr[1] = dev;
10203 } else {
10204 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010205 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010206
Johannes Berg1bf614e2012-06-15 15:23:36 +020010207 if (dev) {
10208 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10209 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010210 if (rtnl)
10211 rtnl_unlock();
10212 return -ENETDOWN;
10213 }
10214
10215 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010216 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10217 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010218 if (rtnl)
10219 rtnl_unlock();
10220 return -ENETDOWN;
10221 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010222 }
10223
Johannes Berg4c476992010-10-04 21:36:35 +020010224 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010225 }
10226
10227 return 0;
10228}
10229
Johannes Bergf84f7712013-11-14 17:14:45 +010010230static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010231 struct genl_info *info)
10232{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010233 if (info->user_ptr[1]) {
10234 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10235 struct wireless_dev *wdev = info->user_ptr[1];
10236
10237 if (wdev->netdev)
10238 dev_put(wdev->netdev);
10239 } else {
10240 dev_put(info->user_ptr[1]);
10241 }
10242 }
Johannes Berg5393b912014-09-10 15:00:16 +030010243
Johannes Berg4c476992010-10-04 21:36:35 +020010244 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10245 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010246
10247 /* If needed, clear the netlink message payload from the SKB
10248 * as it might contain key data that shouldn't stick around on
10249 * the heap after the SKB is freed. The netlink message header
10250 * is still needed for further processing, so leave it intact.
10251 */
10252 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10253 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10254
10255 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10256 }
Johannes Berg4c476992010-10-04 21:36:35 +020010257}
10258
Johannes Berg4534de82013-11-14 17:14:46 +010010259static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010260 {
10261 .cmd = NL80211_CMD_GET_WIPHY,
10262 .doit = nl80211_get_wiphy,
10263 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010264 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010265 .policy = nl80211_policy,
10266 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010267 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10268 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010269 },
10270 {
10271 .cmd = NL80211_CMD_SET_WIPHY,
10272 .doit = nl80211_set_wiphy,
10273 .policy = nl80211_policy,
10274 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010275 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010276 },
10277 {
10278 .cmd = NL80211_CMD_GET_INTERFACE,
10279 .doit = nl80211_get_interface,
10280 .dumpit = nl80211_dump_interface,
10281 .policy = nl80211_policy,
10282 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010283 .internal_flags = NL80211_FLAG_NEED_WDEV |
10284 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010285 },
10286 {
10287 .cmd = NL80211_CMD_SET_INTERFACE,
10288 .doit = nl80211_set_interface,
10289 .policy = nl80211_policy,
10290 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010291 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10292 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010293 },
10294 {
10295 .cmd = NL80211_CMD_NEW_INTERFACE,
10296 .doit = nl80211_new_interface,
10297 .policy = nl80211_policy,
10298 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010299 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10300 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010301 },
10302 {
10303 .cmd = NL80211_CMD_DEL_INTERFACE,
10304 .doit = nl80211_del_interface,
10305 .policy = nl80211_policy,
10306 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010307 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010308 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010309 },
Johannes Berg41ade002007-12-19 02:03:29 +010010310 {
10311 .cmd = NL80211_CMD_GET_KEY,
10312 .doit = nl80211_get_key,
10313 .policy = nl80211_policy,
10314 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010315 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010316 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010317 },
10318 {
10319 .cmd = NL80211_CMD_SET_KEY,
10320 .doit = nl80211_set_key,
10321 .policy = nl80211_policy,
10322 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010323 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010324 NL80211_FLAG_NEED_RTNL |
10325 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010326 },
10327 {
10328 .cmd = NL80211_CMD_NEW_KEY,
10329 .doit = nl80211_new_key,
10330 .policy = nl80211_policy,
10331 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010332 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010333 NL80211_FLAG_NEED_RTNL |
10334 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010335 },
10336 {
10337 .cmd = NL80211_CMD_DEL_KEY,
10338 .doit = nl80211_del_key,
10339 .policy = nl80211_policy,
10340 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010341 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010342 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010343 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010344 {
10345 .cmd = NL80211_CMD_SET_BEACON,
10346 .policy = nl80211_policy,
10347 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010348 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010349 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010350 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010351 },
10352 {
Johannes Berg88600202012-02-13 15:17:18 +010010353 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010354 .policy = nl80211_policy,
10355 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010356 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010357 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010358 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010359 },
10360 {
Johannes Berg88600202012-02-13 15:17:18 +010010361 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010362 .policy = nl80211_policy,
10363 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010364 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010365 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010366 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010367 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010368 {
10369 .cmd = NL80211_CMD_GET_STATION,
10370 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010371 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010372 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010373 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10374 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010375 },
10376 {
10377 .cmd = NL80211_CMD_SET_STATION,
10378 .doit = nl80211_set_station,
10379 .policy = nl80211_policy,
10380 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010381 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010382 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010383 },
10384 {
10385 .cmd = NL80211_CMD_NEW_STATION,
10386 .doit = nl80211_new_station,
10387 .policy = nl80211_policy,
10388 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010389 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010390 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010391 },
10392 {
10393 .cmd = NL80211_CMD_DEL_STATION,
10394 .doit = nl80211_del_station,
10395 .policy = nl80211_policy,
10396 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010397 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010398 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010399 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010400 {
10401 .cmd = NL80211_CMD_GET_MPATH,
10402 .doit = nl80211_get_mpath,
10403 .dumpit = nl80211_dump_mpath,
10404 .policy = nl80211_policy,
10405 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010406 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010407 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010408 },
10409 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010410 .cmd = NL80211_CMD_GET_MPP,
10411 .doit = nl80211_get_mpp,
10412 .dumpit = nl80211_dump_mpp,
10413 .policy = nl80211_policy,
10414 .flags = GENL_ADMIN_PERM,
10415 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10416 NL80211_FLAG_NEED_RTNL,
10417 },
10418 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010419 .cmd = NL80211_CMD_SET_MPATH,
10420 .doit = nl80211_set_mpath,
10421 .policy = nl80211_policy,
10422 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010423 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010424 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010425 },
10426 {
10427 .cmd = NL80211_CMD_NEW_MPATH,
10428 .doit = nl80211_new_mpath,
10429 .policy = nl80211_policy,
10430 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010431 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010432 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010433 },
10434 {
10435 .cmd = NL80211_CMD_DEL_MPATH,
10436 .doit = nl80211_del_mpath,
10437 .policy = nl80211_policy,
10438 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010439 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010440 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010441 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010442 {
10443 .cmd = NL80211_CMD_SET_BSS,
10444 .doit = nl80211_set_bss,
10445 .policy = nl80211_policy,
10446 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010447 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010448 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010449 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010450 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010451 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010452 .doit = nl80211_get_reg_do,
10453 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010454 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010455 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010456 /* can be retrieved by unprivileged users */
10457 },
10458 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010459 .cmd = NL80211_CMD_SET_REG,
10460 .doit = nl80211_set_reg,
10461 .policy = nl80211_policy,
10462 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010463 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010464 },
10465 {
10466 .cmd = NL80211_CMD_REQ_SET_REG,
10467 .doit = nl80211_req_set_reg,
10468 .policy = nl80211_policy,
10469 .flags = GENL_ADMIN_PERM,
10470 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010471 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010472 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10473 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010474 .policy = nl80211_policy,
10475 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010476 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010477 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010478 },
10479 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010480 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10481 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010482 .policy = nl80211_policy,
10483 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010484 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010485 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010486 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010487 {
Johannes Berg2a519312009-02-10 21:25:55 +010010488 .cmd = NL80211_CMD_TRIGGER_SCAN,
10489 .doit = nl80211_trigger_scan,
10490 .policy = nl80211_policy,
10491 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010492 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010493 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010494 },
10495 {
10496 .cmd = NL80211_CMD_GET_SCAN,
10497 .policy = nl80211_policy,
10498 .dumpit = nl80211_dump_scan,
10499 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010500 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010501 .cmd = NL80211_CMD_START_SCHED_SCAN,
10502 .doit = nl80211_start_sched_scan,
10503 .policy = nl80211_policy,
10504 .flags = GENL_ADMIN_PERM,
10505 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10506 NL80211_FLAG_NEED_RTNL,
10507 },
10508 {
10509 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10510 .doit = nl80211_stop_sched_scan,
10511 .policy = nl80211_policy,
10512 .flags = GENL_ADMIN_PERM,
10513 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10514 NL80211_FLAG_NEED_RTNL,
10515 },
10516 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010517 .cmd = NL80211_CMD_AUTHENTICATE,
10518 .doit = nl80211_authenticate,
10519 .policy = nl80211_policy,
10520 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010521 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010522 NL80211_FLAG_NEED_RTNL |
10523 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010524 },
10525 {
10526 .cmd = NL80211_CMD_ASSOCIATE,
10527 .doit = nl80211_associate,
10528 .policy = nl80211_policy,
10529 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010530 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010531 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010532 },
10533 {
10534 .cmd = NL80211_CMD_DEAUTHENTICATE,
10535 .doit = nl80211_deauthenticate,
10536 .policy = nl80211_policy,
10537 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010539 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010540 },
10541 {
10542 .cmd = NL80211_CMD_DISASSOCIATE,
10543 .doit = nl80211_disassociate,
10544 .policy = nl80211_policy,
10545 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010547 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010548 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010549 {
10550 .cmd = NL80211_CMD_JOIN_IBSS,
10551 .doit = nl80211_join_ibss,
10552 .policy = nl80211_policy,
10553 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010555 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010556 },
10557 {
10558 .cmd = NL80211_CMD_LEAVE_IBSS,
10559 .doit = nl80211_leave_ibss,
10560 .policy = nl80211_policy,
10561 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010562 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010563 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010564 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010565#ifdef CONFIG_NL80211_TESTMODE
10566 {
10567 .cmd = NL80211_CMD_TESTMODE,
10568 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010569 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010570 .policy = nl80211_policy,
10571 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010572 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10573 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010574 },
10575#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010576 {
10577 .cmd = NL80211_CMD_CONNECT,
10578 .doit = nl80211_connect,
10579 .policy = nl80211_policy,
10580 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010581 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010582 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010583 },
10584 {
10585 .cmd = NL80211_CMD_DISCONNECT,
10586 .doit = nl80211_disconnect,
10587 .policy = nl80211_policy,
10588 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010590 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010591 },
Johannes Berg463d0182009-07-14 00:33:35 +020010592 {
10593 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10594 .doit = nl80211_wiphy_netns,
10595 .policy = nl80211_policy,
10596 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010597 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10598 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010599 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010600 {
10601 .cmd = NL80211_CMD_GET_SURVEY,
10602 .policy = nl80211_policy,
10603 .dumpit = nl80211_dump_survey,
10604 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010605 {
10606 .cmd = NL80211_CMD_SET_PMKSA,
10607 .doit = nl80211_setdel_pmksa,
10608 .policy = nl80211_policy,
10609 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010610 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010611 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010612 },
10613 {
10614 .cmd = NL80211_CMD_DEL_PMKSA,
10615 .doit = nl80211_setdel_pmksa,
10616 .policy = nl80211_policy,
10617 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010618 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010619 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010620 },
10621 {
10622 .cmd = NL80211_CMD_FLUSH_PMKSA,
10623 .doit = nl80211_flush_pmksa,
10624 .policy = nl80211_policy,
10625 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010626 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010627 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010628 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010629 {
10630 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10631 .doit = nl80211_remain_on_channel,
10632 .policy = nl80211_policy,
10633 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010634 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010635 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010636 },
10637 {
10638 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10639 .doit = nl80211_cancel_remain_on_channel,
10640 .policy = nl80211_policy,
10641 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010642 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010643 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010644 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010645 {
10646 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10647 .doit = nl80211_set_tx_bitrate_mask,
10648 .policy = nl80211_policy,
10649 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010650 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10651 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010652 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010653 {
Johannes Berg2e161f782010-08-12 15:38:38 +020010654 .cmd = NL80211_CMD_REGISTER_FRAME,
10655 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010656 .policy = nl80211_policy,
10657 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010658 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010659 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010660 },
10661 {
Johannes Berg2e161f782010-08-12 15:38:38 +020010662 .cmd = NL80211_CMD_FRAME,
10663 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010664 .policy = nl80211_policy,
10665 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010666 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010667 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010668 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010669 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010670 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10671 .doit = nl80211_tx_mgmt_cancel_wait,
10672 .policy = nl80211_policy,
10673 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010674 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010675 NL80211_FLAG_NEED_RTNL,
10676 },
10677 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010678 .cmd = NL80211_CMD_SET_POWER_SAVE,
10679 .doit = nl80211_set_power_save,
10680 .policy = nl80211_policy,
10681 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010682 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10683 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010684 },
10685 {
10686 .cmd = NL80211_CMD_GET_POWER_SAVE,
10687 .doit = nl80211_get_power_save,
10688 .policy = nl80211_policy,
10689 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010690 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10691 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010692 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010693 {
10694 .cmd = NL80211_CMD_SET_CQM,
10695 .doit = nl80211_set_cqm,
10696 .policy = nl80211_policy,
10697 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010698 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10699 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010700 },
Johannes Bergf444de02010-05-05 15:25:02 +020010701 {
10702 .cmd = NL80211_CMD_SET_CHANNEL,
10703 .doit = nl80211_set_channel,
10704 .policy = nl80211_policy,
10705 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010706 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10707 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010708 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010709 {
10710 .cmd = NL80211_CMD_SET_WDS_PEER,
10711 .doit = nl80211_set_wds_peer,
10712 .policy = nl80211_policy,
10713 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010714 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10715 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010716 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010717 {
10718 .cmd = NL80211_CMD_JOIN_MESH,
10719 .doit = nl80211_join_mesh,
10720 .policy = nl80211_policy,
10721 .flags = GENL_ADMIN_PERM,
10722 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10723 NL80211_FLAG_NEED_RTNL,
10724 },
10725 {
10726 .cmd = NL80211_CMD_LEAVE_MESH,
10727 .doit = nl80211_leave_mesh,
10728 .policy = nl80211_policy,
10729 .flags = GENL_ADMIN_PERM,
10730 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10731 NL80211_FLAG_NEED_RTNL,
10732 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010733 {
10734 .cmd = NL80211_CMD_JOIN_OCB,
10735 .doit = nl80211_join_ocb,
10736 .policy = nl80211_policy,
10737 .flags = GENL_ADMIN_PERM,
10738 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10739 NL80211_FLAG_NEED_RTNL,
10740 },
10741 {
10742 .cmd = NL80211_CMD_LEAVE_OCB,
10743 .doit = nl80211_leave_ocb,
10744 .policy = nl80211_policy,
10745 .flags = GENL_ADMIN_PERM,
10746 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10747 NL80211_FLAG_NEED_RTNL,
10748 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010749#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010750 {
10751 .cmd = NL80211_CMD_GET_WOWLAN,
10752 .doit = nl80211_get_wowlan,
10753 .policy = nl80211_policy,
10754 /* can be retrieved by unprivileged users */
10755 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10756 NL80211_FLAG_NEED_RTNL,
10757 },
10758 {
10759 .cmd = NL80211_CMD_SET_WOWLAN,
10760 .doit = nl80211_set_wowlan,
10761 .policy = nl80211_policy,
10762 .flags = GENL_ADMIN_PERM,
10763 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10764 NL80211_FLAG_NEED_RTNL,
10765 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010766#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010767 {
10768 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10769 .doit = nl80211_set_rekey_data,
10770 .policy = nl80211_policy,
10771 .flags = GENL_ADMIN_PERM,
10772 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010773 NL80211_FLAG_NEED_RTNL |
10774 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010775 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010776 {
10777 .cmd = NL80211_CMD_TDLS_MGMT,
10778 .doit = nl80211_tdls_mgmt,
10779 .policy = nl80211_policy,
10780 .flags = GENL_ADMIN_PERM,
10781 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10782 NL80211_FLAG_NEED_RTNL,
10783 },
10784 {
10785 .cmd = NL80211_CMD_TDLS_OPER,
10786 .doit = nl80211_tdls_oper,
10787 .policy = nl80211_policy,
10788 .flags = GENL_ADMIN_PERM,
10789 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10790 NL80211_FLAG_NEED_RTNL,
10791 },
Johannes Berg28946da2011-11-04 11:18:12 +010010792 {
10793 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10794 .doit = nl80211_register_unexpected_frame,
10795 .policy = nl80211_policy,
10796 .flags = GENL_ADMIN_PERM,
10797 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10798 NL80211_FLAG_NEED_RTNL,
10799 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010800 {
10801 .cmd = NL80211_CMD_PROBE_CLIENT,
10802 .doit = nl80211_probe_client,
10803 .policy = nl80211_policy,
10804 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010805 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010806 NL80211_FLAG_NEED_RTNL,
10807 },
Johannes Berg5e760232011-11-04 11:18:17 +010010808 {
10809 .cmd = NL80211_CMD_REGISTER_BEACONS,
10810 .doit = nl80211_register_beacons,
10811 .policy = nl80211_policy,
10812 .flags = GENL_ADMIN_PERM,
10813 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10814 NL80211_FLAG_NEED_RTNL,
10815 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010816 {
10817 .cmd = NL80211_CMD_SET_NOACK_MAP,
10818 .doit = nl80211_set_noack_map,
10819 .policy = nl80211_policy,
10820 .flags = GENL_ADMIN_PERM,
10821 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10822 NL80211_FLAG_NEED_RTNL,
10823 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010824 {
10825 .cmd = NL80211_CMD_START_P2P_DEVICE,
10826 .doit = nl80211_start_p2p_device,
10827 .policy = nl80211_policy,
10828 .flags = GENL_ADMIN_PERM,
10829 .internal_flags = NL80211_FLAG_NEED_WDEV |
10830 NL80211_FLAG_NEED_RTNL,
10831 },
10832 {
10833 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10834 .doit = nl80211_stop_p2p_device,
10835 .policy = nl80211_policy,
10836 .flags = GENL_ADMIN_PERM,
10837 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10838 NL80211_FLAG_NEED_RTNL,
10839 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010840 {
10841 .cmd = NL80211_CMD_SET_MCAST_RATE,
10842 .doit = nl80211_set_mcast_rate,
10843 .policy = nl80211_policy,
10844 .flags = GENL_ADMIN_PERM,
10845 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10846 NL80211_FLAG_NEED_RTNL,
10847 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010848 {
10849 .cmd = NL80211_CMD_SET_MAC_ACL,
10850 .doit = nl80211_set_mac_acl,
10851 .policy = nl80211_policy,
10852 .flags = GENL_ADMIN_PERM,
10853 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10854 NL80211_FLAG_NEED_RTNL,
10855 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010856 {
10857 .cmd = NL80211_CMD_RADAR_DETECT,
10858 .doit = nl80211_start_radar_detection,
10859 .policy = nl80211_policy,
10860 .flags = GENL_ADMIN_PERM,
10861 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10862 NL80211_FLAG_NEED_RTNL,
10863 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010864 {
10865 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10866 .doit = nl80211_get_protocol_features,
10867 .policy = nl80211_policy,
10868 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010869 {
10870 .cmd = NL80211_CMD_UPDATE_FT_IES,
10871 .doit = nl80211_update_ft_ies,
10872 .policy = nl80211_policy,
10873 .flags = GENL_ADMIN_PERM,
10874 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10875 NL80211_FLAG_NEED_RTNL,
10876 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010877 {
10878 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10879 .doit = nl80211_crit_protocol_start,
10880 .policy = nl80211_policy,
10881 .flags = GENL_ADMIN_PERM,
10882 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10883 NL80211_FLAG_NEED_RTNL,
10884 },
10885 {
10886 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10887 .doit = nl80211_crit_protocol_stop,
10888 .policy = nl80211_policy,
10889 .flags = GENL_ADMIN_PERM,
10890 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10891 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010892 },
10893 {
10894 .cmd = NL80211_CMD_GET_COALESCE,
10895 .doit = nl80211_get_coalesce,
10896 .policy = nl80211_policy,
10897 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10898 NL80211_FLAG_NEED_RTNL,
10899 },
10900 {
10901 .cmd = NL80211_CMD_SET_COALESCE,
10902 .doit = nl80211_set_coalesce,
10903 .policy = nl80211_policy,
10904 .flags = GENL_ADMIN_PERM,
10905 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10906 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010907 },
10908 {
10909 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10910 .doit = nl80211_channel_switch,
10911 .policy = nl80211_policy,
10912 .flags = GENL_ADMIN_PERM,
10913 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10914 NL80211_FLAG_NEED_RTNL,
10915 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010916 {
10917 .cmd = NL80211_CMD_VENDOR,
10918 .doit = nl80211_vendor_cmd,
10919 .policy = nl80211_policy,
10920 .flags = GENL_ADMIN_PERM,
10921 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10922 NL80211_FLAG_NEED_RTNL,
10923 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010924 {
10925 .cmd = NL80211_CMD_SET_QOS_MAP,
10926 .doit = nl80211_set_qos_map,
10927 .policy = nl80211_policy,
10928 .flags = GENL_ADMIN_PERM,
10929 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10930 NL80211_FLAG_NEED_RTNL,
10931 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010932 {
10933 .cmd = NL80211_CMD_ADD_TX_TS,
10934 .doit = nl80211_add_tx_ts,
10935 .policy = nl80211_policy,
10936 .flags = GENL_ADMIN_PERM,
10937 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10938 NL80211_FLAG_NEED_RTNL,
10939 },
10940 {
10941 .cmd = NL80211_CMD_DEL_TX_TS,
10942 .doit = nl80211_del_tx_ts,
10943 .policy = nl80211_policy,
10944 .flags = GENL_ADMIN_PERM,
10945 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10946 NL80211_FLAG_NEED_RTNL,
10947 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020010948 {
10949 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
10950 .doit = nl80211_tdls_channel_switch,
10951 .policy = nl80211_policy,
10952 .flags = GENL_ADMIN_PERM,
10953 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10954 NL80211_FLAG_NEED_RTNL,
10955 },
10956 {
10957 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
10958 .doit = nl80211_tdls_cancel_channel_switch,
10959 .policy = nl80211_policy,
10960 .flags = GENL_ADMIN_PERM,
10961 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10962 NL80211_FLAG_NEED_RTNL,
10963 },
Johannes Berg55682962007-09-20 13:09:35 -040010964};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010965
Johannes Berg55682962007-09-20 13:09:35 -040010966/* notification functions */
10967
Johannes Berg3bb20552014-05-26 13:52:25 +020010968void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10969 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010970{
10971 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010972 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010973
Johannes Berg3bb20552014-05-26 13:52:25 +020010974 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10975 cmd != NL80211_CMD_DEL_WIPHY);
10976
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010977 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010978 if (!msg)
10979 return;
10980
Johannes Berg3bb20552014-05-26 13:52:25 +020010981 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010982 nlmsg_free(msg);
10983 return;
10984 }
10985
Johannes Berg68eb5502013-11-19 15:19:38 +010010986 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010987 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010988}
10989
Johannes Berg362a4152009-05-24 16:43:15 +020010990static int nl80211_add_scan_req(struct sk_buff *msg,
10991 struct cfg80211_registered_device *rdev)
10992{
10993 struct cfg80211_scan_request *req = rdev->scan_req;
10994 struct nlattr *nest;
10995 int i;
10996
10997 if (WARN_ON(!req))
10998 return 0;
10999
11000 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11001 if (!nest)
11002 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011003 for (i = 0; i < req->n_ssids; i++) {
11004 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11005 goto nla_put_failure;
11006 }
Johannes Berg362a4152009-05-24 16:43:15 +020011007 nla_nest_end(msg, nest);
11008
11009 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11010 if (!nest)
11011 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011012 for (i = 0; i < req->n_channels; i++) {
11013 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11014 goto nla_put_failure;
11015 }
Johannes Berg362a4152009-05-24 16:43:15 +020011016 nla_nest_end(msg, nest);
11017
David S. Miller9360ffd2012-03-29 04:41:26 -040011018 if (req->ie &&
11019 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11020 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011021
Johannes Bergae917c92013-10-25 11:05:22 +020011022 if (req->flags &&
11023 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11024 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011025
Johannes Berg362a4152009-05-24 16:43:15 +020011026 return 0;
11027 nla_put_failure:
11028 return -ENOBUFS;
11029}
11030
Johannes Berga538e2d2009-06-16 19:56:42 +020011031static int nl80211_send_scan_msg(struct sk_buff *msg,
11032 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011033 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011034 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011035 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011036{
11037 void *hdr;
11038
Eric W. Biederman15e47302012-09-07 20:12:54 +000011039 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011040 if (!hdr)
11041 return -1;
11042
David S. Miller9360ffd2012-03-29 04:41:26 -040011043 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011044 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11045 wdev->netdev->ifindex)) ||
11046 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011047 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011048
Johannes Berg362a4152009-05-24 16:43:15 +020011049 /* ignore errors and send incomplete event anyway */
11050 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011051
11052 return genlmsg_end(msg, hdr);
11053
11054 nla_put_failure:
11055 genlmsg_cancel(msg, hdr);
11056 return -EMSGSIZE;
11057}
11058
Luciano Coelho807f8a82011-05-11 17:09:35 +030011059static int
11060nl80211_send_sched_scan_msg(struct sk_buff *msg,
11061 struct cfg80211_registered_device *rdev,
11062 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011063 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011064{
11065 void *hdr;
11066
Eric W. Biederman15e47302012-09-07 20:12:54 +000011067 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011068 if (!hdr)
11069 return -1;
11070
David S. Miller9360ffd2012-03-29 04:41:26 -040011071 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11072 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11073 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011074
11075 return genlmsg_end(msg, hdr);
11076
11077 nla_put_failure:
11078 genlmsg_cancel(msg, hdr);
11079 return -EMSGSIZE;
11080}
11081
Johannes Berga538e2d2009-06-16 19:56:42 +020011082void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011083 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011084{
11085 struct sk_buff *msg;
11086
Thomas Graf58050fc2012-06-28 03:57:45 +000011087 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011088 if (!msg)
11089 return;
11090
Johannes Bergfd014282012-06-18 19:17:03 +020011091 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011092 NL80211_CMD_TRIGGER_SCAN) < 0) {
11093 nlmsg_free(msg);
11094 return;
11095 }
11096
Johannes Berg68eb5502013-11-19 15:19:38 +010011097 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011098 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011099}
11100
Johannes Bergf9d15d12014-01-22 11:14:19 +020011101struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11102 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011103{
11104 struct sk_buff *msg;
11105
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011106 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011107 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011108 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011109
Johannes Bergfd014282012-06-18 19:17:03 +020011110 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011111 aborted ? NL80211_CMD_SCAN_ABORTED :
11112 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011113 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011114 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011115 }
11116
Johannes Bergf9d15d12014-01-22 11:14:19 +020011117 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011118}
11119
Johannes Bergf9d15d12014-01-22 11:14:19 +020011120void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11121 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011122{
Johannes Berg2a519312009-02-10 21:25:55 +010011123 if (!msg)
11124 return;
11125
Johannes Berg68eb5502013-11-19 15:19:38 +010011126 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011127 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011128}
11129
Luciano Coelho807f8a82011-05-11 17:09:35 +030011130void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11131 struct net_device *netdev)
11132{
11133 struct sk_buff *msg;
11134
11135 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11136 if (!msg)
11137 return;
11138
11139 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11140 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11141 nlmsg_free(msg);
11142 return;
11143 }
11144
Johannes Berg68eb5502013-11-19 15:19:38 +010011145 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011146 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011147}
11148
11149void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11150 struct net_device *netdev, u32 cmd)
11151{
11152 struct sk_buff *msg;
11153
Thomas Graf58050fc2012-06-28 03:57:45 +000011154 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011155 if (!msg)
11156 return;
11157
11158 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11159 nlmsg_free(msg);
11160 return;
11161 }
11162
Johannes Berg68eb5502013-11-19 15:19:38 +010011163 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011164 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011165}
11166
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011167static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11168 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011169{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011170 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011171 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11172 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011173
David S. Miller9360ffd2012-03-29 04:41:26 -040011174 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11175 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11176 NL80211_REGDOM_TYPE_WORLD))
11177 goto nla_put_failure;
11178 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11179 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11180 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11181 goto nla_put_failure;
11182 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11183 request->intersect) {
11184 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11185 NL80211_REGDOM_TYPE_INTERSECTION))
11186 goto nla_put_failure;
11187 } else {
11188 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11189 NL80211_REGDOM_TYPE_COUNTRY) ||
11190 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11191 request->alpha2))
11192 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011193 }
11194
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011195 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11196 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11197
11198 if (wiphy &&
11199 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11200 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011201
11202 if (wiphy &&
11203 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11204 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11205 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011206 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011207
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011208 return true;
11209
11210nla_put_failure:
11211 return false;
11212}
11213
11214/*
11215 * This can happen on global regulatory changes or device specific settings
11216 * based on custom regulatory domains.
11217 */
11218void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11219 struct regulatory_request *request)
11220{
11221 struct sk_buff *msg;
11222 void *hdr;
11223
11224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11225 if (!msg)
11226 return;
11227
11228 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11229 if (!hdr) {
11230 nlmsg_free(msg);
11231 return;
11232 }
11233
11234 if (nl80211_reg_change_event_fill(msg, request) == false)
11235 goto nla_put_failure;
11236
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011237 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011238
Johannes Bergbc43b282009-07-25 10:54:13 +020011239 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011240 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011241 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011242 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011243
11244 return;
11245
11246nla_put_failure:
11247 genlmsg_cancel(msg, hdr);
11248 nlmsg_free(msg);
11249}
11250
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011251static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11252 struct net_device *netdev,
11253 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011254 enum nl80211_commands cmd, gfp_t gfp,
11255 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011256{
11257 struct sk_buff *msg;
11258 void *hdr;
11259
Johannes Berge6d6e342009-07-01 21:26:47 +020011260 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011261 if (!msg)
11262 return;
11263
11264 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11265 if (!hdr) {
11266 nlmsg_free(msg);
11267 return;
11268 }
11269
David S. Miller9360ffd2012-03-29 04:41:26 -040011270 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11271 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11272 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11273 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011274
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011275 if (uapsd_queues >= 0) {
11276 struct nlattr *nla_wmm =
11277 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11278 if (!nla_wmm)
11279 goto nla_put_failure;
11280
11281 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11282 uapsd_queues))
11283 goto nla_put_failure;
11284
11285 nla_nest_end(msg, nla_wmm);
11286 }
11287
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011288 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011289
Johannes Berg68eb5502013-11-19 15:19:38 +010011290 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011291 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011292 return;
11293
11294 nla_put_failure:
11295 genlmsg_cancel(msg, hdr);
11296 nlmsg_free(msg);
11297}
11298
11299void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011300 struct net_device *netdev, const u8 *buf,
11301 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011302{
11303 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011304 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011305}
11306
11307void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11308 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011309 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011310{
Johannes Berge6d6e342009-07-01 21:26:47 +020011311 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011312 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011313}
11314
Jouni Malinen53b46b82009-03-27 20:53:56 +020011315void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011316 struct net_device *netdev, const u8 *buf,
11317 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011318{
11319 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011320 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011321}
11322
Jouni Malinen53b46b82009-03-27 20:53:56 +020011323void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11324 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011325 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011326{
11327 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011328 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011329}
11330
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011331void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11332 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011333{
Johannes Berg947add32013-02-22 22:05:20 +010011334 struct wireless_dev *wdev = dev->ieee80211_ptr;
11335 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011336 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011337 const struct ieee80211_mgmt *mgmt = (void *)buf;
11338 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011339
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011340 if (WARN_ON(len < 2))
11341 return;
11342
11343 if (ieee80211_is_deauth(mgmt->frame_control))
11344 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11345 else
11346 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11347
11348 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011349 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011350}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011351EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011352
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011353static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11354 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011355 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011356{
11357 struct sk_buff *msg;
11358 void *hdr;
11359
Johannes Berge6d6e342009-07-01 21:26:47 +020011360 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011361 if (!msg)
11362 return;
11363
11364 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11365 if (!hdr) {
11366 nlmsg_free(msg);
11367 return;
11368 }
11369
David S. Miller9360ffd2012-03-29 04:41:26 -040011370 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11371 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11372 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11373 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11374 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011375
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011376 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011377
Johannes Berg68eb5502013-11-19 15:19:38 +010011378 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011379 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011380 return;
11381
11382 nla_put_failure:
11383 genlmsg_cancel(msg, hdr);
11384 nlmsg_free(msg);
11385}
11386
11387void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011388 struct net_device *netdev, const u8 *addr,
11389 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011390{
11391 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011392 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011393}
11394
11395void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011396 struct net_device *netdev, const u8 *addr,
11397 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011398{
Johannes Berge6d6e342009-07-01 21:26:47 +020011399 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11400 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011401}
11402
Samuel Ortizb23aa672009-07-01 21:26:54 +020011403void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11404 struct net_device *netdev, const u8 *bssid,
11405 const u8 *req_ie, size_t req_ie_len,
11406 const u8 *resp_ie, size_t resp_ie_len,
11407 u16 status, gfp_t gfp)
11408{
11409 struct sk_buff *msg;
11410 void *hdr;
11411
Thomas Graf58050fc2012-06-28 03:57:45 +000011412 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011413 if (!msg)
11414 return;
11415
11416 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11417 if (!hdr) {
11418 nlmsg_free(msg);
11419 return;
11420 }
11421
David S. Miller9360ffd2012-03-29 04:41:26 -040011422 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11423 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11424 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11425 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11426 (req_ie &&
11427 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11428 (resp_ie &&
11429 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11430 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011431
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011432 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011433
Johannes Berg68eb5502013-11-19 15:19:38 +010011434 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011435 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011436 return;
11437
11438 nla_put_failure:
11439 genlmsg_cancel(msg, hdr);
11440 nlmsg_free(msg);
11441
11442}
11443
11444void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11445 struct net_device *netdev, const u8 *bssid,
11446 const u8 *req_ie, size_t req_ie_len,
11447 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11448{
11449 struct sk_buff *msg;
11450 void *hdr;
11451
Thomas Graf58050fc2012-06-28 03:57:45 +000011452 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011453 if (!msg)
11454 return;
11455
11456 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11457 if (!hdr) {
11458 nlmsg_free(msg);
11459 return;
11460 }
11461
David S. Miller9360ffd2012-03-29 04:41:26 -040011462 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11463 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11464 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11465 (req_ie &&
11466 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11467 (resp_ie &&
11468 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11469 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011470
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011471 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011472
Johannes Berg68eb5502013-11-19 15:19:38 +010011473 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011474 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011475 return;
11476
11477 nla_put_failure:
11478 genlmsg_cancel(msg, hdr);
11479 nlmsg_free(msg);
11480
11481}
11482
11483void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11484 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020011485 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011486{
11487 struct sk_buff *msg;
11488 void *hdr;
11489
Thomas Graf58050fc2012-06-28 03:57:45 +000011490 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011491 if (!msg)
11492 return;
11493
11494 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11495 if (!hdr) {
11496 nlmsg_free(msg);
11497 return;
11498 }
11499
David S. Miller9360ffd2012-03-29 04:41:26 -040011500 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11501 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11502 (from_ap && reason &&
11503 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11504 (from_ap &&
11505 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11506 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11507 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011508
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011509 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011510
Johannes Berg68eb5502013-11-19 15:19:38 +010011511 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011512 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011513 return;
11514
11515 nla_put_failure:
11516 genlmsg_cancel(msg, hdr);
11517 nlmsg_free(msg);
11518
11519}
11520
Johannes Berg04a773a2009-04-19 21:24:32 +020011521void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11522 struct net_device *netdev, const u8 *bssid,
11523 gfp_t gfp)
11524{
11525 struct sk_buff *msg;
11526 void *hdr;
11527
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011528 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011529 if (!msg)
11530 return;
11531
11532 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11533 if (!hdr) {
11534 nlmsg_free(msg);
11535 return;
11536 }
11537
David S. Miller9360ffd2012-03-29 04:41:26 -040011538 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11539 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11540 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11541 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011542
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011543 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011544
Johannes Berg68eb5502013-11-19 15:19:38 +010011545 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011546 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011547 return;
11548
11549 nla_put_failure:
11550 genlmsg_cancel(msg, hdr);
11551 nlmsg_free(msg);
11552}
11553
Johannes Berg947add32013-02-22 22:05:20 +010011554void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11555 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011556{
Johannes Berg947add32013-02-22 22:05:20 +010011557 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011558 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011559 struct sk_buff *msg;
11560 void *hdr;
11561
Johannes Berg947add32013-02-22 22:05:20 +010011562 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11563 return;
11564
11565 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11566
Javier Cardonac93b5e72011-04-07 15:08:34 -070011567 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11568 if (!msg)
11569 return;
11570
11571 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11572 if (!hdr) {
11573 nlmsg_free(msg);
11574 return;
11575 }
11576
David S. Miller9360ffd2012-03-29 04:41:26 -040011577 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011578 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11579 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011580 (ie_len && ie &&
11581 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11582 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011583
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011584 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011585
Johannes Berg68eb5502013-11-19 15:19:38 +010011586 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011587 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011588 return;
11589
11590 nla_put_failure:
11591 genlmsg_cancel(msg, hdr);
11592 nlmsg_free(msg);
11593}
Johannes Berg947add32013-02-22 22:05:20 +010011594EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011595
Jouni Malinena3b8b052009-03-27 21:59:49 +020011596void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11597 struct net_device *netdev, const u8 *addr,
11598 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011599 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011600{
11601 struct sk_buff *msg;
11602 void *hdr;
11603
Johannes Berge6d6e342009-07-01 21:26:47 +020011604 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011605 if (!msg)
11606 return;
11607
11608 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11609 if (!hdr) {
11610 nlmsg_free(msg);
11611 return;
11612 }
11613
David S. Miller9360ffd2012-03-29 04:41:26 -040011614 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11615 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11616 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11617 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11618 (key_id != -1 &&
11619 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11620 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11621 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011622
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011623 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011624
Johannes Berg68eb5502013-11-19 15:19:38 +010011625 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011626 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011627 return;
11628
11629 nla_put_failure:
11630 genlmsg_cancel(msg, hdr);
11631 nlmsg_free(msg);
11632}
11633
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011634void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11635 struct ieee80211_channel *channel_before,
11636 struct ieee80211_channel *channel_after)
11637{
11638 struct sk_buff *msg;
11639 void *hdr;
11640 struct nlattr *nl_freq;
11641
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011642 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011643 if (!msg)
11644 return;
11645
11646 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11647 if (!hdr) {
11648 nlmsg_free(msg);
11649 return;
11650 }
11651
11652 /*
11653 * Since we are applying the beacon hint to a wiphy we know its
11654 * wiphy_idx is valid
11655 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011656 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11657 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011658
11659 /* Before */
11660 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11661 if (!nl_freq)
11662 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011663 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011664 goto nla_put_failure;
11665 nla_nest_end(msg, nl_freq);
11666
11667 /* After */
11668 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11669 if (!nl_freq)
11670 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011671 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011672 goto nla_put_failure;
11673 nla_nest_end(msg, nl_freq);
11674
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011675 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011676
Johannes Berg463d0182009-07-14 00:33:35 +020011677 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011678 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011679 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011680 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011681
11682 return;
11683
11684nla_put_failure:
11685 genlmsg_cancel(msg, hdr);
11686 nlmsg_free(msg);
11687}
11688
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011689static void nl80211_send_remain_on_chan_event(
11690 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011691 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011692 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011693 unsigned int duration, gfp_t gfp)
11694{
11695 struct sk_buff *msg;
11696 void *hdr;
11697
11698 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11699 if (!msg)
11700 return;
11701
11702 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11703 if (!hdr) {
11704 nlmsg_free(msg);
11705 return;
11706 }
11707
David S. Miller9360ffd2012-03-29 04:41:26 -040011708 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011709 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11710 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011711 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011712 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011713 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11714 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011715 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11716 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011717
David S. Miller9360ffd2012-03-29 04:41:26 -040011718 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11719 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11720 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011721
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011722 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011723
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);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011726 return;
11727
11728 nla_put_failure:
11729 genlmsg_cancel(msg, hdr);
11730 nlmsg_free(msg);
11731}
11732
Johannes Berg947add32013-02-22 22:05:20 +010011733void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11734 struct ieee80211_channel *chan,
11735 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011736{
Johannes Berg947add32013-02-22 22:05:20 +010011737 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011738 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011739
11740 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011741 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011742 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011743 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011744}
Johannes Berg947add32013-02-22 22:05:20 +010011745EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011746
Johannes Berg947add32013-02-22 22:05:20 +010011747void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11748 struct ieee80211_channel *chan,
11749 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011750{
Johannes Berg947add32013-02-22 22:05:20 +010011751 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011752 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011753
11754 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011755 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011756 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011757}
Johannes Berg947add32013-02-22 22:05:20 +010011758EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011759
Johannes Berg947add32013-02-22 22:05:20 +010011760void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11761 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011762{
Johannes Berg947add32013-02-22 22:05:20 +010011763 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011764 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011765 struct sk_buff *msg;
11766
Johannes Berg947add32013-02-22 22:05:20 +010011767 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11768
Thomas Graf58050fc2012-06-28 03:57:45 +000011769 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011770 if (!msg)
11771 return;
11772
Johannes Bergcf5ead82014-11-14 17:14:00 +010011773 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040011774 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011775 nlmsg_free(msg);
11776 return;
11777 }
11778
Johannes Berg68eb5502013-11-19 15:19:38 +010011779 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011780 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011781}
Johannes Berg947add32013-02-22 22:05:20 +010011782EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011783
Johannes Bergcf5ead82014-11-14 17:14:00 +010011784void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
11785 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011786{
Johannes Berg947add32013-02-22 22:05:20 +010011787 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011788 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011789 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010011790 struct station_info empty_sinfo = {};
11791
11792 if (!sinfo)
11793 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020011794
Johannes Berg947add32013-02-22 22:05:20 +010011795 trace_cfg80211_del_sta(dev, mac_addr);
11796
Thomas Graf58050fc2012-06-28 03:57:45 +000011797 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011798 if (!msg)
11799 return;
11800
Johannes Bergcf5ead82014-11-14 17:14:00 +010011801 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010011802 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020011803 nlmsg_free(msg);
11804 return;
11805 }
11806
Johannes Berg68eb5502013-11-19 15:19:38 +010011807 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011808 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011809}
Johannes Bergcf5ead82014-11-14 17:14:00 +010011810EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020011811
Johannes Berg947add32013-02-22 22:05:20 +010011812void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11813 enum nl80211_connect_failed_reason reason,
11814 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011815{
Johannes Berg947add32013-02-22 22:05:20 +010011816 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011817 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011818 struct sk_buff *msg;
11819 void *hdr;
11820
11821 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11822 if (!msg)
11823 return;
11824
11825 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11826 if (!hdr) {
11827 nlmsg_free(msg);
11828 return;
11829 }
11830
11831 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11832 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11833 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11834 goto nla_put_failure;
11835
11836 genlmsg_end(msg, hdr);
11837
Johannes Berg68eb5502013-11-19 15:19:38 +010011838 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011839 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011840 return;
11841
11842 nla_put_failure:
11843 genlmsg_cancel(msg, hdr);
11844 nlmsg_free(msg);
11845}
Johannes Berg947add32013-02-22 22:05:20 +010011846EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011847
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011848static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11849 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011850{
11851 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011852 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011853 struct sk_buff *msg;
11854 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011855 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011856
Eric W. Biederman15e47302012-09-07 20:12:54 +000011857 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011858 return false;
11859
11860 msg = nlmsg_new(100, gfp);
11861 if (!msg)
11862 return true;
11863
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011864 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011865 if (!hdr) {
11866 nlmsg_free(msg);
11867 return true;
11868 }
11869
David S. Miller9360ffd2012-03-29 04:41:26 -040011870 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11871 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11872 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11873 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011874
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011875 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011876 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011877 return true;
11878
11879 nla_put_failure:
11880 genlmsg_cancel(msg, hdr);
11881 nlmsg_free(msg);
11882 return true;
11883}
11884
Johannes Berg947add32013-02-22 22:05:20 +010011885bool cfg80211_rx_spurious_frame(struct net_device *dev,
11886 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011887{
Johannes Berg947add32013-02-22 22:05:20 +010011888 struct wireless_dev *wdev = dev->ieee80211_ptr;
11889 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011890
Johannes Berg947add32013-02-22 22:05:20 +010011891 trace_cfg80211_rx_spurious_frame(dev, addr);
11892
11893 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11894 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11895 trace_cfg80211_return_bool(false);
11896 return false;
11897 }
11898 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11899 addr, gfp);
11900 trace_cfg80211_return_bool(ret);
11901 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011902}
Johannes Berg947add32013-02-22 22:05:20 +010011903EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11904
11905bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11906 const u8 *addr, gfp_t gfp)
11907{
11908 struct wireless_dev *wdev = dev->ieee80211_ptr;
11909 bool ret;
11910
11911 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11912
11913 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11914 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11915 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11916 trace_cfg80211_return_bool(false);
11917 return false;
11918 }
11919 ret = __nl80211_unexpected_frame(dev,
11920 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11921 addr, gfp);
11922 trace_cfg80211_return_bool(ret);
11923 return ret;
11924}
11925EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011926
Johannes Berg2e161f782010-08-12 15:38:38 +020011927int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011928 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011929 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011930 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011931{
Johannes Berg71bbc992012-06-15 15:30:18 +020011932 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011933 struct sk_buff *msg;
11934 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011935
11936 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11937 if (!msg)
11938 return -ENOMEM;
11939
Johannes Berg2e161f782010-08-12 15:38:38 +020011940 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011941 if (!hdr) {
11942 nlmsg_free(msg);
11943 return -ENOMEM;
11944 }
11945
David S. Miller9360ffd2012-03-29 04:41:26 -040011946 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011947 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11948 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011949 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011950 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11951 (sig_dbm &&
11952 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011953 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11954 (flags &&
11955 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011956 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011957
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011958 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011959
Eric W. Biederman15e47302012-09-07 20:12:54 +000011960 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011961
11962 nla_put_failure:
11963 genlmsg_cancel(msg, hdr);
11964 nlmsg_free(msg);
11965 return -ENOBUFS;
11966}
11967
Johannes Berg947add32013-02-22 22:05:20 +010011968void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11969 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011970{
Johannes Berg947add32013-02-22 22:05:20 +010011971 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011972 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011973 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011974 struct sk_buff *msg;
11975 void *hdr;
11976
Johannes Berg947add32013-02-22 22:05:20 +010011977 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11978
Jouni Malinen026331c2010-02-15 12:53:10 +020011979 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11980 if (!msg)
11981 return;
11982
Johannes Berg2e161f782010-08-12 15:38:38 +020011983 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011984 if (!hdr) {
11985 nlmsg_free(msg);
11986 return;
11987 }
11988
David S. Miller9360ffd2012-03-29 04:41:26 -040011989 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011990 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11991 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011992 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011993 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11994 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11995 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11996 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011997
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011998 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011999
Johannes Berg68eb5502013-11-19 15:19:38 +010012000 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012001 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012002 return;
12003
12004 nla_put_failure:
12005 genlmsg_cancel(msg, hdr);
12006 nlmsg_free(msg);
12007}
Johannes Berg947add32013-02-22 22:05:20 +010012008EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012009
Johannes Berg5b97f492014-11-26 12:37:43 +010012010static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12011 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012012{
Johannes Berg947add32013-02-22 22:05:20 +010012013 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012014 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12015 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12016 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012017
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012018 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012019 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012020
Johannes Berg5b97f492014-11-26 12:37:43 +010012021 cb = (void **)msg->cb;
12022
12023 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12024 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012025 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012026 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012027 }
12028
David S. Miller9360ffd2012-03-29 04:41:26 -040012029 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012030 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012031 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012032
Johannes Berg5b97f492014-11-26 12:37:43 +010012033 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012034 goto nla_put_failure;
12035
Johannes Berg5b97f492014-11-26 12:37:43 +010012036 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12037 if (!cb[1])
12038 goto nla_put_failure;
12039
12040 cb[2] = rdev;
12041
12042 return msg;
12043 nla_put_failure:
12044 nlmsg_free(msg);
12045 return NULL;
12046}
12047
12048static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12049{
12050 void **cb = (void **)msg->cb;
12051 struct cfg80211_registered_device *rdev = cb[2];
12052
12053 nla_nest_end(msg, cb[1]);
12054 genlmsg_end(msg, cb[0]);
12055
12056 memset(msg->cb, 0, sizeof(msg->cb));
12057
12058 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12059 NL80211_MCGRP_MLME, gfp);
12060}
12061
12062void cfg80211_cqm_rssi_notify(struct net_device *dev,
12063 enum nl80211_cqm_rssi_threshold_event rssi_event,
12064 gfp_t gfp)
12065{
12066 struct sk_buff *msg;
12067
12068 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12069
Johannes Berg98f03342014-11-26 12:42:02 +010012070 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12071 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12072 return;
12073
Johannes Berg5b97f492014-11-26 12:37:43 +010012074 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12075 if (!msg)
12076 return;
12077
David S. Miller9360ffd2012-03-29 04:41:26 -040012078 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12079 rssi_event))
12080 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012081
Johannes Berg5b97f492014-11-26 12:37:43 +010012082 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012083
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012084 return;
12085
12086 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012087 nlmsg_free(msg);
12088}
Johannes Berg947add32013-02-22 22:05:20 +010012089EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012090
Johannes Berg5b97f492014-11-26 12:37:43 +010012091void cfg80211_cqm_txe_notify(struct net_device *dev,
12092 const u8 *peer, u32 num_packets,
12093 u32 rate, u32 intvl, gfp_t gfp)
12094{
12095 struct sk_buff *msg;
12096
12097 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12098 if (!msg)
12099 return;
12100
12101 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12102 goto nla_put_failure;
12103
12104 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12105 goto nla_put_failure;
12106
12107 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12108 goto nla_put_failure;
12109
12110 cfg80211_send_cqm(msg, gfp);
12111 return;
12112
12113 nla_put_failure:
12114 nlmsg_free(msg);
12115}
12116EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12117
12118void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12119 const u8 *peer, u32 num_packets, gfp_t gfp)
12120{
12121 struct sk_buff *msg;
12122
12123 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12124
12125 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12126 if (!msg)
12127 return;
12128
12129 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12130 goto nla_put_failure;
12131
12132 cfg80211_send_cqm(msg, gfp);
12133 return;
12134
12135 nla_put_failure:
12136 nlmsg_free(msg);
12137}
12138EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12139
Johannes Berg98f03342014-11-26 12:42:02 +010012140void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12141{
12142 struct sk_buff *msg;
12143
12144 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12145 if (!msg)
12146 return;
12147
12148 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12149 goto nla_put_failure;
12150
12151 cfg80211_send_cqm(msg, gfp);
12152 return;
12153
12154 nla_put_failure:
12155 nlmsg_free(msg);
12156}
12157EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12158
Johannes Berg947add32013-02-22 22:05:20 +010012159static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12160 struct net_device *netdev, const u8 *bssid,
12161 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012162{
12163 struct sk_buff *msg;
12164 struct nlattr *rekey_attr;
12165 void *hdr;
12166
Thomas Graf58050fc2012-06-28 03:57:45 +000012167 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012168 if (!msg)
12169 return;
12170
12171 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12172 if (!hdr) {
12173 nlmsg_free(msg);
12174 return;
12175 }
12176
David S. Miller9360ffd2012-03-29 04:41:26 -040012177 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12178 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12179 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12180 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012181
12182 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12183 if (!rekey_attr)
12184 goto nla_put_failure;
12185
David S. Miller9360ffd2012-03-29 04:41:26 -040012186 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12187 NL80211_REPLAY_CTR_LEN, replay_ctr))
12188 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012189
12190 nla_nest_end(msg, rekey_attr);
12191
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012192 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012193
Johannes Berg68eb5502013-11-19 15:19:38 +010012194 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012195 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012196 return;
12197
12198 nla_put_failure:
12199 genlmsg_cancel(msg, hdr);
12200 nlmsg_free(msg);
12201}
12202
Johannes Berg947add32013-02-22 22:05:20 +010012203void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12204 const u8 *replay_ctr, gfp_t gfp)
12205{
12206 struct wireless_dev *wdev = dev->ieee80211_ptr;
12207 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012208 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012209
12210 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12211 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12212}
12213EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12214
12215static void
12216nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12217 struct net_device *netdev, int index,
12218 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012219{
12220 struct sk_buff *msg;
12221 struct nlattr *attr;
12222 void *hdr;
12223
Thomas Graf58050fc2012-06-28 03:57:45 +000012224 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012225 if (!msg)
12226 return;
12227
12228 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12229 if (!hdr) {
12230 nlmsg_free(msg);
12231 return;
12232 }
12233
David S. Miller9360ffd2012-03-29 04:41:26 -040012234 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12235 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12236 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012237
12238 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12239 if (!attr)
12240 goto nla_put_failure;
12241
David S. Miller9360ffd2012-03-29 04:41:26 -040012242 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12243 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12244 (preauth &&
12245 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12246 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012247
12248 nla_nest_end(msg, attr);
12249
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012250 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012251
Johannes Berg68eb5502013-11-19 15:19:38 +010012252 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012253 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012254 return;
12255
12256 nla_put_failure:
12257 genlmsg_cancel(msg, hdr);
12258 nlmsg_free(msg);
12259}
12260
Johannes Berg947add32013-02-22 22:05:20 +010012261void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12262 const u8 *bssid, bool preauth, gfp_t gfp)
12263{
12264 struct wireless_dev *wdev = dev->ieee80211_ptr;
12265 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012266 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012267
12268 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12269 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12270}
12271EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12272
12273static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12274 struct net_device *netdev,
12275 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012276 gfp_t gfp,
12277 enum nl80211_commands notif,
12278 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012279{
12280 struct sk_buff *msg;
12281 void *hdr;
12282
Thomas Graf58050fc2012-06-28 03:57:45 +000012283 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012284 if (!msg)
12285 return;
12286
Luciano Coelhof8d75522014-11-07 14:31:35 +020012287 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012288 if (!hdr) {
12289 nlmsg_free(msg);
12290 return;
12291 }
12292
Johannes Berg683b6d32012-11-08 21:25:48 +010012293 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12294 goto nla_put_failure;
12295
12296 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012297 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012298
Luciano Coelhof8d75522014-11-07 14:31:35 +020012299 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12300 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12301 goto nla_put_failure;
12302
Thomas Pedersen53145262012-04-06 13:35:47 -070012303 genlmsg_end(msg, hdr);
12304
Johannes Berg68eb5502013-11-19 15:19:38 +010012305 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012306 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012307 return;
12308
12309 nla_put_failure:
12310 genlmsg_cancel(msg, hdr);
12311 nlmsg_free(msg);
12312}
12313
Johannes Berg947add32013-02-22 22:05:20 +010012314void cfg80211_ch_switch_notify(struct net_device *dev,
12315 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012316{
Johannes Berg947add32013-02-22 22:05:20 +010012317 struct wireless_dev *wdev = dev->ieee80211_ptr;
12318 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012319 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012320
Simon Wunderliche487eae2013-11-21 18:19:51 +010012321 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012322
Simon Wunderliche487eae2013-11-21 18:19:51 +010012323 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012324
Michal Kazior9e0e2962014-01-29 14:22:27 +010012325 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012326 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012327 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12328 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012329}
12330EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12331
Luciano Coelhof8d75522014-11-07 14:31:35 +020012332void cfg80211_ch_switch_started_notify(struct net_device *dev,
12333 struct cfg80211_chan_def *chandef,
12334 u8 count)
12335{
12336 struct wireless_dev *wdev = dev->ieee80211_ptr;
12337 struct wiphy *wiphy = wdev->wiphy;
12338 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12339
12340 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12341
12342 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12343 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12344}
12345EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12346
Thomas Pedersen84f10702012-07-12 16:17:33 -070012347void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012348nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012349 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012350 enum nl80211_radar_event event,
12351 struct net_device *netdev, gfp_t gfp)
12352{
12353 struct sk_buff *msg;
12354 void *hdr;
12355
12356 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12357 if (!msg)
12358 return;
12359
12360 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12361 if (!hdr) {
12362 nlmsg_free(msg);
12363 return;
12364 }
12365
12366 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12367 goto nla_put_failure;
12368
12369 /* NOP and radar events don't need a netdev parameter */
12370 if (netdev) {
12371 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12372
12373 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12374 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12375 goto nla_put_failure;
12376 }
12377
12378 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12379 goto nla_put_failure;
12380
12381 if (nl80211_send_chandef(msg, chandef))
12382 goto nla_put_failure;
12383
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012384 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012385
Johannes Berg68eb5502013-11-19 15:19:38 +010012386 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012387 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012388 return;
12389
12390 nla_put_failure:
12391 genlmsg_cancel(msg, hdr);
12392 nlmsg_free(msg);
12393}
12394
Johannes Berg7f6cf312011-11-04 11:18:15 +010012395void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12396 u64 cookie, bool acked, gfp_t gfp)
12397{
12398 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012399 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012400 struct sk_buff *msg;
12401 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012402
Beni Lev4ee3e062012-08-27 12:49:39 +030012403 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12404
Thomas Graf58050fc2012-06-28 03:57:45 +000012405 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012406
Johannes Berg7f6cf312011-11-04 11:18:15 +010012407 if (!msg)
12408 return;
12409
12410 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12411 if (!hdr) {
12412 nlmsg_free(msg);
12413 return;
12414 }
12415
David S. Miller9360ffd2012-03-29 04:41:26 -040012416 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12417 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12418 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12419 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12420 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12421 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012422
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012423 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012424
Johannes Berg68eb5502013-11-19 15:19:38 +010012425 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012426 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012427 return;
12428
12429 nla_put_failure:
12430 genlmsg_cancel(msg, hdr);
12431 nlmsg_free(msg);
12432}
12433EXPORT_SYMBOL(cfg80211_probe_status);
12434
Johannes Berg5e760232011-11-04 11:18:17 +010012435void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12436 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012437 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012438{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012439 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012440 struct sk_buff *msg;
12441 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012442 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012443
Beni Lev4ee3e062012-08-27 12:49:39 +030012444 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12445
Ben Greear37c73b52012-10-26 14:49:25 -070012446 spin_lock_bh(&rdev->beacon_registrations_lock);
12447 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12448 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12449 if (!msg) {
12450 spin_unlock_bh(&rdev->beacon_registrations_lock);
12451 return;
12452 }
Johannes Berg5e760232011-11-04 11:18:17 +010012453
Ben Greear37c73b52012-10-26 14:49:25 -070012454 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12455 if (!hdr)
12456 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012457
Ben Greear37c73b52012-10-26 14:49:25 -070012458 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12459 (freq &&
12460 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12461 (sig_dbm &&
12462 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12463 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12464 goto nla_put_failure;
12465
12466 genlmsg_end(msg, hdr);
12467
12468 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012469 }
Ben Greear37c73b52012-10-26 14:49:25 -070012470 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012471 return;
12472
12473 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012474 spin_unlock_bh(&rdev->beacon_registrations_lock);
12475 if (hdr)
12476 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012477 nlmsg_free(msg);
12478}
12479EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12480
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012481#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012482static int cfg80211_net_detect_results(struct sk_buff *msg,
12483 struct cfg80211_wowlan_wakeup *wakeup)
12484{
12485 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12486 struct nlattr *nl_results, *nl_match, *nl_freqs;
12487 int i, j;
12488
12489 nl_results = nla_nest_start(
12490 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12491 if (!nl_results)
12492 return -EMSGSIZE;
12493
12494 for (i = 0; i < nd->n_matches; i++) {
12495 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12496
12497 nl_match = nla_nest_start(msg, i);
12498 if (!nl_match)
12499 break;
12500
12501 /* The SSID attribute is optional in nl80211, but for
12502 * simplicity reasons it's always present in the
12503 * cfg80211 structure. If a driver can't pass the
12504 * SSID, that needs to be changed. A zero length SSID
12505 * is still a valid SSID (wildcard), so it cannot be
12506 * used for this purpose.
12507 */
12508 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12509 match->ssid.ssid)) {
12510 nla_nest_cancel(msg, nl_match);
12511 goto out;
12512 }
12513
12514 if (match->n_channels) {
12515 nl_freqs = nla_nest_start(
12516 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12517 if (!nl_freqs) {
12518 nla_nest_cancel(msg, nl_match);
12519 goto out;
12520 }
12521
12522 for (j = 0; j < match->n_channels; j++) {
12523 if (nla_put_u32(msg,
12524 NL80211_ATTR_WIPHY_FREQ,
12525 match->channels[j])) {
12526 nla_nest_cancel(msg, nl_freqs);
12527 nla_nest_cancel(msg, nl_match);
12528 goto out;
12529 }
12530 }
12531
12532 nla_nest_end(msg, nl_freqs);
12533 }
12534
12535 nla_nest_end(msg, nl_match);
12536 }
12537
12538out:
12539 nla_nest_end(msg, nl_results);
12540 return 0;
12541}
12542
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012543void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12544 struct cfg80211_wowlan_wakeup *wakeup,
12545 gfp_t gfp)
12546{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012547 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012548 struct sk_buff *msg;
12549 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012550 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012551
12552 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12553
12554 if (wakeup)
12555 size += wakeup->packet_present_len;
12556
12557 msg = nlmsg_new(size, gfp);
12558 if (!msg)
12559 return;
12560
12561 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12562 if (!hdr)
12563 goto free_msg;
12564
12565 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12566 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12567 goto free_msg;
12568
12569 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12570 wdev->netdev->ifindex))
12571 goto free_msg;
12572
12573 if (wakeup) {
12574 struct nlattr *reasons;
12575
12576 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012577 if (!reasons)
12578 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012579
12580 if (wakeup->disconnect &&
12581 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12582 goto free_msg;
12583 if (wakeup->magic_pkt &&
12584 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12585 goto free_msg;
12586 if (wakeup->gtk_rekey_failure &&
12587 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12588 goto free_msg;
12589 if (wakeup->eap_identity_req &&
12590 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12591 goto free_msg;
12592 if (wakeup->four_way_handshake &&
12593 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12594 goto free_msg;
12595 if (wakeup->rfkill_release &&
12596 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12597 goto free_msg;
12598
12599 if (wakeup->pattern_idx >= 0 &&
12600 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12601 wakeup->pattern_idx))
12602 goto free_msg;
12603
Johannes Bergae917c92013-10-25 11:05:22 +020012604 if (wakeup->tcp_match &&
12605 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12606 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012607
Johannes Bergae917c92013-10-25 11:05:22 +020012608 if (wakeup->tcp_connlost &&
12609 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12610 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012611
Johannes Bergae917c92013-10-25 11:05:22 +020012612 if (wakeup->tcp_nomoretokens &&
12613 nla_put_flag(msg,
12614 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12615 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012616
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012617 if (wakeup->packet) {
12618 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12619 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12620
12621 if (!wakeup->packet_80211) {
12622 pkt_attr =
12623 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12624 len_attr =
12625 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12626 }
12627
12628 if (wakeup->packet_len &&
12629 nla_put_u32(msg, len_attr, wakeup->packet_len))
12630 goto free_msg;
12631
12632 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12633 wakeup->packet))
12634 goto free_msg;
12635 }
12636
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012637 if (wakeup->net_detect &&
12638 cfg80211_net_detect_results(msg, wakeup))
12639 goto free_msg;
12640
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012641 nla_nest_end(msg, reasons);
12642 }
12643
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012644 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012645
Johannes Berg68eb5502013-11-19 15:19:38 +010012646 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012647 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012648 return;
12649
12650 free_msg:
12651 nlmsg_free(msg);
12652}
12653EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12654#endif
12655
Jouni Malinen3475b092012-11-16 22:49:57 +020012656void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12657 enum nl80211_tdls_operation oper,
12658 u16 reason_code, gfp_t gfp)
12659{
12660 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012661 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012662 struct sk_buff *msg;
12663 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012664
12665 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12666 reason_code);
12667
12668 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12669 if (!msg)
12670 return;
12671
12672 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12673 if (!hdr) {
12674 nlmsg_free(msg);
12675 return;
12676 }
12677
12678 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12679 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12680 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12681 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12682 (reason_code > 0 &&
12683 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12684 goto nla_put_failure;
12685
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012686 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012687
Johannes Berg68eb5502013-11-19 15:19:38 +010012688 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012689 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012690 return;
12691
12692 nla_put_failure:
12693 genlmsg_cancel(msg, hdr);
12694 nlmsg_free(msg);
12695}
12696EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12697
Jouni Malinen026331c2010-02-15 12:53:10 +020012698static int nl80211_netlink_notify(struct notifier_block * nb,
12699 unsigned long state,
12700 void *_notify)
12701{
12702 struct netlink_notify *notify = _notify;
12703 struct cfg80211_registered_device *rdev;
12704 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012705 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012706
12707 if (state != NETLINK_URELEASE)
12708 return NOTIFY_DONE;
12709
12710 rcu_read_lock();
12711
Johannes Berg5e760232011-11-04 11:18:17 +010012712 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012713 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012714 bool schedule_scan_stop = false;
12715 struct cfg80211_sched_scan_request *sched_scan_req =
12716 rcu_dereference(rdev->sched_scan_req);
12717
12718 if (sched_scan_req && notify->portid &&
12719 sched_scan_req->owner_nlportid == notify->portid)
12720 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010012721
12722 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012723 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012724
Johannes Berg78f22b62014-03-24 17:57:27 +010012725 if (wdev->owner_nlportid == notify->portid)
12726 schedule_destroy_work = true;
12727 }
12728
Ben Greear37c73b52012-10-26 14:49:25 -070012729 spin_lock_bh(&rdev->beacon_registrations_lock);
12730 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12731 list) {
12732 if (reg->nlportid == notify->portid) {
12733 list_del(&reg->list);
12734 kfree(reg);
12735 break;
12736 }
12737 }
12738 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012739
12740 if (schedule_destroy_work) {
12741 struct cfg80211_iface_destroy *destroy;
12742
12743 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12744 if (destroy) {
12745 destroy->nlportid = notify->portid;
12746 spin_lock(&rdev->destroy_list_lock);
12747 list_add(&destroy->list, &rdev->destroy_list);
12748 spin_unlock(&rdev->destroy_list_lock);
12749 schedule_work(&rdev->destroy_work);
12750 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012751 } else if (schedule_scan_stop) {
12752 sched_scan_req->owner_nlportid = 0;
12753
12754 if (rdev->ops->sched_scan_stop &&
12755 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
12756 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010012757 }
Johannes Berg5e760232011-11-04 11:18:17 +010012758 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012759
12760 rcu_read_unlock();
12761
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012762 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012763}
12764
12765static struct notifier_block nl80211_netlink_notifier = {
12766 .notifier_call = nl80211_netlink_notify,
12767};
12768
Jouni Malinen355199e2013-02-27 17:14:27 +020012769void cfg80211_ft_event(struct net_device *netdev,
12770 struct cfg80211_ft_event_params *ft_event)
12771{
12772 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012773 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012774 struct sk_buff *msg;
12775 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012776
12777 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12778
12779 if (!ft_event->target_ap)
12780 return;
12781
12782 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12783 if (!msg)
12784 return;
12785
12786 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012787 if (!hdr)
12788 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012789
Johannes Bergae917c92013-10-25 11:05:22 +020012790 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12791 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12792 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12793 goto out;
12794
12795 if (ft_event->ies &&
12796 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12797 goto out;
12798 if (ft_event->ric_ies &&
12799 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12800 ft_event->ric_ies))
12801 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012802
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012803 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012804
Johannes Berg68eb5502013-11-19 15:19:38 +010012805 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012806 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012807 return;
12808 out:
12809 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012810}
12811EXPORT_SYMBOL(cfg80211_ft_event);
12812
Arend van Spriel5de17982013-04-18 15:49:00 +020012813void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12814{
12815 struct cfg80211_registered_device *rdev;
12816 struct sk_buff *msg;
12817 void *hdr;
12818 u32 nlportid;
12819
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012820 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012821 if (!rdev->crit_proto_nlportid)
12822 return;
12823
12824 nlportid = rdev->crit_proto_nlportid;
12825 rdev->crit_proto_nlportid = 0;
12826
12827 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12828 if (!msg)
12829 return;
12830
12831 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12832 if (!hdr)
12833 goto nla_put_failure;
12834
12835 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12836 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12837 goto nla_put_failure;
12838
12839 genlmsg_end(msg, hdr);
12840
12841 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12842 return;
12843
12844 nla_put_failure:
12845 if (hdr)
12846 genlmsg_cancel(msg, hdr);
12847 nlmsg_free(msg);
12848
12849}
12850EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12851
Johannes Berg348baf02014-01-24 14:06:29 +010012852void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12853{
12854 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012855 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012856 struct sk_buff *msg;
12857 void *hdr;
12858
12859 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12860 if (!msg)
12861 return;
12862
12863 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12864 if (!hdr)
12865 goto out;
12866
12867 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12868 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12869 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12870 goto out;
12871
12872 genlmsg_end(msg, hdr);
12873
12874 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12875 NL80211_MCGRP_MLME, GFP_KERNEL);
12876 return;
12877 out:
12878 nlmsg_free(msg);
12879}
12880
Johannes Berg55682962007-09-20 13:09:35 -040012881/* initialisation/exit functions */
12882
12883int nl80211_init(void)
12884{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012885 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012886
Johannes Berg2a94fe42013-11-19 15:19:39 +010012887 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12888 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012889 if (err)
12890 return err;
12891
Jouni Malinen026331c2010-02-15 12:53:10 +020012892 err = netlink_register_notifier(&nl80211_netlink_notifier);
12893 if (err)
12894 goto err_out;
12895
Johannes Berg55682962007-09-20 13:09:35 -040012896 return 0;
12897 err_out:
12898 genl_unregister_family(&nl80211_fam);
12899 return err;
12900}
12901
12902void nl80211_exit(void)
12903{
Jouni Malinen026331c2010-02-15 12:53:10 +020012904 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012905 genl_unregister_family(&nl80211_fam);
12906}