blob: 543dd51342f04d036f928dc7f34887eefc8afd69 [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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-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 Berg7fee4772012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee4772012-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 Malinendc6382c2009-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 Berg2e161f72010-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 },
Ilan peer05050752015-03-04 00:32:06 -0500402 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400403};
404
Johannes Berge31b8212010-10-05 19:39:30 +0200405/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000406static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200407 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 [NL80211_KEY_IDX] = { .type = NLA_U8 },
409 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200410 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200411 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
412 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200413 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100414 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
415};
416
417/* policy for the key default flags */
418static const struct nla_policy
419nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
420 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
421 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200422};
423
Johannes Bergff1b6e62011-05-04 15:37:28 +0200424/* policy for WoWLAN attributes */
425static const struct nla_policy
426nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
427 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200431 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100435 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300436 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100437};
438
439static const struct nla_policy
440nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
441 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
442 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
443 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
444 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
445 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
446 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
448 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
449 },
450 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
451 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
452 },
453 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
454 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
455 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200456};
457
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700458/* policy for coalesce rule attributes */
459static const struct nla_policy
460nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
461 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
462 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
463 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
464};
465
Johannes Berge5497d72011-07-05 16:35:40 +0200466/* policy for GTK rekey offload attributes */
467static const struct nla_policy
468nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
469 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
470 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
471 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
472};
473
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300474static const struct nla_policy
475nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200476 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300477 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700478 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300479};
480
Johannes Berg97990a02013-04-19 01:02:55 +0200481static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
482 struct netlink_callback *cb,
483 struct cfg80211_registered_device **rdev,
484 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100485{
Johannes Berg67748892010-10-04 21:14:06 +0200486 int err;
487
Johannes Berg67748892010-10-04 21:14:06 +0200488 rtnl_lock();
489
Johannes Berg97990a02013-04-19 01:02:55 +0200490 if (!cb->args[0]) {
491 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
492 nl80211_fam.attrbuf, nl80211_fam.maxattr,
493 nl80211_policy);
494 if (err)
495 goto out_unlock;
496
497 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
498 nl80211_fam.attrbuf);
499 if (IS_ERR(*wdev)) {
500 err = PTR_ERR(*wdev);
501 goto out_unlock;
502 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800503 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200504 /* 0 is the first index - add 1 to parse only once */
505 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200506 cb->args[1] = (*wdev)->identifier;
507 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200508 /* subtract the 1 again here */
509 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200510 struct wireless_dev *tmp;
511
512 if (!wiphy) {
513 err = -ENODEV;
514 goto out_unlock;
515 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800516 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200517 *wdev = NULL;
518
Johannes Berg97990a02013-04-19 01:02:55 +0200519 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
520 if (tmp->identifier == cb->args[1]) {
521 *wdev = tmp;
522 break;
523 }
524 }
Johannes Berg97990a02013-04-19 01:02:55 +0200525
526 if (!*wdev) {
527 err = -ENODEV;
528 goto out_unlock;
529 }
Johannes Berg67748892010-10-04 21:14:06 +0200530 }
531
Johannes Berg67748892010-10-04 21:14:06 +0200532 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200533 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200534 rtnl_unlock();
535 return err;
536}
537
Johannes Berg97990a02013-04-19 01:02:55 +0200538static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200539{
Johannes Berg67748892010-10-04 21:14:06 +0200540 rtnl_unlock();
541}
542
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100543/* IE validation */
544static bool is_valid_ie_attr(const struct nlattr *attr)
545{
546 const u8 *pos;
547 int len;
548
549 if (!attr)
550 return true;
551
552 pos = nla_data(attr);
553 len = nla_len(attr);
554
555 while (len) {
556 u8 elemlen;
557
558 if (len < 2)
559 return false;
560 len -= 2;
561
562 elemlen = pos[1];
563 if (elemlen > len)
564 return false;
565
566 len -= elemlen;
567 pos += 2 + elemlen;
568 }
569
570 return true;
571}
572
Johannes Berg55682962007-09-20 13:09:35 -0400573/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000574static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400575 int flags, u8 cmd)
576{
577 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000578 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400579}
580
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400581static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100582 struct ieee80211_channel *chan,
583 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400584{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200585 /* Some channels must be completely excluded from the
586 * list to protect old user-space tools from breaking
587 */
588 if (!large && chan->flags &
589 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
590 return 0;
591
David S. Miller9360ffd2012-03-29 04:41:26 -0400592 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
593 chan->center_freq))
594 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400595
David S. Miller9360ffd2012-03-29 04:41:26 -0400596 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
597 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
598 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200599 if (chan->flags & IEEE80211_CHAN_NO_IR) {
600 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
601 goto nla_put_failure;
602 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
603 goto nla_put_failure;
604 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100605 if (chan->flags & IEEE80211_CHAN_RADAR) {
606 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
607 goto nla_put_failure;
608 if (large) {
609 u32 time;
610
611 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
612
613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
614 chan->dfs_state))
615 goto nla_put_failure;
616 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
617 time))
618 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100619 if (nla_put_u32(msg,
620 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
621 chan->dfs_cac_ms))
622 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100623 }
624 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400625
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100626 if (large) {
627 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
635 goto nla_put_failure;
636 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
638 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200639 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
641 goto nla_put_failure;
642 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
643 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
644 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200645 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
646 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
647 goto nla_put_failure;
648 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
649 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
650 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100651 }
652
David S. Miller9360ffd2012-03-29 04:41:26 -0400653 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
654 DBM_TO_MBM(chan->max_power)))
655 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400656
657 return 0;
658
659 nla_put_failure:
660 return -ENOBUFS;
661}
662
Johannes Berg55682962007-09-20 13:09:35 -0400663/* netlink command implementations */
664
Johannes Bergb9454e82009-07-08 13:29:08 +0200665struct key_parse {
666 struct key_params p;
667 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200668 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200669 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100670 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200671};
672
673static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
674{
675 struct nlattr *tb[NL80211_KEY_MAX + 1];
676 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
677 nl80211_key_policy);
678 if (err)
679 return err;
680
681 k->def = !!tb[NL80211_KEY_DEFAULT];
682 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
683
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100684 if (k->def) {
685 k->def_uni = true;
686 k->def_multi = true;
687 }
688 if (k->defmgmt)
689 k->def_multi = true;
690
Johannes Bergb9454e82009-07-08 13:29:08 +0200691 if (tb[NL80211_KEY_IDX])
692 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
693
694 if (tb[NL80211_KEY_DATA]) {
695 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
696 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
697 }
698
699 if (tb[NL80211_KEY_SEQ]) {
700 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
701 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
702 }
703
704 if (tb[NL80211_KEY_CIPHER])
705 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
706
Johannes Berge31b8212010-10-05 19:39:30 +0200707 if (tb[NL80211_KEY_TYPE]) {
708 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
709 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
710 return -EINVAL;
711 }
712
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100713 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
714 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100715 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
716 tb[NL80211_KEY_DEFAULT_TYPES],
717 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100718 if (err)
719 return err;
720
721 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
722 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
723 }
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 return 0;
726}
727
728static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
729{
730 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
731 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
732 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
733 }
734
735 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
736 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
737 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
738 }
739
740 if (info->attrs[NL80211_ATTR_KEY_IDX])
741 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
742
743 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
744 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
745
746 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
747 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
748
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100749 if (k->def) {
750 k->def_uni = true;
751 k->def_multi = true;
752 }
753 if (k->defmgmt)
754 k->def_multi = true;
755
Johannes Berge31b8212010-10-05 19:39:30 +0200756 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
757 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
758 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
759 return -EINVAL;
760 }
761
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100762 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
763 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
764 int err = nla_parse_nested(
765 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
766 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
767 nl80211_key_default_policy);
768 if (err)
769 return err;
770
771 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
772 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
773 }
774
Johannes Bergb9454e82009-07-08 13:29:08 +0200775 return 0;
776}
777
778static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
779{
780 int err;
781
782 memset(k, 0, sizeof(*k));
783 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200784 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200785
786 if (info->attrs[NL80211_ATTR_KEY])
787 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
788 else
789 err = nl80211_parse_key_old(info, k);
790
791 if (err)
792 return err;
793
794 if (k->def && k->defmgmt)
795 return -EINVAL;
796
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100797 if (k->defmgmt) {
798 if (k->def_uni || !k->def_multi)
799 return -EINVAL;
800 }
801
Johannes Bergb9454e82009-07-08 13:29:08 +0200802 if (k->idx != -1) {
803 if (k->defmgmt) {
804 if (k->idx < 4 || k->idx > 5)
805 return -EINVAL;
806 } else if (k->def) {
807 if (k->idx < 0 || k->idx > 3)
808 return -EINVAL;
809 } else {
810 if (k->idx < 0 || k->idx > 5)
811 return -EINVAL;
812 }
813 }
814
815 return 0;
816}
817
Johannes Bergfffd0932009-07-08 14:22:54 +0200818static struct cfg80211_cached_keys *
819nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530820 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200821{
822 struct key_parse parse;
823 struct nlattr *key;
824 struct cfg80211_cached_keys *result;
825 int rem, err, def = 0;
826
827 result = kzalloc(sizeof(*result), GFP_KERNEL);
828 if (!result)
829 return ERR_PTR(-ENOMEM);
830
831 result->def = -1;
832 result->defmgmt = -1;
833
834 nla_for_each_nested(key, keys, rem) {
835 memset(&parse, 0, sizeof(parse));
836 parse.idx = -1;
837
838 err = nl80211_parse_key_new(key, &parse);
839 if (err)
840 goto error;
841 err = -EINVAL;
842 if (!parse.p.key)
843 goto error;
844 if (parse.idx < 0 || parse.idx > 4)
845 goto error;
846 if (parse.def) {
847 if (def)
848 goto error;
849 def = 1;
850 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100851 if (!parse.def_uni || !parse.def_multi)
852 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200853 } else if (parse.defmgmt)
854 goto error;
855 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200856 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200857 if (err)
858 goto error;
859 result->params[parse.idx].cipher = parse.p.cipher;
860 result->params[parse.idx].key_len = parse.p.key_len;
861 result->params[parse.idx].key = result->data[parse.idx];
862 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530863
864 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
865 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
866 if (no_ht)
867 *no_ht = true;
868 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200869 }
870
871 return result;
872 error:
873 kfree(result);
874 return ERR_PTR(err);
875}
876
877static int nl80211_key_allowed(struct wireless_dev *wdev)
878{
879 ASSERT_WDEV_LOCK(wdev);
880
Johannes Bergfffd0932009-07-08 14:22:54 +0200881 switch (wdev->iftype) {
882 case NL80211_IFTYPE_AP:
883 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200884 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700885 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200886 break;
887 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200889 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200890 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200891 return -ENOLINK;
892 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100893 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100894 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100895 case NL80211_IFTYPE_MONITOR:
896 case NL80211_IFTYPE_P2P_DEVICE:
897 case NL80211_IFTYPE_WDS:
898 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200899 return -EINVAL;
900 }
901
902 return 0;
903}
904
Jouni Malinen664834d2014-01-15 00:01:44 +0200905static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
906 struct nlattr *tb)
907{
908 struct ieee80211_channel *chan;
909
910 if (tb == NULL)
911 return NULL;
912 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
913 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
914 return NULL;
915 return chan;
916}
917
Johannes Berg7527a782011-05-13 10:58:57 +0200918static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
919{
920 struct nlattr *nl_modes = nla_nest_start(msg, attr);
921 int i;
922
923 if (!nl_modes)
924 goto nla_put_failure;
925
926 i = 0;
927 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400928 if ((ifmodes & 1) && nla_put_flag(msg, i))
929 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200930 ifmodes >>= 1;
931 i++;
932 }
933
934 nla_nest_end(msg, nl_modes);
935 return 0;
936
937nla_put_failure:
938 return -ENOBUFS;
939}
940
941static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100942 struct sk_buff *msg,
943 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200944{
945 struct nlattr *nl_combis;
946 int i, j;
947
948 nl_combis = nla_nest_start(msg,
949 NL80211_ATTR_INTERFACE_COMBINATIONS);
950 if (!nl_combis)
951 goto nla_put_failure;
952
953 for (i = 0; i < wiphy->n_iface_combinations; i++) {
954 const struct ieee80211_iface_combination *c;
955 struct nlattr *nl_combi, *nl_limits;
956
957 c = &wiphy->iface_combinations[i];
958
959 nl_combi = nla_nest_start(msg, i + 1);
960 if (!nl_combi)
961 goto nla_put_failure;
962
963 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
964 if (!nl_limits)
965 goto nla_put_failure;
966
967 for (j = 0; j < c->n_limits; j++) {
968 struct nlattr *nl_limit;
969
970 nl_limit = nla_nest_start(msg, j + 1);
971 if (!nl_limit)
972 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400973 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
974 c->limits[j].max))
975 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200976 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
977 c->limits[j].types))
978 goto nla_put_failure;
979 nla_nest_end(msg, nl_limit);
980 }
981
982 nla_nest_end(msg, nl_limits);
983
David S. Miller9360ffd2012-03-29 04:41:26 -0400984 if (c->beacon_int_infra_match &&
985 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
986 goto nla_put_failure;
987 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
988 c->num_different_channels) ||
989 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
990 c->max_interfaces))
991 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100992 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200993 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
994 c->radar_detect_widths) ||
995 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
996 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100997 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200998
999 nla_nest_end(msg, nl_combi);
1000 }
1001
1002 nla_nest_end(msg, nl_combis);
1003
1004 return 0;
1005nla_put_failure:
1006 return -ENOBUFS;
1007}
1008
Johannes Berg3713b4e2013-02-14 16:19:38 +01001009#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001010static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1011 struct sk_buff *msg)
1012{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001013 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001014 struct nlattr *nl_tcp;
1015
1016 if (!tcp)
1017 return 0;
1018
1019 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1020 if (!nl_tcp)
1021 return -ENOBUFS;
1022
1023 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1024 tcp->data_payload_max))
1025 return -ENOBUFS;
1026
1027 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1028 tcp->data_payload_max))
1029 return -ENOBUFS;
1030
1031 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1032 return -ENOBUFS;
1033
1034 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1035 sizeof(*tcp->tok), tcp->tok))
1036 return -ENOBUFS;
1037
1038 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1039 tcp->data_interval_max))
1040 return -ENOBUFS;
1041
1042 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1043 tcp->wake_payload_max))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_tcp);
1047 return 0;
1048}
1049
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001052 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053{
1054 struct nlattr *nl_wowlan;
1055
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 return 0;
1058
1059 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1060 if (!nl_wowlan)
1061 return -ENOBUFS;
1062
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001066 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001067 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001068 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001069 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001070 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001071 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001073 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001074 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1079 return -ENOBUFS;
1080
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001081 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001082 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001083 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1084 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1085 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1086 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087 };
1088
1089 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1090 sizeof(pat), &pat))
1091 return -ENOBUFS;
1092 }
1093
Luciano Coelho75453cc2015-01-09 14:06:37 +02001094 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1095 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1096 rdev->wiphy.wowlan->max_nd_match_sets))
1097 return -ENOBUFS;
1098
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001099 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001100 return -ENOBUFS;
1101
Johannes Berg3713b4e2013-02-14 16:19:38 +01001102 nla_nest_end(msg, nl_wowlan);
1103
1104 return 0;
1105}
1106#endif
1107
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001108static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001109 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001110{
1111 struct nl80211_coalesce_rule_support rule;
1112
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001113 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001114 return 0;
1115
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001116 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1117 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1118 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1119 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1120 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1121 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001122
1123 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1124 return -ENOBUFS;
1125
1126 return 0;
1127}
1128
Johannes Berg3713b4e2013-02-14 16:19:38 +01001129static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1130 struct ieee80211_supported_band *sband)
1131{
1132 struct nlattr *nl_rates, *nl_rate;
1133 struct ieee80211_rate *rate;
1134 int i;
1135
1136 /* add HT info */
1137 if (sband->ht_cap.ht_supported &&
1138 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1139 sizeof(sband->ht_cap.mcs),
1140 &sband->ht_cap.mcs) ||
1141 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1142 sband->ht_cap.cap) ||
1143 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1144 sband->ht_cap.ampdu_factor) ||
1145 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1146 sband->ht_cap.ampdu_density)))
1147 return -ENOBUFS;
1148
1149 /* add VHT info */
1150 if (sband->vht_cap.vht_supported &&
1151 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1152 sizeof(sband->vht_cap.vht_mcs),
1153 &sband->vht_cap.vht_mcs) ||
1154 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1155 sband->vht_cap.cap)))
1156 return -ENOBUFS;
1157
1158 /* add bitrates */
1159 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1160 if (!nl_rates)
1161 return -ENOBUFS;
1162
1163 for (i = 0; i < sband->n_bitrates; i++) {
1164 nl_rate = nla_nest_start(msg, i);
1165 if (!nl_rate)
1166 return -ENOBUFS;
1167
1168 rate = &sband->bitrates[i];
1169 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1170 rate->bitrate))
1171 return -ENOBUFS;
1172 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1173 nla_put_flag(msg,
1174 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1175 return -ENOBUFS;
1176
1177 nla_nest_end(msg, nl_rate);
1178 }
1179
1180 nla_nest_end(msg, nl_rates);
1181
1182 return 0;
1183}
1184
1185static int
1186nl80211_send_mgmt_stypes(struct sk_buff *msg,
1187 const struct ieee80211_txrx_stypes *mgmt_stypes)
1188{
1189 u16 stypes;
1190 struct nlattr *nl_ftypes, *nl_ifs;
1191 enum nl80211_iftype ift;
1192 int i;
1193
1194 if (!mgmt_stypes)
1195 return 0;
1196
1197 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1198 if (!nl_ifs)
1199 return -ENOBUFS;
1200
1201 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1202 nl_ftypes = nla_nest_start(msg, ift);
1203 if (!nl_ftypes)
1204 return -ENOBUFS;
1205 i = 0;
1206 stypes = mgmt_stypes[ift].tx;
1207 while (stypes) {
1208 if ((stypes & 1) &&
1209 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1210 (i << 4) | IEEE80211_FTYPE_MGMT))
1211 return -ENOBUFS;
1212 stypes >>= 1;
1213 i++;
1214 }
1215 nla_nest_end(msg, nl_ftypes);
1216 }
1217
1218 nla_nest_end(msg, nl_ifs);
1219
1220 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1221 if (!nl_ifs)
1222 return -ENOBUFS;
1223
1224 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1225 nl_ftypes = nla_nest_start(msg, ift);
1226 if (!nl_ftypes)
1227 return -ENOBUFS;
1228 i = 0;
1229 stypes = mgmt_stypes[ift].rx;
1230 while (stypes) {
1231 if ((stypes & 1) &&
1232 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1233 (i << 4) | IEEE80211_FTYPE_MGMT))
1234 return -ENOBUFS;
1235 stypes >>= 1;
1236 i++;
1237 }
1238 nla_nest_end(msg, nl_ftypes);
1239 }
1240 nla_nest_end(msg, nl_ifs);
1241
1242 return 0;
1243}
1244
Johannes Berg86e8cf92013-06-19 10:57:22 +02001245struct nl80211_dump_wiphy_state {
1246 s64 filter_wiphy;
1247 long start;
1248 long split_start, band_start, chan_start;
1249 bool split;
1250};
1251
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001252static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001253 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001254 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001255 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001256{
1257 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001258 struct nlattr *nl_bands, *nl_band;
1259 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001260 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001261 enum ieee80211_band band;
1262 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001263 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001264 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001266 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001267
Johannes Berg3bb20552014-05-26 13:52:25 +02001268 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001269 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 return -ENOBUFS;
1271
Johannes Berg86e8cf92013-06-19 10:57:22 +02001272 if (WARN_ON(!state))
1273 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001274
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001276 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001278 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001280 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001281
Johannes Berg3bb20552014-05-26 13:52:25 +02001282 if (cmd != NL80211_CMD_NEW_WIPHY)
1283 goto finish;
1284
Johannes Berg86e8cf92013-06-19 10:57:22 +02001285 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 case 0:
1287 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001304 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001307 goto nla_put_failure;
1308
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1311 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001312 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1314 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1317 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001318 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001319 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1320 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1323 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001326 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001327 state->split_start++;
1328 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 break;
1330 case 1:
1331 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001332 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1333 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001334 goto nla_put_failure;
1335
Johannes Berg3713b4e2013-02-14 16:19:38 +01001336 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001338 goto nla_put_failure;
1339
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1342 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001343
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001345 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001347 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001349
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001350 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001352 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001354
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 if ((rdev->wiphy.available_antennas_tx ||
1356 rdev->wiphy.available_antennas_rx) &&
1357 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 u32 tx_ant = 0, rx_ant = 0;
1359 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001360 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 if (!res) {
1362 if (nla_put_u32(msg,
1363 NL80211_ATTR_WIPHY_ANTENNA_TX,
1364 tx_ant) ||
1365 nla_put_u32(msg,
1366 NL80211_ATTR_WIPHY_ANTENNA_RX,
1367 rx_ant))
1368 goto nla_put_failure;
1369 }
Johannes Bergee688b002008-01-24 19:38:39 +01001370 }
1371
Johannes Berg86e8cf92013-06-19 10:57:22 +02001372 state->split_start++;
1373 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 break;
1375 case 2:
1376 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001377 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001379 state->split_start++;
1380 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381 break;
1382 case 3:
1383 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1384 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001385 goto nla_put_failure;
1386
Johannes Berg86e8cf92013-06-19 10:57:22 +02001387 for (band = state->band_start;
1388 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001389 struct ieee80211_supported_band *sband;
1390
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001391 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392
1393 if (!sband)
1394 continue;
1395
1396 nl_band = nla_nest_start(msg, band);
1397 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001398 goto nla_put_failure;
1399
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001401 case 0:
1402 if (nl80211_send_band_rateinfo(msg, sband))
1403 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->chan_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 default:
1408 /* add frequencies */
1409 nl_freqs = nla_nest_start(
1410 msg, NL80211_BAND_ATTR_FREQS);
1411 if (!nl_freqs)
1412 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001413
Johannes Berg86e8cf92013-06-19 10:57:22 +02001414 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001415 i < sband->n_channels;
1416 i++) {
1417 nl_freq = nla_nest_start(msg, i);
1418 if (!nl_freq)
1419 goto nla_put_failure;
1420
1421 chan = &sband->channels[i];
1422
Johannes Berg86e8cf92013-06-19 10:57:22 +02001423 if (nl80211_msg_put_channel(
1424 msg, chan,
1425 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 goto nla_put_failure;
1427
1428 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 break;
1431 }
1432 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001433 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 nla_nest_end(msg, nl_freqs);
1437 }
1438
1439 nla_nest_end(msg, nl_band);
1440
Johannes Berg86e8cf92013-06-19 10:57:22 +02001441 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001443 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 band--;
1445 break;
1446 }
Johannes Bergee688b002008-01-24 19:38:39 +01001447 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001449
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001451 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001453 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001454
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001456 if (state->band_start == 0 && state->chan_start == 0)
1457 state->split_start++;
1458 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 break;
1460 case 4:
1461 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1462 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001463 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464
1465 i = 0;
1466#define CMD(op, n) \
1467 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001468 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 i++; \
1470 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1471 goto nla_put_failure; \
1472 } \
1473 } while (0)
1474
1475 CMD(add_virtual_intf, NEW_INTERFACE);
1476 CMD(change_virtual_intf, SET_INTERFACE);
1477 CMD(add_key, NEW_KEY);
1478 CMD(start_ap, START_AP);
1479 CMD(add_station, NEW_STATION);
1480 CMD(add_mpath, NEW_MPATH);
1481 CMD(update_mesh_config, SET_MESH_CONFIG);
1482 CMD(change_bss, SET_BSS);
1483 CMD(auth, AUTHENTICATE);
1484 CMD(assoc, ASSOCIATE);
1485 CMD(deauth, DEAUTHENTICATE);
1486 CMD(disassoc, DISASSOCIATE);
1487 CMD(join_ibss, JOIN_IBSS);
1488 CMD(join_mesh, JOIN_MESH);
1489 CMD(set_pmksa, SET_PMKSA);
1490 CMD(del_pmksa, DEL_PMKSA);
1491 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001492 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1494 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1495 CMD(mgmt_tx, FRAME);
1496 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 i++;
1499 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1500 goto nla_put_failure;
1501 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1503 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001504 i++;
1505 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1506 goto nla_put_failure;
1507 }
1508 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001509 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 CMD(tdls_mgmt, TDLS_MGMT);
1511 CMD(tdls_oper, TDLS_OPER);
1512 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001513 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 CMD(sched_scan_start, START_SCHED_SCAN);
1515 CMD(probe_client, PROBE_CLIENT);
1516 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 i++;
1519 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1520 goto nla_put_failure;
1521 }
1522 CMD(start_p2p_device, START_P2P_DEVICE);
1523 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001524#ifdef CONFIG_NL80211_TESTMODE
1525 CMD(testmode_cmd, TESTMODE);
1526#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001528 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1529 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001531 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001532 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001533 if (rdev->wiphy.features &
1534 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001535 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001536 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001537 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001538#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001539
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 i++;
1542 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001543 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001544 }
1545
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001546 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547 i++;
1548 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1549 goto nla_put_failure;
1550 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001551
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001553 state->split_start++;
1554 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001555 break;
1556 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001557 if (rdev->ops->remain_on_channel &&
1558 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559 nla_put_u32(msg,
1560 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001561 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001562 goto nla_put_failure;
1563
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001564 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1566 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001567
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1569 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001570 state->split_start++;
1571 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 break;
1573 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001574#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001577 state->split_start++;
1578 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001579 break;
1580#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582#endif
1583 case 7:
1584 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001586 goto nla_put_failure;
1587
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001589 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001591
Johannes Berg86e8cf92013-06-19 10:57:22 +02001592 state->split_start++;
1593 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 break;
1595 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 goto nla_put_failure;
1600
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001601 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001602 /*
1603 * We can only add the per-channel limit information if the
1604 * dump is split, otherwise it makes it too big. Therefore
1605 * only advertise it in that case.
1606 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001607 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001608 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1609 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 goto nla_put_failure;
1611
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1615 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 goto nla_put_failure;
1617
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001618 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1619 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001620 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 goto nla_put_failure;
1623
1624 /*
1625 * Any information below this point is only available to
1626 * applications that can deal with it being split. This
1627 * helps ensure that newly added capabilities don't break
1628 * older tools by overrunning their buffers.
1629 *
1630 * We still increment split_start so that in the split
1631 * case we'll continue with more data in the next round,
1632 * but break unconditionally so unsplit data stops here.
1633 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001634 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 break;
1636 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001638 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 rdev->wiphy.extended_capabilities_len,
1640 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001641 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 rdev->wiphy.extended_capabilities_len,
1643 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001644 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001647 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001648 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1649 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001650 goto nla_put_failure;
1651
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001652 state->split_start++;
1653 break;
1654 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001655 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001656 goto nla_put_failure;
1657
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001658 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001659 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1660 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1661 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001664 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001665 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001666 goto nla_put_failure;
1667
Johannes Bergad7e7182013-11-13 13:37:47 +01001668 state->split_start++;
1669 break;
1670 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001672 const struct nl80211_vendor_cmd_info *info;
1673 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001674
Johannes Berg567ffc32013-12-18 14:43:31 +01001675 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1676 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001677 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001678
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001679 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1680 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001681 if (nla_put(msg, i + 1, sizeof(*info), info))
1682 goto nla_put_failure;
1683 }
1684 nla_nest_end(msg, nested);
1685 }
1686
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001687 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001688 const struct nl80211_vendor_cmd_info *info;
1689 struct nlattr *nested;
1690
1691 nested = nla_nest_start(msg,
1692 NL80211_ATTR_VENDOR_EVENTS);
1693 if (!nested)
1694 goto nla_put_failure;
1695
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1697 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001698 if (nla_put(msg, i + 1, sizeof(*info), info))
1699 goto nla_put_failure;
1700 }
1701 nla_nest_end(msg, nested);
1702 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001703 state->split_start++;
1704 break;
1705 case 12:
1706 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1707 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1708 rdev->wiphy.max_num_csa_counters))
1709 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001710
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001711 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1712 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1713 goto nla_put_failure;
1714
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001715 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1716 sizeof(rdev->wiphy.ext_features),
1717 rdev->wiphy.ext_features))
1718 goto nla_put_failure;
1719
Johannes Berg3713b4e2013-02-14 16:19:38 +01001720 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001721 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001722 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001723 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001724 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001725 genlmsg_end(msg, hdr);
1726 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001727
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 Berg053c0952015-01-16 22:09:00 +01002409 genlmsg_end(msg, hdr);
2410 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002411
2412 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002413 genlmsg_cancel(msg, hdr);
2414 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002415}
2416
2417static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2418{
2419 int wp_idx = 0;
2420 int if_idx = 0;
2421 int wp_start = cb->args[0];
2422 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002423 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002424 struct wireless_dev *wdev;
2425
Johannes Berg5fe231e2013-05-08 21:45:15 +02002426 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002427 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2428 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002429 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002430 if (wp_idx < wp_start) {
2431 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002432 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002433 }
Johannes Berg55682962007-09-20 13:09:35 -04002434 if_idx = 0;
2435
Johannes Berg89a54e42012-06-15 14:33:17 +02002436 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002437 if (if_idx < if_start) {
2438 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002439 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002440 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002441 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002442 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002443 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002444 goto out;
2445 }
2446 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002447 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002448
2449 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002450 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002451 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002452 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002453
2454 cb->args[0] = wp_idx;
2455 cb->args[1] = if_idx;
2456
2457 return skb->len;
2458}
2459
2460static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2461{
2462 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002463 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002464 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002465
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002466 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002467 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002468 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002469
Eric W. Biederman15e47302012-09-07 20:12:54 +00002470 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002471 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002472 nlmsg_free(msg);
2473 return -ENOBUFS;
2474 }
Johannes Berg55682962007-09-20 13:09:35 -04002475
Johannes Berg134e6372009-07-10 09:51:34 +00002476 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002477}
2478
Michael Wu66f7ac52008-01-31 19:48:22 +01002479static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2480 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2481 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2482 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2483 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2484 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002485 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002486};
2487
2488static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2489{
2490 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2491 int flag;
2492
2493 *mntrflags = 0;
2494
2495 if (!nla)
2496 return -EINVAL;
2497
2498 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2499 nla, mntr_flags_policy))
2500 return -EINVAL;
2501
2502 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2503 if (flags[flag])
2504 *mntrflags |= (1<<flag);
2505
2506 return 0;
2507}
2508
Johannes Berg9bc383d2009-11-19 11:55:19 +01002509static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002510 struct net_device *netdev, u8 use_4addr,
2511 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002512{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002513 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002514 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002515 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002516 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002517 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002518
2519 switch (iftype) {
2520 case NL80211_IFTYPE_AP_VLAN:
2521 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2522 return 0;
2523 break;
2524 case NL80211_IFTYPE_STATION:
2525 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2526 return 0;
2527 break;
2528 default:
2529 break;
2530 }
2531
2532 return -EOPNOTSUPP;
2533}
2534
Johannes Berg55682962007-09-20 13:09:35 -04002535static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2536{
Johannes Berg4c476992010-10-04 21:36:35 +02002537 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002538 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002539 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002540 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002541 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002542 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002543 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002544
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002545 memset(&params, 0, sizeof(params));
2546
Johannes Berg04a773a2009-04-19 21:24:32 +02002547 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002548
Johannes Berg723b0382008-09-16 20:22:09 +02002549 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002550 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002551 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002552 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002553 if (ntype > NL80211_IFTYPE_MAX)
2554 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002555 }
2556
Johannes Berg92ffe052008-09-16 20:39:36 +02002557 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002558 struct wireless_dev *wdev = dev->ieee80211_ptr;
2559
Johannes Berg4c476992010-10-04 21:36:35 +02002560 if (ntype != NL80211_IFTYPE_MESH_POINT)
2561 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002562 if (netif_running(dev))
2563 return -EBUSY;
2564
2565 wdev_lock(wdev);
2566 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2567 IEEE80211_MAX_MESH_ID_LEN);
2568 wdev->mesh_id_up_len =
2569 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2570 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2571 wdev->mesh_id_up_len);
2572 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002573 }
2574
Felix Fietkau8b787642009-11-10 18:53:10 +01002575 if (info->attrs[NL80211_ATTR_4ADDR]) {
2576 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2577 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002578 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002579 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002580 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002581 } else {
2582 params.use_4addr = -1;
2583 }
2584
Johannes Berg92ffe052008-09-16 20:39:36 +02002585 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002586 if (ntype != NL80211_IFTYPE_MONITOR)
2587 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002588 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2589 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002590 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002591 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002592
2593 flags = &_flags;
2594 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002595 }
Johannes Berg3b858752009-03-12 09:55:09 +01002596
Luciano Coelho18003292013-08-29 13:26:57 +03002597 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002598 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2599 return -EOPNOTSUPP;
2600
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002601 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002602 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002603 else
2604 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002605
Johannes Berg9bc383d2009-11-19 11:55:19 +01002606 if (!err && params.use_4addr != -1)
2607 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2608
Johannes Berg55682962007-09-20 13:09:35 -04002609 return err;
2610}
2611
2612static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2613{
Johannes Berg4c476992010-10-04 21:36:35 +02002614 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002615 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002616 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002617 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002618 int err;
2619 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002620 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002621
Johannes Berg78f22b62014-03-24 17:57:27 +01002622 /* to avoid failing a new interface creation due to pending removal */
2623 cfg80211_destroy_ifaces(rdev);
2624
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002625 memset(&params, 0, sizeof(params));
2626
Johannes Berg55682962007-09-20 13:09:35 -04002627 if (!info->attrs[NL80211_ATTR_IFNAME])
2628 return -EINVAL;
2629
2630 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2631 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2632 if (type > NL80211_IFTYPE_MAX)
2633 return -EINVAL;
2634 }
2635
Johannes Berg79c97e92009-07-07 03:56:12 +02002636 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002637 !(rdev->wiphy.interface_modes & (1 << type)))
2638 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002639
Ben Greeare8f479b2014-10-22 12:23:05 -07002640 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2641 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2642 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002643 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2644 ETH_ALEN);
2645 if (!is_valid_ether_addr(params.macaddr))
2646 return -EADDRNOTAVAIL;
2647 }
2648
Johannes Berg9bc383d2009-11-19 11:55:19 +01002649 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002650 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002651 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002652 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002653 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002654 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002655
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002656 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2657 if (!msg)
2658 return -ENOMEM;
2659
Michael Wu66f7ac52008-01-31 19:48:22 +01002660 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2661 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2662 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002663
Luciano Coelho18003292013-08-29 13:26:57 +03002664 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002665 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2666 return -EOPNOTSUPP;
2667
Hila Gonene35e4d22012-06-27 17:19:42 +03002668 wdev = rdev_add_virtual_intf(rdev,
2669 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2670 type, err ? NULL : &flags, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002671 if (WARN_ON(!wdev)) {
2672 nlmsg_free(msg);
2673 return -EPROTO;
2674 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002675 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002676 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002677 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002678
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002679 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002680 wdev->owner_nlportid = info->snd_portid;
2681
Johannes Berg98104fde2012-06-16 00:19:54 +02002682 switch (type) {
2683 case NL80211_IFTYPE_MESH_POINT:
2684 if (!info->attrs[NL80211_ATTR_MESH_ID])
2685 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002686 wdev_lock(wdev);
2687 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2688 IEEE80211_MAX_MESH_ID_LEN);
2689 wdev->mesh_id_up_len =
2690 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2691 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2692 wdev->mesh_id_up_len);
2693 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002694 break;
2695 case NL80211_IFTYPE_P2P_DEVICE:
2696 /*
2697 * P2P Device doesn't have a netdev, so doesn't go
2698 * through the netdev notifier and must be added here
2699 */
2700 mutex_init(&wdev->mtx);
2701 INIT_LIST_HEAD(&wdev->event_list);
2702 spin_lock_init(&wdev->event_lock);
2703 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2704 spin_lock_init(&wdev->mgmt_registrations_lock);
2705
Johannes Berg98104fde2012-06-16 00:19:54 +02002706 wdev->identifier = ++rdev->wdev_id;
2707 list_add_rcu(&wdev->list, &rdev->wdev_list);
2708 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002709 break;
2710 default:
2711 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002712 }
2713
Eric W. Biederman15e47302012-09-07 20:12:54 +00002714 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002715 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002716 nlmsg_free(msg);
2717 return -ENOBUFS;
2718 }
2719
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002720 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2721 if (event) {
2722 if (nl80211_send_iface(event, 0, 0, 0,
2723 rdev, wdev, false) < 0) {
2724 nlmsg_free(event);
2725 goto out;
2726 }
2727
2728 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2729 event, 0, NL80211_MCGRP_CONFIG,
2730 GFP_KERNEL);
2731 }
2732
2733out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002734 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002735}
2736
2737static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2738{
Johannes Berg4c476992010-10-04 21:36:35 +02002739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002740 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002741 struct sk_buff *msg;
2742 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002743
Johannes Berg4c476992010-10-04 21:36:35 +02002744 if (!rdev->ops->del_virtual_intf)
2745 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002746
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002747 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2748 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2749 nlmsg_free(msg);
2750 msg = NULL;
2751 }
2752
Johannes Berg84efbb82012-06-16 00:00:26 +02002753 /*
2754 * If we remove a wireless device without a netdev then clear
2755 * user_ptr[1] so that nl80211_post_doit won't dereference it
2756 * to check if it needs to do dev_put(). Otherwise it crashes
2757 * since the wdev has been freed, unlike with a netdev where
2758 * we need the dev_put() for the netdev to really be freed.
2759 */
2760 if (!wdev->netdev)
2761 info->user_ptr[1] = NULL;
2762
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002763 status = rdev_del_virtual_intf(rdev, wdev);
2764 if (status >= 0 && msg)
2765 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2766 msg, 0, NL80211_MCGRP_CONFIG,
2767 GFP_KERNEL);
2768 else
2769 nlmsg_free(msg);
2770
2771 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002772}
2773
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002774static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2775{
2776 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2777 struct net_device *dev = info->user_ptr[1];
2778 u16 noack_map;
2779
2780 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2781 return -EINVAL;
2782
2783 if (!rdev->ops->set_noack_map)
2784 return -EOPNOTSUPP;
2785
2786 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2787
Hila Gonene35e4d22012-06-27 17:19:42 +03002788 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002789}
2790
Johannes Berg41ade002007-12-19 02:03:29 +01002791struct get_key_cookie {
2792 struct sk_buff *msg;
2793 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002794 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002795};
2796
2797static void get_key_callback(void *c, struct key_params *params)
2798{
Johannes Bergb9454e82009-07-08 13:29:08 +02002799 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002800 struct get_key_cookie *cookie = c;
2801
David S. Miller9360ffd2012-03-29 04:41:26 -04002802 if ((params->key &&
2803 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2804 params->key_len, params->key)) ||
2805 (params->seq &&
2806 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2807 params->seq_len, params->seq)) ||
2808 (params->cipher &&
2809 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2810 params->cipher)))
2811 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002812
Johannes Bergb9454e82009-07-08 13:29:08 +02002813 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2814 if (!key)
2815 goto nla_put_failure;
2816
David S. Miller9360ffd2012-03-29 04:41:26 -04002817 if ((params->key &&
2818 nla_put(cookie->msg, NL80211_KEY_DATA,
2819 params->key_len, params->key)) ||
2820 (params->seq &&
2821 nla_put(cookie->msg, NL80211_KEY_SEQ,
2822 params->seq_len, params->seq)) ||
2823 (params->cipher &&
2824 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2825 params->cipher)))
2826 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002827
David S. Miller9360ffd2012-03-29 04:41:26 -04002828 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2829 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002830
2831 nla_nest_end(cookie->msg, key);
2832
Johannes Berg41ade002007-12-19 02:03:29 +01002833 return;
2834 nla_put_failure:
2835 cookie->error = 1;
2836}
2837
2838static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2839{
Johannes Berg4c476992010-10-04 21:36:35 +02002840 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002841 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002842 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002843 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002844 const u8 *mac_addr = NULL;
2845 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002846 struct get_key_cookie cookie = {
2847 .error = 0,
2848 };
2849 void *hdr;
2850 struct sk_buff *msg;
2851
2852 if (info->attrs[NL80211_ATTR_KEY_IDX])
2853 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2854
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002855 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002856 return -EINVAL;
2857
2858 if (info->attrs[NL80211_ATTR_MAC])
2859 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2860
Johannes Berge31b8212010-10-05 19:39:30 +02002861 pairwise = !!mac_addr;
2862 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2863 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2864 if (kt >= NUM_NL80211_KEYTYPES)
2865 return -EINVAL;
2866 if (kt != NL80211_KEYTYPE_GROUP &&
2867 kt != NL80211_KEYTYPE_PAIRWISE)
2868 return -EINVAL;
2869 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2870 }
2871
Johannes Berg4c476992010-10-04 21:36:35 +02002872 if (!rdev->ops->get_key)
2873 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002874
Johannes Berg0fa7b392015-01-23 11:10:12 +01002875 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2876 return -ENOENT;
2877
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002878 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002879 if (!msg)
2880 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002881
Eric W. Biederman15e47302012-09-07 20:12:54 +00002882 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002883 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002884 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002885 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002886
2887 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002888 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002889
David S. Miller9360ffd2012-03-29 04:41:26 -04002890 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2891 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2892 goto nla_put_failure;
2893 if (mac_addr &&
2894 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2895 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002896
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
Johannes Berg0fa7b392015-01-23 11:10:12 +01003067 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003068 !(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 Berg053c0952015-01-16 22:09:00 +01003843 genlmsg_end(msg, hdr);
3844 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003845
3846 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003847 genlmsg_cancel(msg, hdr);
3848 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003849}
3850
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003851static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003852 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003853{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003854 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003855 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003856 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003857 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003858 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003859 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003860
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003861 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003862 if (err)
3863 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003864
Johannes Berg97990a02013-04-19 01:02:55 +02003865 if (!wdev->netdev) {
3866 err = -EINVAL;
3867 goto out_err;
3868 }
3869
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003870 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003871 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003872 goto out_err;
3873 }
3874
Johannes Bergbba95fe2008-07-29 13:22:51 +02003875 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003876 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003877 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003878 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003879 if (err == -ENOENT)
3880 break;
3881 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003882 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003883
Johannes Bergcf5ead82014-11-14 17:14:00 +01003884 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003885 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003886 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003887 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003888 &sinfo) < 0)
3889 goto out;
3890
3891 sta_idx++;
3892 }
3893
3894
3895 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003896 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003897 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003898 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003899 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003900
3901 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003902}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003903
Johannes Berg5727ef12007-12-19 02:03:34 +01003904static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3905{
Johannes Berg4c476992010-10-04 21:36:35 +02003906 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3907 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003908 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003909 struct sk_buff *msg;
3910 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003911 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003912
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003913 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003914
3915 if (!info->attrs[NL80211_ATTR_MAC])
3916 return -EINVAL;
3917
3918 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3919
Johannes Berg4c476992010-10-04 21:36:35 +02003920 if (!rdev->ops->get_station)
3921 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003922
Hila Gonene35e4d22012-06-27 17:19:42 +03003923 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003924 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003925 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003926
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003928 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003929 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003930
Johannes Bergcf5ead82014-11-14 17:14:00 +01003931 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3932 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003933 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003934 nlmsg_free(msg);
3935 return -ENOBUFS;
3936 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003937
Johannes Berg4c476992010-10-04 21:36:35 +02003938 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003939}
3940
Johannes Berg77ee7c82013-02-15 00:48:33 +01003941int cfg80211_check_station_change(struct wiphy *wiphy,
3942 struct station_parameters *params,
3943 enum cfg80211_station_type statype)
3944{
3945 if (params->listen_interval != -1)
3946 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003947 if (params->aid &&
3948 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003949 return -EINVAL;
3950
3951 /* When you run into this, adjust the code below for the new flag */
3952 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3953
3954 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003955 case CFG80211_STA_MESH_PEER_KERNEL:
3956 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003957 /*
3958 * No ignoring the TDLS flag here -- the userspace mesh
3959 * code doesn't have the bug of including TDLS in the
3960 * mask everywhere.
3961 */
3962 if (params->sta_flags_mask &
3963 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3964 BIT(NL80211_STA_FLAG_MFP) |
3965 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3966 return -EINVAL;
3967 break;
3968 case CFG80211_STA_TDLS_PEER_SETUP:
3969 case CFG80211_STA_TDLS_PEER_ACTIVE:
3970 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3971 return -EINVAL;
3972 /* ignore since it can't change */
3973 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3974 break;
3975 default:
3976 /* disallow mesh-specific things */
3977 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3978 return -EINVAL;
3979 if (params->local_pm)
3980 return -EINVAL;
3981 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3982 return -EINVAL;
3983 }
3984
3985 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3986 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3987 /* TDLS can't be set, ... */
3988 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3989 return -EINVAL;
3990 /*
3991 * ... but don't bother the driver with it. This works around
3992 * a hostapd/wpa_supplicant issue -- it always includes the
3993 * TLDS_PEER flag in the mask even for AP mode.
3994 */
3995 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3996 }
3997
3998 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3999 /* reject other things that can't change */
4000 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4001 return -EINVAL;
4002 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4003 return -EINVAL;
4004 if (params->supported_rates)
4005 return -EINVAL;
4006 if (params->ext_capab || params->ht_capa || params->vht_capa)
4007 return -EINVAL;
4008 }
4009
4010 if (statype != CFG80211_STA_AP_CLIENT) {
4011 if (params->vlan)
4012 return -EINVAL;
4013 }
4014
4015 switch (statype) {
4016 case CFG80211_STA_AP_MLME_CLIENT:
4017 /* Use this only for authorizing/unauthorizing a station */
4018 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4019 return -EOPNOTSUPP;
4020 break;
4021 case CFG80211_STA_AP_CLIENT:
4022 /* accept only the listed bits */
4023 if (params->sta_flags_mask &
4024 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4025 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4026 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4027 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4028 BIT(NL80211_STA_FLAG_WME) |
4029 BIT(NL80211_STA_FLAG_MFP)))
4030 return -EINVAL;
4031
4032 /* but authenticated/associated only if driver handles it */
4033 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4034 params->sta_flags_mask &
4035 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4036 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4037 return -EINVAL;
4038 break;
4039 case CFG80211_STA_IBSS:
4040 case CFG80211_STA_AP_STA:
4041 /* reject any changes other than AUTHORIZED */
4042 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4043 return -EINVAL;
4044 break;
4045 case CFG80211_STA_TDLS_PEER_SETUP:
4046 /* reject any changes other than AUTHORIZED or WME */
4047 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4048 BIT(NL80211_STA_FLAG_WME)))
4049 return -EINVAL;
4050 /* force (at least) rates when authorizing */
4051 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4052 !params->supported_rates)
4053 return -EINVAL;
4054 break;
4055 case CFG80211_STA_TDLS_PEER_ACTIVE:
4056 /* reject any changes */
4057 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004058 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004059 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4060 return -EINVAL;
4061 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004062 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004063 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4064 return -EINVAL;
4065 break;
4066 }
4067
4068 return 0;
4069}
4070EXPORT_SYMBOL(cfg80211_check_station_change);
4071
Johannes Berg5727ef12007-12-19 02:03:34 +01004072/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004073 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004074 */
Johannes Berg80b99892011-11-18 16:23:01 +01004075static struct net_device *get_vlan(struct genl_info *info,
4076 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004077{
Johannes Berg463d0182009-07-14 00:33:35 +02004078 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004079 struct net_device *v;
4080 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004081
Johannes Berg80b99892011-11-18 16:23:01 +01004082 if (!vlanattr)
4083 return NULL;
4084
4085 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4086 if (!v)
4087 return ERR_PTR(-ENODEV);
4088
4089 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4090 ret = -EINVAL;
4091 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004092 }
Johannes Berg80b99892011-11-18 16:23:01 +01004093
Johannes Berg77ee7c82013-02-15 00:48:33 +01004094 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4095 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4096 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4097 ret = -EINVAL;
4098 goto error;
4099 }
4100
Johannes Berg80b99892011-11-18 16:23:01 +01004101 if (!netif_running(v)) {
4102 ret = -ENETDOWN;
4103 goto error;
4104 }
4105
4106 return v;
4107 error:
4108 dev_put(v);
4109 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004110}
4111
Johannes Berg94e860f2014-01-20 23:58:15 +01004112static const struct nla_policy
4113nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004114 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4115 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4116};
4117
Johannes Bergff276692013-02-15 00:09:01 +01004118static int nl80211_parse_sta_wme(struct genl_info *info,
4119 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004120{
Jouni Malinendf881292013-02-14 21:10:54 +02004121 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4122 struct nlattr *nla;
4123 int err;
4124
Jouni Malinendf881292013-02-14 21:10:54 +02004125 /* parse WME attributes if present */
4126 if (!info->attrs[NL80211_ATTR_STA_WME])
4127 return 0;
4128
4129 nla = info->attrs[NL80211_ATTR_STA_WME];
4130 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4131 nl80211_sta_wme_policy);
4132 if (err)
4133 return err;
4134
4135 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4136 params->uapsd_queues = nla_get_u8(
4137 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4138 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4139 return -EINVAL;
4140
4141 if (tb[NL80211_STA_WME_MAX_SP])
4142 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4143
4144 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4145 return -EINVAL;
4146
4147 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4148
4149 return 0;
4150}
4151
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304152static int nl80211_parse_sta_channel_info(struct genl_info *info,
4153 struct station_parameters *params)
4154{
4155 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4156 params->supported_channels =
4157 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4158 params->supported_channels_len =
4159 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4160 /*
4161 * Need to include at least one (first channel, number of
4162 * channels) tuple for each subband, and must have proper
4163 * tuples for the rest of the data as well.
4164 */
4165 if (params->supported_channels_len < 2)
4166 return -EINVAL;
4167 if (params->supported_channels_len % 2)
4168 return -EINVAL;
4169 }
4170
4171 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4172 params->supported_oper_classes =
4173 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4174 params->supported_oper_classes_len =
4175 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4176 /*
4177 * The value of the Length field of the Supported Operating
4178 * Classes element is between 2 and 253.
4179 */
4180 if (params->supported_oper_classes_len < 2 ||
4181 params->supported_oper_classes_len > 253)
4182 return -EINVAL;
4183 }
4184 return 0;
4185}
4186
Johannes Bergff276692013-02-15 00:09:01 +01004187static int nl80211_set_station_tdls(struct genl_info *info,
4188 struct station_parameters *params)
4189{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304190 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004191 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004192 if (info->attrs[NL80211_ATTR_PEER_AID])
4193 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004194 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4195 params->ht_capa =
4196 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4197 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4198 params->vht_capa =
4199 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4200
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304201 err = nl80211_parse_sta_channel_info(info, params);
4202 if (err)
4203 return err;
4204
Johannes Bergff276692013-02-15 00:09:01 +01004205 return nl80211_parse_sta_wme(info, params);
4206}
4207
Johannes Berg5727ef12007-12-19 02:03:34 +01004208static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4209{
Johannes Berg4c476992010-10-04 21:36:35 +02004210 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004211 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004212 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004213 u8 *mac_addr;
4214 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004215
4216 memset(&params, 0, sizeof(params));
4217
4218 params.listen_interval = -1;
4219
Johannes Berg77ee7c82013-02-15 00:48:33 +01004220 if (!rdev->ops->change_station)
4221 return -EOPNOTSUPP;
4222
Johannes Berg5727ef12007-12-19 02:03:34 +01004223 if (info->attrs[NL80211_ATTR_STA_AID])
4224 return -EINVAL;
4225
4226 if (!info->attrs[NL80211_ATTR_MAC])
4227 return -EINVAL;
4228
4229 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4230
4231 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4232 params.supported_rates =
4233 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4234 params.supported_rates_len =
4235 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4236 }
4237
Jouni Malinen9d62a982013-02-14 21:10:13 +02004238 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4239 params.capability =
4240 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4241 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4242 }
4243
4244 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4245 params.ext_capab =
4246 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4247 params.ext_capab_len =
4248 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4249 }
4250
Jouni Malinendf881292013-02-14 21:10:54 +02004251 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004252 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004253
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004254 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004255 return -EINVAL;
4256
Johannes Bergf8bacc22013-02-14 23:27:01 +01004257 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004258 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004259 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4260 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4261 return -EINVAL;
4262 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004263
Johannes Bergf8bacc22013-02-14 23:27:01 +01004264 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004265 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004266 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4267 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4268 return -EINVAL;
4269 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4270 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004271
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004272 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4273 enum nl80211_mesh_power_mode pm = nla_get_u32(
4274 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4275
4276 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4277 pm > NL80211_MESH_POWER_MAX)
4278 return -EINVAL;
4279
4280 params.local_pm = pm;
4281 }
4282
Johannes Berg77ee7c82013-02-15 00:48:33 +01004283 /* Include parameters for TDLS peer (will check later) */
4284 err = nl80211_set_station_tdls(info, &params);
4285 if (err)
4286 return err;
4287
4288 params.vlan = get_vlan(info, rdev);
4289 if (IS_ERR(params.vlan))
4290 return PTR_ERR(params.vlan);
4291
Johannes Berga97f4422009-06-18 17:23:43 +02004292 switch (dev->ieee80211_ptr->iftype) {
4293 case NL80211_IFTYPE_AP:
4294 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004295 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004296 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004297 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004298 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004299 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004300 break;
4301 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004302 err = -EOPNOTSUPP;
4303 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004304 }
4305
Johannes Berg77ee7c82013-02-15 00:48:33 +01004306 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004307 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004308
Johannes Berg77ee7c82013-02-15 00:48:33 +01004309 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004310 if (params.vlan)
4311 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004312
Johannes Berg5727ef12007-12-19 02:03:34 +01004313 return err;
4314}
4315
4316static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4317{
Johannes Berg4c476992010-10-04 21:36:35 +02004318 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004319 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004320 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004321 struct station_parameters params;
4322 u8 *mac_addr = NULL;
4323
4324 memset(&params, 0, sizeof(params));
4325
Johannes Berg984c3112013-02-14 23:43:25 +01004326 if (!rdev->ops->add_station)
4327 return -EOPNOTSUPP;
4328
Johannes Berg5727ef12007-12-19 02:03:34 +01004329 if (!info->attrs[NL80211_ATTR_MAC])
4330 return -EINVAL;
4331
Johannes Berg5727ef12007-12-19 02:03:34 +01004332 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4333 return -EINVAL;
4334
4335 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4336 return -EINVAL;
4337
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004338 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4339 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004340 return -EINVAL;
4341
Johannes Berg5727ef12007-12-19 02:03:34 +01004342 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4343 params.supported_rates =
4344 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4345 params.supported_rates_len =
4346 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4347 params.listen_interval =
4348 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004349
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004350 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004351 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004352 else
4353 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004354 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4355 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004356
Jouni Malinen9d62a982013-02-14 21:10:13 +02004357 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4358 params.capability =
4359 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4360 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4361 }
4362
4363 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4364 params.ext_capab =
4365 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4366 params.ext_capab_len =
4367 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4368 }
4369
Jouni Malinen36aedc92008-08-25 11:58:58 +03004370 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4371 params.ht_capa =
4372 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004373
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004374 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4375 params.vht_capa =
4376 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4377
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004378 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4379 params.opmode_notif_used = true;
4380 params.opmode_notif =
4381 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4382 }
4383
Johannes Bergf8bacc22013-02-14 23:27:01 +01004384 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004385 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004386 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4387 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4388 return -EINVAL;
4389 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004390
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304391 err = nl80211_parse_sta_channel_info(info, &params);
4392 if (err)
4393 return err;
4394
Johannes Bergff276692013-02-15 00:09:01 +01004395 err = nl80211_parse_sta_wme(info, &params);
4396 if (err)
4397 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004398
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004399 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004400 return -EINVAL;
4401
Johannes Berg77ee7c82013-02-15 00:48:33 +01004402 /* When you run into this, adjust the code below for the new flag */
4403 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4404
Johannes Bergbdd90d52011-12-14 12:20:27 +01004405 switch (dev->ieee80211_ptr->iftype) {
4406 case NL80211_IFTYPE_AP:
4407 case NL80211_IFTYPE_AP_VLAN:
4408 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004409 /* ignore WME attributes if iface/sta is not capable */
4410 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4411 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4412 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004413
Johannes Bergbdd90d52011-12-14 12:20:27 +01004414 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004415 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4416 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004417 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004418 /* but don't bother the driver with it */
4419 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004420
Johannes Bergd582cff2012-10-26 17:53:44 +02004421 /* allow authenticated/associated only if driver handles it */
4422 if (!(rdev->wiphy.features &
4423 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4424 params.sta_flags_mask &
4425 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4426 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4427 return -EINVAL;
4428
Johannes Bergbdd90d52011-12-14 12:20:27 +01004429 /* must be last in here for error handling */
4430 params.vlan = get_vlan(info, rdev);
4431 if (IS_ERR(params.vlan))
4432 return PTR_ERR(params.vlan);
4433 break;
4434 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004435 /* ignore uAPSD data */
4436 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4437
Johannes Bergd582cff2012-10-26 17:53:44 +02004438 /* associated is disallowed */
4439 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4440 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004441 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004442 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4443 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004444 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004445 break;
4446 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004447 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004448 /* ignore uAPSD data */
4449 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4450
Johannes Berg77ee7c82013-02-15 00:48:33 +01004451 /* these are disallowed */
4452 if (params.sta_flags_mask &
4453 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4454 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004455 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004456 /* Only TDLS peers can be added */
4457 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4458 return -EINVAL;
4459 /* Can only add if TDLS ... */
4460 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4461 return -EOPNOTSUPP;
4462 /* ... with external setup is supported */
4463 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4464 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004465 /*
4466 * Older wpa_supplicant versions always mark the TDLS peer
4467 * as authorized, but it shouldn't yet be.
4468 */
4469 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004470 break;
4471 default:
4472 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004473 }
4474
Johannes Bergbdd90d52011-12-14 12:20:27 +01004475 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004476
Hila Gonene35e4d22012-06-27 17:19:42 +03004477 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004478
Johannes Berg5727ef12007-12-19 02:03:34 +01004479 if (params.vlan)
4480 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004481 return err;
4482}
4483
4484static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4485{
Johannes Berg4c476992010-10-04 21:36:35 +02004486 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4487 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004488 struct station_del_parameters params;
4489
4490 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004491
4492 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004493 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004494
Johannes Berge80cf852009-05-11 14:43:13 +02004495 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004496 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004497 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004498 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4499 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004500
Johannes Berg4c476992010-10-04 21:36:35 +02004501 if (!rdev->ops->del_station)
4502 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004503
Jouni Malinen98856862014-10-20 13:20:45 +03004504 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4505 params.subtype =
4506 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4507 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4508 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4509 return -EINVAL;
4510 } else {
4511 /* Default to Deauthentication frame */
4512 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4513 }
4514
4515 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4516 params.reason_code =
4517 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4518 if (params.reason_code == 0)
4519 return -EINVAL; /* 0 is reserved */
4520 } else {
4521 /* Default to reason code 2 */
4522 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4523 }
4524
Jouni Malinen89c771e2014-10-10 20:52:40 +03004525 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004526}
4527
Eric W. Biederman15e47302012-09-07 20:12:54 +00004528static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004529 int flags, struct net_device *dev,
4530 u8 *dst, u8 *next_hop,
4531 struct mpath_info *pinfo)
4532{
4533 void *hdr;
4534 struct nlattr *pinfoattr;
4535
Henning Rogge1ef4c852014-11-04 16:14:58 +01004536 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004537 if (!hdr)
4538 return -1;
4539
David S. Miller9360ffd2012-03-29 04:41:26 -04004540 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4541 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4542 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4543 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4544 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004545
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004546 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4547 if (!pinfoattr)
4548 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004549 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4550 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4551 pinfo->frame_qlen))
4552 goto nla_put_failure;
4553 if (((pinfo->filled & MPATH_INFO_SN) &&
4554 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4555 ((pinfo->filled & MPATH_INFO_METRIC) &&
4556 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4557 pinfo->metric)) ||
4558 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4559 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4560 pinfo->exptime)) ||
4561 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4562 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4563 pinfo->flags)) ||
4564 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4565 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4566 pinfo->discovery_timeout)) ||
4567 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4568 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4569 pinfo->discovery_retries)))
4570 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004571
4572 nla_nest_end(msg, pinfoattr);
4573
Johannes Berg053c0952015-01-16 22:09:00 +01004574 genlmsg_end(msg, hdr);
4575 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004576
4577 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004578 genlmsg_cancel(msg, hdr);
4579 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004580}
4581
4582static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004583 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004584{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004585 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004586 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004587 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004588 u8 dst[ETH_ALEN];
4589 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004590 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004591 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004592
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004593 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004594 if (err)
4595 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004596
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004597 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004598 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004599 goto out_err;
4600 }
4601
Johannes Berg97990a02013-04-19 01:02:55 +02004602 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004603 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004604 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004605 }
4606
Johannes Bergbba95fe2008-07-29 13:22:51 +02004607 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004608 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004609 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004610 if (err == -ENOENT)
4611 break;
4612 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004613 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004614
Eric W. Biederman15e47302012-09-07 20:12:54 +00004615 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004616 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004617 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004618 &pinfo) < 0)
4619 goto out;
4620
4621 path_idx++;
4622 }
4623
4624
4625 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004626 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004627 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004628 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004629 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004630 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004631}
4632
4633static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4634{
Johannes Berg4c476992010-10-04 21:36:35 +02004635 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004636 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004637 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004638 struct mpath_info pinfo;
4639 struct sk_buff *msg;
4640 u8 *dst = NULL;
4641 u8 next_hop[ETH_ALEN];
4642
4643 memset(&pinfo, 0, sizeof(pinfo));
4644
4645 if (!info->attrs[NL80211_ATTR_MAC])
4646 return -EINVAL;
4647
4648 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4649
Johannes Berg4c476992010-10-04 21:36:35 +02004650 if (!rdev->ops->get_mpath)
4651 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004652
Johannes Berg4c476992010-10-04 21:36:35 +02004653 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4654 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004655
Hila Gonene35e4d22012-06-27 17:19:42 +03004656 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004657 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004658 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004659
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004660 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004661 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004662 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004663
Eric W. Biederman15e47302012-09-07 20:12:54 +00004664 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004665 dev, dst, next_hop, &pinfo) < 0) {
4666 nlmsg_free(msg);
4667 return -ENOBUFS;
4668 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004669
Johannes Berg4c476992010-10-04 21:36:35 +02004670 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004671}
4672
4673static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4674{
Johannes Berg4c476992010-10-04 21:36:35 +02004675 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4676 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004677 u8 *dst = NULL;
4678 u8 *next_hop = NULL;
4679
4680 if (!info->attrs[NL80211_ATTR_MAC])
4681 return -EINVAL;
4682
4683 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4684 return -EINVAL;
4685
4686 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4687 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4688
Johannes Berg4c476992010-10-04 21:36:35 +02004689 if (!rdev->ops->change_mpath)
4690 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004691
Johannes Berg4c476992010-10-04 21:36:35 +02004692 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4693 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004694
Hila Gonene35e4d22012-06-27 17:19:42 +03004695 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004696}
Johannes Berg4c476992010-10-04 21:36:35 +02004697
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004698static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4699{
Johannes Berg4c476992010-10-04 21:36:35 +02004700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4701 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004702 u8 *dst = NULL;
4703 u8 *next_hop = NULL;
4704
4705 if (!info->attrs[NL80211_ATTR_MAC])
4706 return -EINVAL;
4707
4708 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4709 return -EINVAL;
4710
4711 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4712 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4713
Johannes Berg4c476992010-10-04 21:36:35 +02004714 if (!rdev->ops->add_mpath)
4715 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004716
Johannes Berg4c476992010-10-04 21:36:35 +02004717 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4718 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004719
Hila Gonene35e4d22012-06-27 17:19:42 +03004720 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004721}
4722
4723static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4724{
Johannes Berg4c476992010-10-04 21:36:35 +02004725 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4726 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004727 u8 *dst = NULL;
4728
4729 if (info->attrs[NL80211_ATTR_MAC])
4730 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4731
Johannes Berg4c476992010-10-04 21:36:35 +02004732 if (!rdev->ops->del_mpath)
4733 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004734
Hila Gonene35e4d22012-06-27 17:19:42 +03004735 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004736}
4737
Henning Rogge66be7d22014-09-12 08:58:49 +02004738static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4739{
4740 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4741 int err;
4742 struct net_device *dev = info->user_ptr[1];
4743 struct mpath_info pinfo;
4744 struct sk_buff *msg;
4745 u8 *dst = NULL;
4746 u8 mpp[ETH_ALEN];
4747
4748 memset(&pinfo, 0, sizeof(pinfo));
4749
4750 if (!info->attrs[NL80211_ATTR_MAC])
4751 return -EINVAL;
4752
4753 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4754
4755 if (!rdev->ops->get_mpp)
4756 return -EOPNOTSUPP;
4757
4758 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4759 return -EOPNOTSUPP;
4760
4761 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4762 if (err)
4763 return err;
4764
4765 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4766 if (!msg)
4767 return -ENOMEM;
4768
4769 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4770 dev, dst, mpp, &pinfo) < 0) {
4771 nlmsg_free(msg);
4772 return -ENOBUFS;
4773 }
4774
4775 return genlmsg_reply(msg, info);
4776}
4777
4778static int nl80211_dump_mpp(struct sk_buff *skb,
4779 struct netlink_callback *cb)
4780{
4781 struct mpath_info pinfo;
4782 struct cfg80211_registered_device *rdev;
4783 struct wireless_dev *wdev;
4784 u8 dst[ETH_ALEN];
4785 u8 mpp[ETH_ALEN];
4786 int path_idx = cb->args[2];
4787 int err;
4788
4789 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4790 if (err)
4791 return err;
4792
4793 if (!rdev->ops->dump_mpp) {
4794 err = -EOPNOTSUPP;
4795 goto out_err;
4796 }
4797
4798 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4799 err = -EOPNOTSUPP;
4800 goto out_err;
4801 }
4802
4803 while (1) {
4804 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4805 mpp, &pinfo);
4806 if (err == -ENOENT)
4807 break;
4808 if (err)
4809 goto out_err;
4810
4811 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4812 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4813 wdev->netdev, dst, mpp,
4814 &pinfo) < 0)
4815 goto out;
4816
4817 path_idx++;
4818 }
4819
4820 out:
4821 cb->args[2] = path_idx;
4822 err = skb->len;
4823 out_err:
4824 nl80211_finish_wdev_dump(rdev);
4825 return err;
4826}
4827
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004828static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4829{
Johannes Berg4c476992010-10-04 21:36:35 +02004830 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4831 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004832 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004833 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004834 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004835
4836 memset(&params, 0, sizeof(params));
4837 /* default to not changing parameters */
4838 params.use_cts_prot = -1;
4839 params.use_short_preamble = -1;
4840 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004841 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004842 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004843 params.p2p_ctwindow = -1;
4844 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004845
4846 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4847 params.use_cts_prot =
4848 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4849 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4850 params.use_short_preamble =
4851 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4852 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4853 params.use_short_slot_time =
4854 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004855 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4856 params.basic_rates =
4857 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4858 params.basic_rates_len =
4859 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4860 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004861 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4862 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004863 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4864 params.ht_opmode =
4865 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004866
Johannes Berg53cabad2012-11-14 15:17:28 +01004867 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4868 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4869 return -EINVAL;
4870 params.p2p_ctwindow =
4871 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4872 if (params.p2p_ctwindow < 0)
4873 return -EINVAL;
4874 if (params.p2p_ctwindow != 0 &&
4875 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4876 return -EINVAL;
4877 }
4878
4879 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4880 u8 tmp;
4881
4882 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4883 return -EINVAL;
4884 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4885 if (tmp > 1)
4886 return -EINVAL;
4887 params.p2p_opp_ps = tmp;
4888 if (params.p2p_opp_ps &&
4889 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4890 return -EINVAL;
4891 }
4892
Johannes Berg4c476992010-10-04 21:36:35 +02004893 if (!rdev->ops->change_bss)
4894 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004895
Johannes Berg074ac8d2010-09-16 14:58:22 +02004896 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004897 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4898 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004899
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004900 wdev_lock(wdev);
4901 err = rdev_change_bss(rdev, dev, &params);
4902 wdev_unlock(wdev);
4903
4904 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004905}
4906
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004907static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004908 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4909 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4910 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4911 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4912 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4913 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004914 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004915};
4916
4917static int parse_reg_rule(struct nlattr *tb[],
4918 struct ieee80211_reg_rule *reg_rule)
4919{
4920 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4921 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4922
4923 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4924 return -EINVAL;
4925 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4926 return -EINVAL;
4927 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4928 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004929 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4930 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004931 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4932 return -EINVAL;
4933
4934 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4935
4936 freq_range->start_freq_khz =
4937 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4938 freq_range->end_freq_khz =
4939 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004940 freq_range->max_bandwidth_khz =
4941 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004942
4943 power_rule->max_eirp =
4944 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4945
4946 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4947 power_rule->max_antenna_gain =
4948 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4949
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004950 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4951 reg_rule->dfs_cac_ms =
4952 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4953
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004954 return 0;
4955}
4956
4957static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4958{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004959 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05004960 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004961 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05004962 u32 owner_nlportid;
4963
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004964
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004965 /*
4966 * You should only get this when cfg80211 hasn't yet initialized
4967 * completely when built-in to the kernel right between the time
4968 * window between nl80211_init() and regulatory_init(), if that is
4969 * even possible.
4970 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004971 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004972 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004973
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004974 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4975 user_reg_hint_type =
4976 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4977 else
4978 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4979
4980 switch (user_reg_hint_type) {
4981 case NL80211_USER_REG_HINT_USER:
4982 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004983 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4984 return -EINVAL;
4985
4986 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4987 return regulatory_hint_user(data, user_reg_hint_type);
4988 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05004989 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
4990 owner_nlportid = info->snd_portid;
4991 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
4992 } else {
4993 owner_nlportid = 0;
4994 is_indoor = true;
4995 }
4996
4997 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004998 default:
4999 return -EINVAL;
5000 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005001}
5002
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005003static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005004 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005005{
Johannes Berg4c476992010-10-04 21:36:35 +02005006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005007 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005008 struct wireless_dev *wdev = dev->ieee80211_ptr;
5009 struct mesh_config cur_params;
5010 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005011 void *hdr;
5012 struct nlattr *pinfoattr;
5013 struct sk_buff *msg;
5014
Johannes Berg29cbe682010-12-03 09:20:44 +01005015 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5016 return -EOPNOTSUPP;
5017
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005018 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005019 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005020
Johannes Berg29cbe682010-12-03 09:20:44 +01005021 wdev_lock(wdev);
5022 /* If not connected, get default parameters */
5023 if (!wdev->mesh_id_len)
5024 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5025 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005026 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005027 wdev_unlock(wdev);
5028
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005029 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005030 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005031
5032 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005033 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005034 if (!msg)
5035 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005036 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005037 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005038 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005039 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005040 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005041 if (!pinfoattr)
5042 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005043 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5044 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5045 cur_params.dot11MeshRetryTimeout) ||
5046 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5047 cur_params.dot11MeshConfirmTimeout) ||
5048 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5049 cur_params.dot11MeshHoldingTimeout) ||
5050 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5051 cur_params.dot11MeshMaxPeerLinks) ||
5052 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5053 cur_params.dot11MeshMaxRetries) ||
5054 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5055 cur_params.dot11MeshTTL) ||
5056 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5057 cur_params.element_ttl) ||
5058 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5059 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005060 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5061 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005062 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5063 cur_params.dot11MeshHWMPmaxPREQretries) ||
5064 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5065 cur_params.path_refresh_time) ||
5066 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5067 cur_params.min_discovery_timeout) ||
5068 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5069 cur_params.dot11MeshHWMPactivePathTimeout) ||
5070 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5071 cur_params.dot11MeshHWMPpreqMinInterval) ||
5072 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5073 cur_params.dot11MeshHWMPperrMinInterval) ||
5074 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5075 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5076 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5077 cur_params.dot11MeshHWMPRootMode) ||
5078 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5079 cur_params.dot11MeshHWMPRannInterval) ||
5080 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5081 cur_params.dot11MeshGateAnnouncementProtocol) ||
5082 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5083 cur_params.dot11MeshForwarding) ||
5084 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005085 cur_params.rssi_threshold) ||
5086 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005087 cur_params.ht_opmode) ||
5088 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5089 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5090 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005091 cur_params.dot11MeshHWMProotInterval) ||
5092 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005093 cur_params.dot11MeshHWMPconfirmationInterval) ||
5094 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5095 cur_params.power_mode) ||
5096 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005097 cur_params.dot11MeshAwakeWindowDuration) ||
5098 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5099 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005100 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005101 nla_nest_end(msg, pinfoattr);
5102 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005103 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005104
Johannes Berg3b858752009-03-12 09:55:09 +01005105 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005106 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005107 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005108 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005109 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005110}
5111
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005112static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005113 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5114 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5115 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5116 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5117 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5118 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005119 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005120 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005121 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005122 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5123 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5124 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5125 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5126 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005127 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005128 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005129 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005130 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005131 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005132 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005133 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5134 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005135 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5136 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005137 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005138 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5139 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005140 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005141};
5142
Javier Cardonac80d5452010-12-16 17:37:49 -08005143static const struct nla_policy
5144 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005145 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005146 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5147 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005148 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005149 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005150 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005151 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005152 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005153 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005154};
5155
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005156static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005157 struct mesh_config *cfg,
5158 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005159{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005160 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005161 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005162
Marco Porschea54fba2013-01-07 16:04:48 +01005163#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5164do { \
5165 if (tb[attr]) { \
5166 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5167 return -EINVAL; \
5168 cfg->param = fn(tb[attr]); \
5169 mask |= (1 << (attr - 1)); \
5170 } \
5171} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005172
5173
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005174 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005175 return -EINVAL;
5176 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005177 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005178 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005179 return -EINVAL;
5180
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005181 /* This makes sure that there aren't more than 32 mesh config
5182 * parameters (otherwise our bitfield scheme would not work.) */
5183 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5184
5185 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005186 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005187 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5188 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005189 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005190 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5191 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005192 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005193 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5194 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005195 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005196 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5197 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005198 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005199 mask, NL80211_MESHCONF_MAX_RETRIES,
5200 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005201 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005202 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005203 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005204 mask, NL80211_MESHCONF_ELEMENT_TTL,
5205 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005206 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005207 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5208 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005209 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5210 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005211 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5212 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005213 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005214 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5215 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005216 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005217 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5218 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005219 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005220 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5221 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005222 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5223 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005224 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5225 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005227 1, 65535, mask,
5228 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005229 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005230 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005231 1, 65535, mask,
5232 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005233 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005234 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005235 dot11MeshHWMPnetDiameterTraversalTime,
5236 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005237 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5238 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005239 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5240 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5241 nla_get_u8);
5242 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5243 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005244 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005245 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005246 dot11MeshGateAnnouncementProtocol, 0, 1,
5247 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005248 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005249 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005250 mask, NL80211_MESHCONF_FORWARDING,
5251 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005252 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005253 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005254 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005255 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005256 mask, NL80211_MESHCONF_HT_OPMODE,
5257 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005258 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005259 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005260 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5261 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005262 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005263 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5264 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005265 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005266 dot11MeshHWMPconfirmationInterval,
5267 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005268 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5269 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005270 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5271 NL80211_MESH_POWER_ACTIVE,
5272 NL80211_MESH_POWER_MAX,
5273 mask, NL80211_MESHCONF_POWER_MODE,
5274 nla_get_u32);
5275 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5276 0, 65535, mask,
5277 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005278 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005279 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5280 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005281 if (mask_out)
5282 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005283
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005284 return 0;
5285
5286#undef FILL_IN_MESH_PARAM_IF_SET
5287}
5288
Javier Cardonac80d5452010-12-16 17:37:49 -08005289static int nl80211_parse_mesh_setup(struct genl_info *info,
5290 struct mesh_setup *setup)
5291{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005292 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005293 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5294
5295 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5296 return -EINVAL;
5297 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5298 info->attrs[NL80211_ATTR_MESH_SETUP],
5299 nl80211_mesh_setup_params_policy))
5300 return -EINVAL;
5301
Javier Cardonad299a1f2012-03-31 11:31:33 -07005302 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5303 setup->sync_method =
5304 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5305 IEEE80211_SYNC_METHOD_VENDOR :
5306 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5307
Javier Cardonac80d5452010-12-16 17:37:49 -08005308 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5309 setup->path_sel_proto =
5310 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5311 IEEE80211_PATH_PROTOCOL_VENDOR :
5312 IEEE80211_PATH_PROTOCOL_HWMP;
5313
5314 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5315 setup->path_metric =
5316 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5317 IEEE80211_PATH_METRIC_VENDOR :
5318 IEEE80211_PATH_METRIC_AIRTIME;
5319
Javier Cardona581a8b02011-04-07 15:08:27 -07005320
5321 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005322 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005323 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005324 if (!is_valid_ie_attr(ieattr))
5325 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005326 setup->ie = nla_data(ieattr);
5327 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005328 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005329 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5330 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5331 return -EINVAL;
5332 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005333 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5334 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005335 if (setup->is_secure)
5336 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005337
Colleen Twitty6e16d902013-05-08 11:45:59 -07005338 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5339 if (!setup->user_mpm)
5340 return -EINVAL;
5341 setup->auth_id =
5342 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5343 }
5344
Javier Cardonac80d5452010-12-16 17:37:49 -08005345 return 0;
5346}
5347
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005348static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005349 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005350{
5351 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5352 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005353 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005354 struct mesh_config cfg;
5355 u32 mask;
5356 int err;
5357
Johannes Berg29cbe682010-12-03 09:20:44 +01005358 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5359 return -EOPNOTSUPP;
5360
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005361 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005362 return -EOPNOTSUPP;
5363
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005364 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005365 if (err)
5366 return err;
5367
Johannes Berg29cbe682010-12-03 09:20:44 +01005368 wdev_lock(wdev);
5369 if (!wdev->mesh_id_len)
5370 err = -ENOLINK;
5371
5372 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005373 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005374
5375 wdev_unlock(wdev);
5376
5377 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005378}
5379
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005380static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5381 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005382{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005383 struct nlattr *nl_reg_rules;
5384 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005385
Johannes Berg458f4f92012-12-06 15:47:38 +01005386 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5387 (regdom->dfs_region &&
5388 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005389 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005390
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005391 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5392 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005393 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005394
Johannes Berg458f4f92012-12-06 15:47:38 +01005395 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005396 struct nlattr *nl_reg_rule;
5397 const struct ieee80211_reg_rule *reg_rule;
5398 const struct ieee80211_freq_range *freq_range;
5399 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005400 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005401
Johannes Berg458f4f92012-12-06 15:47:38 +01005402 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005403 freq_range = &reg_rule->freq_range;
5404 power_rule = &reg_rule->power_rule;
5405
5406 nl_reg_rule = nla_nest_start(msg, i);
5407 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005408 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005409
Janusz Dziedzic97524822014-01-30 09:52:20 +01005410 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5411 if (!max_bandwidth_khz)
5412 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5413 reg_rule);
5414
David S. Miller9360ffd2012-03-29 04:41:26 -04005415 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5416 reg_rule->flags) ||
5417 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5418 freq_range->start_freq_khz) ||
5419 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5420 freq_range->end_freq_khz) ||
5421 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005422 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005423 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5424 power_rule->max_antenna_gain) ||
5425 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005426 power_rule->max_eirp) ||
5427 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5428 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005429 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005430
5431 nla_nest_end(msg, nl_reg_rule);
5432 }
5433
5434 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005435 return 0;
5436
5437nla_put_failure:
5438 return -EMSGSIZE;
5439}
5440
5441static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5442{
5443 const struct ieee80211_regdomain *regdom = NULL;
5444 struct cfg80211_registered_device *rdev;
5445 struct wiphy *wiphy = NULL;
5446 struct sk_buff *msg;
5447 void *hdr;
5448
5449 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5450 if (!msg)
5451 return -ENOBUFS;
5452
5453 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5454 NL80211_CMD_GET_REG);
5455 if (!hdr)
5456 goto put_failure;
5457
5458 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005459 bool self_managed;
5460
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005461 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5462 if (IS_ERR(rdev)) {
5463 nlmsg_free(msg);
5464 return PTR_ERR(rdev);
5465 }
5466
5467 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005468 self_managed = wiphy->regulatory_flags &
5469 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005470 regdom = get_wiphy_regdom(wiphy);
5471
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005472 /* a self-managed-reg device must have a private regdom */
5473 if (WARN_ON(!regdom && self_managed)) {
5474 nlmsg_free(msg);
5475 return -EINVAL;
5476 }
5477
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005478 if (regdom &&
5479 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5480 goto nla_put_failure;
5481 }
5482
5483 if (!wiphy && reg_last_request_cell_base() &&
5484 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5485 NL80211_USER_REG_HINT_CELL_BASE))
5486 goto nla_put_failure;
5487
5488 rcu_read_lock();
5489
5490 if (!regdom)
5491 regdom = rcu_dereference(cfg80211_regdomain);
5492
5493 if (nl80211_put_regdom(regdom, msg))
5494 goto nla_put_failure_rcu;
5495
5496 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005497
5498 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005499 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005500
Johannes Berg458f4f92012-12-06 15:47:38 +01005501nla_put_failure_rcu:
5502 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005503nla_put_failure:
5504 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005505put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005506 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005507 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005508}
5509
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005510static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5511 u32 seq, int flags, struct wiphy *wiphy,
5512 const struct ieee80211_regdomain *regdom)
5513{
5514 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5515 NL80211_CMD_GET_REG);
5516
5517 if (!hdr)
5518 return -1;
5519
5520 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5521
5522 if (nl80211_put_regdom(regdom, msg))
5523 goto nla_put_failure;
5524
5525 if (!wiphy && reg_last_request_cell_base() &&
5526 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5527 NL80211_USER_REG_HINT_CELL_BASE))
5528 goto nla_put_failure;
5529
5530 if (wiphy &&
5531 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5532 goto nla_put_failure;
5533
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005534 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5535 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5536 goto nla_put_failure;
5537
Johannes Berg053c0952015-01-16 22:09:00 +01005538 genlmsg_end(msg, hdr);
5539 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005540
5541nla_put_failure:
5542 genlmsg_cancel(msg, hdr);
5543 return -EMSGSIZE;
5544}
5545
5546static int nl80211_get_reg_dump(struct sk_buff *skb,
5547 struct netlink_callback *cb)
5548{
5549 const struct ieee80211_regdomain *regdom = NULL;
5550 struct cfg80211_registered_device *rdev;
5551 int err, reg_idx, start = cb->args[2];
5552
5553 rtnl_lock();
5554
5555 if (cfg80211_regdomain && start == 0) {
5556 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5557 NLM_F_MULTI, NULL,
5558 rtnl_dereference(cfg80211_regdomain));
5559 if (err < 0)
5560 goto out_err;
5561 }
5562
5563 /* the global regdom is idx 0 */
5564 reg_idx = 1;
5565 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5566 regdom = get_wiphy_regdom(&rdev->wiphy);
5567 if (!regdom)
5568 continue;
5569
5570 if (++reg_idx <= start)
5571 continue;
5572
5573 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5574 NLM_F_MULTI, &rdev->wiphy, regdom);
5575 if (err < 0) {
5576 reg_idx--;
5577 break;
5578 }
5579 }
5580
5581 cb->args[2] = reg_idx;
5582 err = skb->len;
5583out_err:
5584 rtnl_unlock();
5585 return err;
5586}
5587
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005588static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5589{
5590 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5591 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005592 char *alpha2;
5593 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005594 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005595 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005596 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005597
5598 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5599 return -EINVAL;
5600
5601 if (!info->attrs[NL80211_ATTR_REG_RULES])
5602 return -EINVAL;
5603
5604 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5605
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005606 if (info->attrs[NL80211_ATTR_DFS_REGION])
5607 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5608
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005609 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005610 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005611 num_rules++;
5612 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005613 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005614 }
5615
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005616 if (!reg_is_valid_request(alpha2))
5617 return -EINVAL;
5618
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005619 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005620 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005621
5622 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005623 if (!rd)
5624 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005625
5626 rd->n_reg_rules = num_rules;
5627 rd->alpha2[0] = alpha2[0];
5628 rd->alpha2[1] = alpha2[1];
5629
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005630 /*
5631 * Disable DFS master mode if the DFS region was
5632 * not supported or known on this kernel.
5633 */
5634 if (reg_supported_dfs_region(dfs_region))
5635 rd->dfs_region = dfs_region;
5636
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005637 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005638 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005639 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5640 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5641 reg_rule_policy);
5642 if (r)
5643 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005644 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5645 if (r)
5646 goto bad_reg;
5647
5648 rule_idx++;
5649
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005650 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5651 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005652 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005653 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005654 }
5655
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005656 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005657 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005658 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005659
Johannes Bergd2372b32008-10-24 20:32:20 +02005660 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005661 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005662 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005663}
5664
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005665static int validate_scan_freqs(struct nlattr *freqs)
5666{
5667 struct nlattr *attr1, *attr2;
5668 int n_channels = 0, tmp1, tmp2;
5669
5670 nla_for_each_nested(attr1, freqs, tmp1) {
5671 n_channels++;
5672 /*
5673 * Some hardware has a limited channel list for
5674 * scanning, and it is pretty much nonsensical
5675 * to scan for a channel twice, so disallow that
5676 * and don't require drivers to check that the
5677 * channel list they get isn't longer than what
5678 * they can scan, as long as they can scan all
5679 * the channels they registered at once.
5680 */
5681 nla_for_each_nested(attr2, freqs, tmp2)
5682 if (attr1 != attr2 &&
5683 nla_get_u32(attr1) == nla_get_u32(attr2))
5684 return 0;
5685 }
5686
5687 return n_channels;
5688}
5689
Johannes Bergad2b26a2014-06-12 21:39:05 +02005690static int nl80211_parse_random_mac(struct nlattr **attrs,
5691 u8 *mac_addr, u8 *mac_addr_mask)
5692{
5693 int i;
5694
5695 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
5696 memset(mac_addr, 0, ETH_ALEN);
5697 memset(mac_addr_mask, 0, ETH_ALEN);
5698 mac_addr[0] = 0x2;
5699 mac_addr_mask[0] = 0x3;
5700
5701 return 0;
5702 }
5703
5704 /* need both or none */
5705 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5706 return -EINVAL;
5707
5708 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5709 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5710
5711 /* don't allow or configure an mcast address */
5712 if (!is_multicast_ether_addr(mac_addr_mask) ||
5713 is_multicast_ether_addr(mac_addr))
5714 return -EINVAL;
5715
5716 /*
5717 * allow users to pass a MAC address that has bits set outside
5718 * of the mask, but don't bother drivers with having to deal
5719 * with such bits
5720 */
5721 for (i = 0; i < ETH_ALEN; i++)
5722 mac_addr[i] &= mac_addr_mask[i];
5723
5724 return 0;
5725}
5726
Johannes Berg2a519312009-02-10 21:25:55 +01005727static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5728{
Johannes Berg4c476992010-10-04 21:36:35 +02005729 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005730 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005731 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005732 struct nlattr *attr;
5733 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005734 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005735 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005736
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005737 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5738 return -EINVAL;
5739
Johannes Berg79c97e92009-07-07 03:56:12 +02005740 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005741
Johannes Berg4c476992010-10-04 21:36:35 +02005742 if (!rdev->ops->scan)
5743 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005744
Johannes Bergf9d15d12014-01-22 11:14:19 +02005745 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005746 err = -EBUSY;
5747 goto unlock;
5748 }
Johannes Berg2a519312009-02-10 21:25:55 +01005749
5750 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005751 n_channels = validate_scan_freqs(
5752 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005753 if (!n_channels) {
5754 err = -EINVAL;
5755 goto unlock;
5756 }
Johannes Berg2a519312009-02-10 21:25:55 +01005757 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005758 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005759 }
5760
5761 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5762 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5763 n_ssids++;
5764
Johannes Bergf9f47522013-03-19 15:04:07 +01005765 if (n_ssids > wiphy->max_scan_ssids) {
5766 err = -EINVAL;
5767 goto unlock;
5768 }
Johannes Berg2a519312009-02-10 21:25:55 +01005769
Jouni Malinen70692ad2009-02-16 19:39:13 +02005770 if (info->attrs[NL80211_ATTR_IE])
5771 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5772 else
5773 ie_len = 0;
5774
Johannes Bergf9f47522013-03-19 15:04:07 +01005775 if (ie_len > wiphy->max_scan_ie_len) {
5776 err = -EINVAL;
5777 goto unlock;
5778 }
Johannes Berg18a83652009-03-31 12:12:05 +02005779
Johannes Berg2a519312009-02-10 21:25:55 +01005780 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005781 + sizeof(*request->ssids) * n_ssids
5782 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005783 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005784 if (!request) {
5785 err = -ENOMEM;
5786 goto unlock;
5787 }
Johannes Berg2a519312009-02-10 21:25:55 +01005788
Johannes Berg2a519312009-02-10 21:25:55 +01005789 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005790 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005791 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005792 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005793 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005794 request->ie = (void *)(request->ssids + n_ssids);
5795 else
5796 request->ie = (void *)(request->channels + n_channels);
5797 }
Johannes Berg2a519312009-02-10 21:25:55 +01005798
Johannes Berg584991d2009-11-02 13:32:03 +01005799 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005800 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5801 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005802 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005803 struct ieee80211_channel *chan;
5804
5805 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5806
5807 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005808 err = -EINVAL;
5809 goto out_free;
5810 }
Johannes Berg584991d2009-11-02 13:32:03 +01005811
5812 /* ignore disabled channels */
5813 if (chan->flags & IEEE80211_CHAN_DISABLED)
5814 continue;
5815
5816 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005817 i++;
5818 }
5819 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005820 enum ieee80211_band band;
5821
Johannes Berg2a519312009-02-10 21:25:55 +01005822 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005823 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5824 int j;
5825 if (!wiphy->bands[band])
5826 continue;
5827 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005828 struct ieee80211_channel *chan;
5829
5830 chan = &wiphy->bands[band]->channels[j];
5831
5832 if (chan->flags & IEEE80211_CHAN_DISABLED)
5833 continue;
5834
5835 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005836 i++;
5837 }
5838 }
5839 }
5840
Johannes Berg584991d2009-11-02 13:32:03 +01005841 if (!i) {
5842 err = -EINVAL;
5843 goto out_free;
5844 }
5845
5846 request->n_channels = i;
5847
Johannes Berg2a519312009-02-10 21:25:55 +01005848 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005849 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005850 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005851 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005852 err = -EINVAL;
5853 goto out_free;
5854 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005855 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005856 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005857 i++;
5858 }
5859 }
5860
Jouni Malinen70692ad2009-02-16 19:39:13 +02005861 if (info->attrs[NL80211_ATTR_IE]) {
5862 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005863 memcpy((void *)request->ie,
5864 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005865 request->ie_len);
5866 }
5867
Johannes Berg34850ab2011-07-18 18:08:35 +02005868 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005869 if (wiphy->bands[i])
5870 request->rates[i] =
5871 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005872
5873 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5874 nla_for_each_nested(attr,
5875 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5876 tmp) {
5877 enum ieee80211_band band = nla_type(attr);
5878
Dan Carpenter84404622011-07-29 11:52:18 +03005879 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005880 err = -EINVAL;
5881 goto out_free;
5882 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005883
5884 if (!wiphy->bands[band])
5885 continue;
5886
Johannes Berg34850ab2011-07-18 18:08:35 +02005887 err = ieee80211_get_ratemask(wiphy->bands[band],
5888 nla_data(attr),
5889 nla_len(attr),
5890 &request->rates[band]);
5891 if (err)
5892 goto out_free;
5893 }
5894 }
5895
Sam Leffler46856bb2012-10-11 21:03:32 -07005896 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005897 request->flags = nla_get_u32(
5898 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005899 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5900 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005901 err = -EOPNOTSUPP;
5902 goto out_free;
5903 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005904
5905 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5906 if (!(wiphy->features &
5907 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5908 err = -EOPNOTSUPP;
5909 goto out_free;
5910 }
5911
5912 if (wdev->current_bss) {
5913 err = -EOPNOTSUPP;
5914 goto out_free;
5915 }
5916
5917 err = nl80211_parse_random_mac(info->attrs,
5918 request->mac_addr,
5919 request->mac_addr_mask);
5920 if (err)
5921 goto out_free;
5922 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005923 }
Sam Lefflered4737712012-10-11 21:03:31 -07005924
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305925 request->no_cck =
5926 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5927
Johannes Bergfd014282012-06-18 19:17:03 +02005928 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005929 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005930 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005931
Johannes Berg79c97e92009-07-07 03:56:12 +02005932 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005933 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005934
Johannes Berg463d0182009-07-14 00:33:35 +02005935 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005936 nl80211_send_scan_start(rdev, wdev);
5937 if (wdev->netdev)
5938 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005939 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005940 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005941 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005942 kfree(request);
5943 }
Johannes Berg3b858752009-03-12 09:55:09 +01005944
Johannes Bergf9f47522013-03-19 15:04:07 +01005945 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005946 return err;
5947}
5948
Luciano Coelho256da022014-11-10 16:13:46 +02005949static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005950nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005951 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005952{
5953 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005954 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005955 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005956 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005957 enum ieee80211_band band;
5958 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005959 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005960 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005961
Luciano Coelho256da022014-11-10 16:13:46 +02005962 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5963 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005964
Luciano Coelho256da022014-11-10 16:13:46 +02005965 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5966 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005967
Luciano Coelho256da022014-11-10 16:13:46 +02005968 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005969 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005970 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005971
Luciano Coelho256da022014-11-10 16:13:46 +02005972 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005973 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005974 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005975 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005976 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005977 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005978 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005979 }
5980
Luciano Coelho256da022014-11-10 16:13:46 +02005981 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5982 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005983 tmp)
5984 n_ssids++;
5985
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005986 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005987 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005988
Johannes Bergea73cbc2014-01-24 10:53:53 +01005989 /*
5990 * First, count the number of 'real' matchsets. Due to an issue with
5991 * the old implementation, matchsets containing only the RSSI attribute
5992 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5993 * RSSI for all matchsets, rather than their own matchset for reporting
5994 * all APs with a strong RSSI. This is needed to be compatible with
5995 * older userspace that treated a matchset with only the RSSI as the
5996 * global RSSI for all other matchsets - if there are other matchsets.
5997 */
Luciano Coelho256da022014-11-10 16:13:46 +02005998 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005999 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006000 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006001 tmp) {
6002 struct nlattr *rssi;
6003
6004 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6005 nla_data(attr), nla_len(attr),
6006 nl80211_match_policy);
6007 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006008 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006009 /* add other standalone attributes here */
6010 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6011 n_match_sets++;
6012 continue;
6013 }
6014 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6015 if (rssi)
6016 default_match_rssi = nla_get_s32(rssi);
6017 }
6018 }
6019
6020 /* However, if there's no other matchset, add the RSSI one */
6021 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6022 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006023
6024 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006025 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006026
Luciano Coelho256da022014-11-10 16:13:46 +02006027 if (attrs[NL80211_ATTR_IE])
6028 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006029 else
6030 ie_len = 0;
6031
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006032 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006033 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006034
Luciano Coelho807f8a82011-05-11 17:09:35 +03006035 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006036 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006037 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006038 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006039 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006040 if (!request)
6041 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006042
6043 if (n_ssids)
6044 request->ssids = (void *)&request->channels[n_channels];
6045 request->n_ssids = n_ssids;
6046 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006047 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006048 request->ie = (void *)(request->ssids + n_ssids);
6049 else
6050 request->ie = (void *)(request->channels + n_channels);
6051 }
6052
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006053 if (n_match_sets) {
6054 if (request->ie)
6055 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006056 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006057 request->match_sets =
6058 (void *)(request->ssids + n_ssids);
6059 else
6060 request->match_sets =
6061 (void *)(request->channels + n_channels);
6062 }
6063 request->n_match_sets = n_match_sets;
6064
Luciano Coelho807f8a82011-05-11 17:09:35 +03006065 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006066 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006067 /* user specified, bail out if channel not found */
6068 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006069 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006070 tmp) {
6071 struct ieee80211_channel *chan;
6072
6073 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6074
6075 if (!chan) {
6076 err = -EINVAL;
6077 goto out_free;
6078 }
6079
6080 /* ignore disabled channels */
6081 if (chan->flags & IEEE80211_CHAN_DISABLED)
6082 continue;
6083
6084 request->channels[i] = chan;
6085 i++;
6086 }
6087 } else {
6088 /* all channels */
6089 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6090 int j;
6091 if (!wiphy->bands[band])
6092 continue;
6093 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6094 struct ieee80211_channel *chan;
6095
6096 chan = &wiphy->bands[band]->channels[j];
6097
6098 if (chan->flags & IEEE80211_CHAN_DISABLED)
6099 continue;
6100
6101 request->channels[i] = chan;
6102 i++;
6103 }
6104 }
6105 }
6106
6107 if (!i) {
6108 err = -EINVAL;
6109 goto out_free;
6110 }
6111
6112 request->n_channels = i;
6113
6114 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006115 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006116 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006117 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006118 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006119 err = -EINVAL;
6120 goto out_free;
6121 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006122 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006123 memcpy(request->ssids[i].ssid, nla_data(attr),
6124 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006125 i++;
6126 }
6127 }
6128
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006129 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006130 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006131 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006132 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006133 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006134 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006135
Johannes Bergae811e22014-01-24 10:17:47 +01006136 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6137 nla_data(attr), nla_len(attr),
6138 nl80211_match_policy);
6139 if (err)
6140 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006141 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006142 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006143 if (WARN_ON(i >= n_match_sets)) {
6144 /* this indicates a programming error,
6145 * the loop above should have verified
6146 * things properly
6147 */
6148 err = -EINVAL;
6149 goto out_free;
6150 }
6151
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006152 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6153 err = -EINVAL;
6154 goto out_free;
6155 }
6156 memcpy(request->match_sets[i].ssid.ssid,
6157 nla_data(ssid), nla_len(ssid));
6158 request->match_sets[i].ssid.ssid_len =
6159 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006160 /* special attribute - old implemenation w/a */
6161 request->match_sets[i].rssi_thold =
6162 default_match_rssi;
6163 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6164 if (rssi)
6165 request->match_sets[i].rssi_thold =
6166 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006167 }
6168 i++;
6169 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006170
6171 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006172 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006173 request->match_sets[0].rssi_thold = default_match_rssi;
6174
6175 request->min_rssi_thold = INT_MAX;
6176 for (i = 0; i < n_match_sets; i++)
6177 request->min_rssi_thold =
6178 min(request->match_sets[i].rssi_thold,
6179 request->min_rssi_thold);
6180 } else {
6181 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006182 }
6183
Johannes Berg9900e482014-02-04 21:01:25 +01006184 if (ie_len) {
6185 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006186 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006187 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006188 request->ie_len);
6189 }
6190
Luciano Coelho256da022014-11-10 16:13:46 +02006191 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006192 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006193 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006194 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6195 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006196 err = -EOPNOTSUPP;
6197 goto out_free;
6198 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006199
6200 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6201 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6202
6203 if (!wdev) /* must be net-detect */
6204 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6205
6206 if (!(wiphy->features & flg)) {
6207 err = -EOPNOTSUPP;
6208 goto out_free;
6209 }
6210
6211 if (wdev && wdev->current_bss) {
6212 err = -EOPNOTSUPP;
6213 goto out_free;
6214 }
6215
6216 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6217 request->mac_addr_mask);
6218 if (err)
6219 goto out_free;
6220 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006221 }
Sam Lefflered4737712012-10-11 21:03:31 -07006222
Luciano Coelho9c748932015-01-16 16:04:09 +02006223 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6224 request->delay =
6225 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6226
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006227 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006228 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006229
Luciano Coelho256da022014-11-10 16:13:46 +02006230 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006231
6232out_free:
6233 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006234 return ERR_PTR(err);
6235}
6236
6237static int nl80211_start_sched_scan(struct sk_buff *skb,
6238 struct genl_info *info)
6239{
6240 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6241 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006242 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006243 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006244 int err;
6245
6246 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6247 !rdev->ops->sched_scan_start)
6248 return -EOPNOTSUPP;
6249
6250 if (rdev->sched_scan_req)
6251 return -EINPROGRESS;
6252
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006253 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6254 info->attrs);
6255
6256 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006257 if (err)
6258 goto out_err;
6259
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006260 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006261 if (err)
6262 goto out_free;
6263
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006264 sched_scan_req->dev = dev;
6265 sched_scan_req->wiphy = &rdev->wiphy;
6266
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006267 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6268 sched_scan_req->owner_nlportid = info->snd_portid;
6269
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006270 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006271
6272 nl80211_send_sched_scan(rdev, dev,
6273 NL80211_CMD_START_SCHED_SCAN);
6274 return 0;
6275
6276out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006277 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006278out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006279 return err;
6280}
6281
6282static int nl80211_stop_sched_scan(struct sk_buff *skb,
6283 struct genl_info *info)
6284{
6285 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6286
6287 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6288 !rdev->ops->sched_scan_stop)
6289 return -EOPNOTSUPP;
6290
Johannes Berg5fe231e2013-05-08 21:45:15 +02006291 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006292}
6293
Simon Wunderlich04f39042013-02-08 18:16:19 +01006294static int nl80211_start_radar_detection(struct sk_buff *skb,
6295 struct genl_info *info)
6296{
6297 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6298 struct net_device *dev = info->user_ptr[1];
6299 struct wireless_dev *wdev = dev->ieee80211_ptr;
6300 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006301 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006302 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006303 int err;
6304
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006305 dfs_region = reg_get_dfs_region(wdev->wiphy);
6306 if (dfs_region == NL80211_DFS_UNSET)
6307 return -EINVAL;
6308
Simon Wunderlich04f39042013-02-08 18:16:19 +01006309 err = nl80211_parse_chandef(rdev, info, &chandef);
6310 if (err)
6311 return err;
6312
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006313 if (netif_carrier_ok(dev))
6314 return -EBUSY;
6315
Simon Wunderlich04f39042013-02-08 18:16:19 +01006316 if (wdev->cac_started)
6317 return -EBUSY;
6318
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006319 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006320 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006321 if (err < 0)
6322 return err;
6323
6324 if (err == 0)
6325 return -EINVAL;
6326
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006327 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006328 return -EINVAL;
6329
6330 if (!rdev->ops->start_radar_detection)
6331 return -EOPNOTSUPP;
6332
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006333 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6334 if (WARN_ON(!cac_time_ms))
6335 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6336
6337 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6338 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006339 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006340 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006341 wdev->cac_started = true;
6342 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006343 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006344 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006345 return err;
6346}
6347
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006348static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6349{
6350 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6351 struct net_device *dev = info->user_ptr[1];
6352 struct wireless_dev *wdev = dev->ieee80211_ptr;
6353 struct cfg80211_csa_settings params;
6354 /* csa_attrs is defined static to avoid waste of stack size - this
6355 * function is called under RTNL lock, so this should not be a problem.
6356 */
6357 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006358 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006359 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006360 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006361 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006362
6363 if (!rdev->ops->channel_switch ||
6364 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6365 return -EOPNOTSUPP;
6366
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006367 switch (dev->ieee80211_ptr->iftype) {
6368 case NL80211_IFTYPE_AP:
6369 case NL80211_IFTYPE_P2P_GO:
6370 need_new_beacon = true;
6371
6372 /* useless if AP is not running */
6373 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006374 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006375 break;
6376 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006377 if (!wdev->ssid_len)
6378 return -ENOTCONN;
6379 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006380 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006381 if (!wdev->mesh_id_len)
6382 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006383 break;
6384 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006385 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006386 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006387
6388 memset(&params, 0, sizeof(params));
6389
6390 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6391 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6392 return -EINVAL;
6393
6394 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006395 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006396 return -EINVAL;
6397
Luciano Coelho252e07c2014-10-08 09:48:34 +03006398 /* Even though the attribute is u32, the specification says
6399 * u8, so let's make sure we don't overflow.
6400 */
6401 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6402 if (cs_count > 255)
6403 return -EINVAL;
6404
6405 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006406
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006407 if (!need_new_beacon)
6408 goto skip_beacons;
6409
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006410 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6411 if (err)
6412 return err;
6413
6414 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6415 info->attrs[NL80211_ATTR_CSA_IES],
6416 nl80211_policy);
6417 if (err)
6418 return err;
6419
6420 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6421 if (err)
6422 return err;
6423
6424 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6425 return -EINVAL;
6426
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006427 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6428 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006429 return -EINVAL;
6430
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006431 params.n_counter_offsets_beacon = len / sizeof(u16);
6432 if (rdev->wiphy.max_num_csa_counters &&
6433 (params.n_counter_offsets_beacon >
6434 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006435 return -EINVAL;
6436
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006437 params.counter_offsets_beacon =
6438 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6439
6440 /* sanity checks - counters should fit and be the same */
6441 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6442 u16 offset = params.counter_offsets_beacon[i];
6443
6444 if (offset >= params.beacon_csa.tail_len)
6445 return -EINVAL;
6446
6447 if (params.beacon_csa.tail[offset] != params.count)
6448 return -EINVAL;
6449 }
6450
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006451 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006452 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6453 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006454 return -EINVAL;
6455
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006456 params.n_counter_offsets_presp = len / sizeof(u16);
6457 if (rdev->wiphy.max_num_csa_counters &&
6458 (params.n_counter_offsets_beacon >
6459 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006460 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006461
6462 params.counter_offsets_presp =
6463 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6464
6465 /* sanity checks - counters should fit and be the same */
6466 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6467 u16 offset = params.counter_offsets_presp[i];
6468
6469 if (offset >= params.beacon_csa.probe_resp_len)
6470 return -EINVAL;
6471
6472 if (params.beacon_csa.probe_resp[offset] !=
6473 params.count)
6474 return -EINVAL;
6475 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006476 }
6477
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006478skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006479 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6480 if (err)
6481 return err;
6482
Ilan Peer174e0cd2014-02-23 09:13:01 +02006483 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6484 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006485 return -EINVAL;
6486
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006487 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6488 &params.chandef,
6489 wdev->iftype);
6490 if (err < 0)
6491 return err;
6492
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006493 if (err > 0)
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006494 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006495
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006496 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6497 params.block_tx = true;
6498
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006499 wdev_lock(wdev);
6500 err = rdev_channel_switch(rdev, dev, &params);
6501 wdev_unlock(wdev);
6502
6503 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006504}
6505
Johannes Berg9720bb32011-06-21 09:45:33 +02006506static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6507 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006508 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006509 struct wireless_dev *wdev,
6510 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006511{
Johannes Berg48ab9052009-07-10 18:42:31 +02006512 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006513 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006514 void *hdr;
6515 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006516
6517 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006518
Eric W. Biederman15e47302012-09-07 20:12:54 +00006519 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006520 NL80211_CMD_NEW_SCAN_RESULTS);
6521 if (!hdr)
6522 return -1;
6523
Johannes Berg9720bb32011-06-21 09:45:33 +02006524 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6525
Johannes Berg97990a02013-04-19 01:02:55 +02006526 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6527 goto nla_put_failure;
6528 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006529 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6530 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006531 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6532 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006533
6534 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6535 if (!bss)
6536 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006537 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006538 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006539 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006540
6541 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006542 /* indicate whether we have probe response data or not */
6543 if (rcu_access_pointer(res->proberesp_ies) &&
6544 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6545 goto fail_unlock_rcu;
6546
6547 /* this pointer prefers to be pointed to probe response data
6548 * but is always valid
6549 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006550 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006551 if (ies) {
6552 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6553 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006554 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6555 ies->len, ies->data))
6556 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006557 }
Johannes Berg0e227082014-08-12 20:34:30 +02006558
6559 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006560 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006561 if (ies && ies->from_beacon) {
6562 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006563 goto fail_unlock_rcu;
6564 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6565 ies->len, ies->data))
6566 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006567 }
6568 rcu_read_unlock();
6569
David S. Miller9360ffd2012-03-29 04:41:26 -04006570 if (res->beacon_interval &&
6571 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6572 goto nla_put_failure;
6573 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6574 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006575 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006576 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6577 jiffies_to_msecs(jiffies - intbss->ts)))
6578 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006579
Johannes Berg77965c92009-02-18 18:45:06 +01006580 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006581 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006582 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6583 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006584 break;
6585 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006586 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6587 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006588 break;
6589 default:
6590 break;
6591 }
6592
Johannes Berg48ab9052009-07-10 18:42:31 +02006593 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006594 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006595 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006596 if (intbss == wdev->current_bss &&
6597 nla_put_u32(msg, NL80211_BSS_STATUS,
6598 NL80211_BSS_STATUS_ASSOCIATED))
6599 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006600 break;
6601 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006602 if (intbss == wdev->current_bss &&
6603 nla_put_u32(msg, NL80211_BSS_STATUS,
6604 NL80211_BSS_STATUS_IBSS_JOINED))
6605 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006606 break;
6607 default:
6608 break;
6609 }
6610
Johannes Berg2a519312009-02-10 21:25:55 +01006611 nla_nest_end(msg, bss);
6612
Johannes Berg053c0952015-01-16 22:09:00 +01006613 genlmsg_end(msg, hdr);
6614 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006615
Johannes Berg8cef2c92013-02-05 16:54:31 +01006616 fail_unlock_rcu:
6617 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006618 nla_put_failure:
6619 genlmsg_cancel(msg, hdr);
6620 return -EMSGSIZE;
6621}
6622
Johannes Berg97990a02013-04-19 01:02:55 +02006623static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006624{
Johannes Berg48ab9052009-07-10 18:42:31 +02006625 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006626 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006627 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006628 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006629 int err;
6630
Johannes Berg97990a02013-04-19 01:02:55 +02006631 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006632 if (err)
6633 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006634
Johannes Berg48ab9052009-07-10 18:42:31 +02006635 wdev_lock(wdev);
6636 spin_lock_bh(&rdev->bss_lock);
6637 cfg80211_bss_expire(rdev);
6638
Johannes Berg9720bb32011-06-21 09:45:33 +02006639 cb->seq = rdev->bss_generation;
6640
Johannes Berg48ab9052009-07-10 18:42:31 +02006641 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006642 if (++idx <= start)
6643 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006644 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006645 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006646 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006647 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006648 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006649 }
6650 }
6651
Johannes Berg48ab9052009-07-10 18:42:31 +02006652 spin_unlock_bh(&rdev->bss_lock);
6653 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006654
Johannes Berg97990a02013-04-19 01:02:55 +02006655 cb->args[2] = idx;
6656 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006657
Johannes Berg67748892010-10-04 21:14:06 +02006658 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006659}
6660
Eric W. Biederman15e47302012-09-07 20:12:54 +00006661static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006662 int flags, struct net_device *dev,
6663 bool allow_radio_stats,
6664 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006665{
6666 void *hdr;
6667 struct nlattr *infoattr;
6668
Johannes Berg11f78ac2014-11-14 16:43:50 +01006669 /* skip radio stats if userspace didn't request them */
6670 if (!survey->channel && !allow_radio_stats)
6671 return 0;
6672
Eric W. Biederman15e47302012-09-07 20:12:54 +00006673 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006674 NL80211_CMD_NEW_SURVEY_RESULTS);
6675 if (!hdr)
6676 return -ENOMEM;
6677
David S. Miller9360ffd2012-03-29 04:41:26 -04006678 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6679 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006680
6681 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6682 if (!infoattr)
6683 goto nla_put_failure;
6684
Johannes Berg11f78ac2014-11-14 16:43:50 +01006685 if (survey->channel &&
6686 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006687 survey->channel->center_freq))
6688 goto nla_put_failure;
6689
6690 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6691 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6692 goto nla_put_failure;
6693 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6694 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6695 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006696 if ((survey->filled & SURVEY_INFO_TIME) &&
6697 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6698 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006699 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006700 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6701 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6702 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006703 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006704 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6705 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6706 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006707 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006708 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6709 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6710 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006711 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006712 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6713 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6714 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006715 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006716 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6717 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6718 survey->time_scan))
6719 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006720
6721 nla_nest_end(msg, infoattr);
6722
Johannes Berg053c0952015-01-16 22:09:00 +01006723 genlmsg_end(msg, hdr);
6724 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006725
6726 nla_put_failure:
6727 genlmsg_cancel(msg, hdr);
6728 return -EMSGSIZE;
6729}
6730
Johannes Berg11f78ac2014-11-14 16:43:50 +01006731static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006732{
6733 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006734 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006735 struct wireless_dev *wdev;
6736 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006737 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006738 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006739
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006740 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006741 if (res)
6742 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006743
Johannes Berg11f78ac2014-11-14 16:43:50 +01006744 /* prepare_wdev_dump parsed the attributes */
6745 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6746
Johannes Berg97990a02013-04-19 01:02:55 +02006747 if (!wdev->netdev) {
6748 res = -EINVAL;
6749 goto out_err;
6750 }
6751
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006752 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006753 res = -EOPNOTSUPP;
6754 goto out_err;
6755 }
6756
6757 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006758 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006759 if (res == -ENOENT)
6760 break;
6761 if (res)
6762 goto out_err;
6763
Johannes Berg11f78ac2014-11-14 16:43:50 +01006764 /* don't send disabled channels, but do send non-channel data */
6765 if (survey.channel &&
6766 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006767 survey_idx++;
6768 continue;
6769 }
6770
Holger Schurig61fa7132009-11-11 12:25:40 +01006771 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006772 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006773 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006774 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006775 goto out;
6776 survey_idx++;
6777 }
6778
6779 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006780 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006781 res = skb->len;
6782 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006783 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006784 return res;
6785}
6786
Samuel Ortizb23aa672009-07-01 21:26:54 +02006787static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6788{
6789 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6790 NL80211_WPA_VERSION_2));
6791}
6792
Jouni Malinen636a5d32009-03-19 13:39:22 +02006793static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6794{
Johannes Berg4c476992010-10-04 21:36:35 +02006795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6796 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006797 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006798 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6799 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006800 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006801 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006802 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006803
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006804 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6805 return -EINVAL;
6806
6807 if (!info->attrs[NL80211_ATTR_MAC])
6808 return -EINVAL;
6809
Jouni Malinen17780922009-03-27 20:52:47 +02006810 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6811 return -EINVAL;
6812
Johannes Berg19957bb2009-07-02 17:20:43 +02006813 if (!info->attrs[NL80211_ATTR_SSID])
6814 return -EINVAL;
6815
6816 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6817 return -EINVAL;
6818
Johannes Bergfffd0932009-07-08 14:22:54 +02006819 err = nl80211_parse_key(info, &key);
6820 if (err)
6821 return err;
6822
6823 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006824 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6825 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006826 if (!key.p.key || !key.p.key_len)
6827 return -EINVAL;
6828 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6829 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6830 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6831 key.p.key_len != WLAN_KEY_LEN_WEP104))
6832 return -EINVAL;
6833 if (key.idx > 4)
6834 return -EINVAL;
6835 } else {
6836 key.p.key_len = 0;
6837 key.p.key = NULL;
6838 }
6839
Johannes Bergafea0b72010-08-10 09:46:42 +02006840 if (key.idx >= 0) {
6841 int i;
6842 bool ok = false;
6843 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6844 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6845 ok = true;
6846 break;
6847 }
6848 }
Johannes Berg4c476992010-10-04 21:36:35 +02006849 if (!ok)
6850 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006851 }
6852
Johannes Berg4c476992010-10-04 21:36:35 +02006853 if (!rdev->ops->auth)
6854 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006855
Johannes Berg074ac8d2010-09-16 14:58:22 +02006856 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006857 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6858 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006859
Johannes Berg19957bb2009-07-02 17:20:43 +02006860 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006861 chan = nl80211_get_valid_chan(&rdev->wiphy,
6862 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6863 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006864 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006865
Johannes Berg19957bb2009-07-02 17:20:43 +02006866 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6867 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6868
6869 if (info->attrs[NL80211_ATTR_IE]) {
6870 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6871 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6872 }
6873
6874 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006875 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006876 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006877
Jouni Malinene39e5b52012-09-30 19:29:39 +03006878 if (auth_type == NL80211_AUTHTYPE_SAE &&
6879 !info->attrs[NL80211_ATTR_SAE_DATA])
6880 return -EINVAL;
6881
6882 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6883 if (auth_type != NL80211_AUTHTYPE_SAE)
6884 return -EINVAL;
6885 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6886 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6887 /* need to include at least Auth Transaction and Status Code */
6888 if (sae_data_len < 4)
6889 return -EINVAL;
6890 }
6891
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006892 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6893
Johannes Berg95de8172012-01-20 13:55:25 +01006894 /*
6895 * Since we no longer track auth state, ignore
6896 * requests to only change local state.
6897 */
6898 if (local_state_change)
6899 return 0;
6900
Johannes Berg91bf9b22013-05-15 17:44:01 +02006901 wdev_lock(dev->ieee80211_ptr);
6902 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6903 ssid, ssid_len, ie, ie_len,
6904 key.p.key, key.p.key_len, key.idx,
6905 sae_data, sae_data_len);
6906 wdev_unlock(dev->ieee80211_ptr);
6907 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006908}
6909
Johannes Bergc0692b82010-08-27 14:26:53 +03006910static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6911 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006912 struct cfg80211_crypto_settings *settings,
6913 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006914{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006915 memset(settings, 0, sizeof(*settings));
6916
Samuel Ortizb23aa672009-07-01 21:26:54 +02006917 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6918
Johannes Bergc0692b82010-08-27 14:26:53 +03006919 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6920 u16 proto;
6921 proto = nla_get_u16(
6922 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6923 settings->control_port_ethertype = cpu_to_be16(proto);
6924 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6925 proto != ETH_P_PAE)
6926 return -EINVAL;
6927 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6928 settings->control_port_no_encrypt = true;
6929 } else
6930 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6931
Samuel Ortizb23aa672009-07-01 21:26:54 +02006932 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6933 void *data;
6934 int len, i;
6935
6936 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6937 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6938 settings->n_ciphers_pairwise = len / sizeof(u32);
6939
6940 if (len % sizeof(u32))
6941 return -EINVAL;
6942
Johannes Berg3dc27d22009-07-02 21:36:37 +02006943 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006944 return -EINVAL;
6945
6946 memcpy(settings->ciphers_pairwise, data, len);
6947
6948 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006949 if (!cfg80211_supported_cipher_suite(
6950 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006951 settings->ciphers_pairwise[i]))
6952 return -EINVAL;
6953 }
6954
6955 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6956 settings->cipher_group =
6957 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006958 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6959 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006960 return -EINVAL;
6961 }
6962
6963 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6964 settings->wpa_versions =
6965 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6966 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6967 return -EINVAL;
6968 }
6969
6970 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6971 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006972 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006973
6974 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6975 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6976 settings->n_akm_suites = len / sizeof(u32);
6977
6978 if (len % sizeof(u32))
6979 return -EINVAL;
6980
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006981 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6982 return -EINVAL;
6983
Samuel Ortizb23aa672009-07-01 21:26:54 +02006984 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006985 }
6986
6987 return 0;
6988}
6989
Jouni Malinen636a5d32009-03-19 13:39:22 +02006990static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6991{
Johannes Berg4c476992010-10-04 21:36:35 +02006992 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6993 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006994 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006995 struct cfg80211_assoc_request req = {};
6996 const u8 *bssid, *ssid;
6997 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006998
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006999 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7000 return -EINVAL;
7001
7002 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007003 !info->attrs[NL80211_ATTR_SSID] ||
7004 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007005 return -EINVAL;
7006
Johannes Berg4c476992010-10-04 21:36:35 +02007007 if (!rdev->ops->assoc)
7008 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007009
Johannes Berg074ac8d2010-09-16 14:58:22 +02007010 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007011 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7012 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007013
Johannes Berg19957bb2009-07-02 17:20:43 +02007014 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007015
Jouni Malinen664834d2014-01-15 00:01:44 +02007016 chan = nl80211_get_valid_chan(&rdev->wiphy,
7017 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7018 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007019 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007020
Johannes Berg19957bb2009-07-02 17:20:43 +02007021 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7022 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007023
7024 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007025 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7026 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007027 }
7028
Jouni Malinendc6382c2009-05-06 22:09:37 +03007029 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007030 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007031 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007032 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007033 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007034 else if (mfp != NL80211_MFP_NO)
7035 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007036 }
7037
Johannes Berg3e5d7642009-07-07 14:37:26 +02007038 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007039 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007040
Ben Greear7e7c8922011-11-18 11:31:59 -08007041 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007042 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007043
7044 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007045 memcpy(&req.ht_capa_mask,
7046 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7047 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007048
7049 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007050 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007051 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007052 memcpy(&req.ht_capa,
7053 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7054 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007055 }
7056
Johannes Bergee2aca32013-02-21 17:36:01 +01007057 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007058 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007059
7060 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007061 memcpy(&req.vht_capa_mask,
7062 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7063 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007064
7065 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007066 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007067 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007068 memcpy(&req.vht_capa,
7069 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7070 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007071 }
7072
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007073 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7074 if (!(rdev->wiphy.features &
7075 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7076 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7077 return -EINVAL;
7078 req.flags |= ASSOC_REQ_USE_RRM;
7079 }
7080
Johannes Bergf62fab72013-02-21 20:09:09 +01007081 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007082 if (!err) {
7083 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007084 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7085 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007086 wdev_unlock(dev->ieee80211_ptr);
7087 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007088
Jouni Malinen636a5d32009-03-19 13:39:22 +02007089 return err;
7090}
7091
7092static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7093{
Johannes Berg4c476992010-10-04 21:36:35 +02007094 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7095 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007096 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007097 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007098 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007099 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007100
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007101 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7102 return -EINVAL;
7103
7104 if (!info->attrs[NL80211_ATTR_MAC])
7105 return -EINVAL;
7106
7107 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7108 return -EINVAL;
7109
Johannes Berg4c476992010-10-04 21:36:35 +02007110 if (!rdev->ops->deauth)
7111 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007112
Johannes Berg074ac8d2010-09-16 14:58:22 +02007113 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007114 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7115 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007116
Johannes Berg19957bb2009-07-02 17:20:43 +02007117 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007118
Johannes Berg19957bb2009-07-02 17:20:43 +02007119 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7120 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007121 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007122 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007123 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007124
7125 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007126 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7127 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007128 }
7129
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007130 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7131
Johannes Berg91bf9b22013-05-15 17:44:01 +02007132 wdev_lock(dev->ieee80211_ptr);
7133 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7134 local_state_change);
7135 wdev_unlock(dev->ieee80211_ptr);
7136 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007137}
7138
7139static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7140{
Johannes Berg4c476992010-10-04 21:36:35 +02007141 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7142 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007143 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007144 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007145 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007146 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007147
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007148 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7149 return -EINVAL;
7150
7151 if (!info->attrs[NL80211_ATTR_MAC])
7152 return -EINVAL;
7153
7154 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7155 return -EINVAL;
7156
Johannes Berg4c476992010-10-04 21:36:35 +02007157 if (!rdev->ops->disassoc)
7158 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007159
Johannes Berg074ac8d2010-09-16 14:58:22 +02007160 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007161 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7162 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007163
Johannes Berg19957bb2009-07-02 17:20:43 +02007164 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007165
Johannes Berg19957bb2009-07-02 17:20:43 +02007166 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7167 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007168 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007169 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007170 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007171
7172 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007173 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7174 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007175 }
7176
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007177 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7178
Johannes Berg91bf9b22013-05-15 17:44:01 +02007179 wdev_lock(dev->ieee80211_ptr);
7180 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7181 local_state_change);
7182 wdev_unlock(dev->ieee80211_ptr);
7183 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007184}
7185
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007186static bool
7187nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7188 int mcast_rate[IEEE80211_NUM_BANDS],
7189 int rateval)
7190{
7191 struct wiphy *wiphy = &rdev->wiphy;
7192 bool found = false;
7193 int band, i;
7194
7195 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7196 struct ieee80211_supported_band *sband;
7197
7198 sband = wiphy->bands[band];
7199 if (!sband)
7200 continue;
7201
7202 for (i = 0; i < sband->n_bitrates; i++) {
7203 if (sband->bitrates[i].bitrate == rateval) {
7204 mcast_rate[band] = i + 1;
7205 found = true;
7206 break;
7207 }
7208 }
7209 }
7210
7211 return found;
7212}
7213
Johannes Berg04a773a2009-04-19 21:24:32 +02007214static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7215{
Johannes Berg4c476992010-10-04 21:36:35 +02007216 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7217 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007218 struct cfg80211_ibss_params ibss;
7219 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007220 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007221 int err;
7222
Johannes Berg8e30bc52009-04-22 17:45:38 +02007223 memset(&ibss, 0, sizeof(ibss));
7224
Johannes Berg04a773a2009-04-19 21:24:32 +02007225 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7226 return -EINVAL;
7227
Johannes Berg683b6d32012-11-08 21:25:48 +01007228 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007229 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7230 return -EINVAL;
7231
Johannes Berg8e30bc52009-04-22 17:45:38 +02007232 ibss.beacon_interval = 100;
7233
7234 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7235 ibss.beacon_interval =
7236 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7237 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7238 return -EINVAL;
7239 }
7240
Johannes Berg4c476992010-10-04 21:36:35 +02007241 if (!rdev->ops->join_ibss)
7242 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007243
Johannes Berg4c476992010-10-04 21:36:35 +02007244 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7245 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007246
Johannes Berg79c97e92009-07-07 03:56:12 +02007247 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007248
Johannes Berg39193492011-09-16 13:45:25 +02007249 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007250 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007251
7252 if (!is_valid_ether_addr(ibss.bssid))
7253 return -EINVAL;
7254 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007255 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7256 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7257
7258 if (info->attrs[NL80211_ATTR_IE]) {
7259 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7260 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7261 }
7262
Johannes Berg683b6d32012-11-08 21:25:48 +01007263 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7264 if (err)
7265 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007266
Ilan Peer174e0cd2014-02-23 09:13:01 +02007267 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7268 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007269 return -EINVAL;
7270
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007271 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007272 case NL80211_CHAN_WIDTH_5:
7273 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007274 case NL80211_CHAN_WIDTH_20_NOHT:
7275 break;
7276 case NL80211_CHAN_WIDTH_20:
7277 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007278 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7279 return -EINVAL;
7280 break;
7281 case NL80211_CHAN_WIDTH_80:
7282 case NL80211_CHAN_WIDTH_80P80:
7283 case NL80211_CHAN_WIDTH_160:
7284 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7285 return -EINVAL;
7286 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7287 NL80211_EXT_FEATURE_VHT_IBSS))
7288 return -EINVAL;
7289 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007290 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007291 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007292 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007293
Johannes Berg04a773a2009-04-19 21:24:32 +02007294 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007295 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007296
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007297 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7298 u8 *rates =
7299 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7300 int n_rates =
7301 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7302 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007303 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007304
Johannes Berg34850ab2011-07-18 18:08:35 +02007305 err = ieee80211_get_ratemask(sband, rates, n_rates,
7306 &ibss.basic_rates);
7307 if (err)
7308 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007309 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007310
Simon Wunderlich803768f2013-06-28 10:39:58 +02007311 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7312 memcpy(&ibss.ht_capa_mask,
7313 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7314 sizeof(ibss.ht_capa_mask));
7315
7316 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7317 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7318 return -EINVAL;
7319 memcpy(&ibss.ht_capa,
7320 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7321 sizeof(ibss.ht_capa));
7322 }
7323
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007324 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7325 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7326 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7327 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007328
Johannes Berg4c476992010-10-04 21:36:35 +02007329 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307330 bool no_ht = false;
7331
Johannes Berg4c476992010-10-04 21:36:35 +02007332 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307333 info->attrs[NL80211_ATTR_KEYS],
7334 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007335 if (IS_ERR(connkeys))
7336 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307337
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007338 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7339 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307340 kfree(connkeys);
7341 return -EINVAL;
7342 }
Johannes Berg4c476992010-10-04 21:36:35 +02007343 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007344
Antonio Quartulli267335d2012-01-31 20:25:47 +01007345 ibss.control_port =
7346 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7347
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007348 ibss.userspace_handles_dfs =
7349 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7350
Johannes Berg4c476992010-10-04 21:36:35 +02007351 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007352 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007353 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007354 return err;
7355}
7356
7357static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7358{
Johannes Berg4c476992010-10-04 21:36:35 +02007359 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7360 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007361
Johannes Berg4c476992010-10-04 21:36:35 +02007362 if (!rdev->ops->leave_ibss)
7363 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007364
Johannes Berg4c476992010-10-04 21:36:35 +02007365 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7366 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007367
Johannes Berg4c476992010-10-04 21:36:35 +02007368 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007369}
7370
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007371static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7372{
7373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7374 struct net_device *dev = info->user_ptr[1];
7375 int mcast_rate[IEEE80211_NUM_BANDS];
7376 u32 nla_rate;
7377 int err;
7378
7379 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7380 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7381 return -EOPNOTSUPP;
7382
7383 if (!rdev->ops->set_mcast_rate)
7384 return -EOPNOTSUPP;
7385
7386 memset(mcast_rate, 0, sizeof(mcast_rate));
7387
7388 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7389 return -EINVAL;
7390
7391 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7392 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7393 return -EINVAL;
7394
7395 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7396
7397 return err;
7398}
7399
Johannes Bergad7e7182013-11-13 13:37:47 +01007400static struct sk_buff *
7401__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007402 struct wireless_dev *wdev, int approxlen,
7403 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007404 enum nl80211_attrs attr,
7405 const struct nl80211_vendor_cmd_info *info,
7406 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007407{
7408 struct sk_buff *skb;
7409 void *hdr;
7410 struct nlattr *data;
7411
7412 skb = nlmsg_new(approxlen + 100, gfp);
7413 if (!skb)
7414 return NULL;
7415
7416 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7417 if (!hdr) {
7418 kfree_skb(skb);
7419 return NULL;
7420 }
7421
7422 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7423 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007424
7425 if (info) {
7426 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7427 info->vendor_id))
7428 goto nla_put_failure;
7429 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7430 info->subcmd))
7431 goto nla_put_failure;
7432 }
7433
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007434 if (wdev) {
7435 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7436 wdev_id(wdev)))
7437 goto nla_put_failure;
7438 if (wdev->netdev &&
7439 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7440 wdev->netdev->ifindex))
7441 goto nla_put_failure;
7442 }
7443
Johannes Bergad7e7182013-11-13 13:37:47 +01007444 data = nla_nest_start(skb, attr);
7445
7446 ((void **)skb->cb)[0] = rdev;
7447 ((void **)skb->cb)[1] = hdr;
7448 ((void **)skb->cb)[2] = data;
7449
7450 return skb;
7451
7452 nla_put_failure:
7453 kfree_skb(skb);
7454 return NULL;
7455}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007456
Johannes Berge03ad6e2014-01-01 17:22:30 +01007457struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007458 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007459 enum nl80211_commands cmd,
7460 enum nl80211_attrs attr,
7461 int vendor_event_idx,
7462 int approxlen, gfp_t gfp)
7463{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007464 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007465 const struct nl80211_vendor_cmd_info *info;
7466
7467 switch (cmd) {
7468 case NL80211_CMD_TESTMODE:
7469 if (WARN_ON(vendor_event_idx != -1))
7470 return NULL;
7471 info = NULL;
7472 break;
7473 case NL80211_CMD_VENDOR:
7474 if (WARN_ON(vendor_event_idx < 0 ||
7475 vendor_event_idx >= wiphy->n_vendor_events))
7476 return NULL;
7477 info = &wiphy->vendor_events[vendor_event_idx];
7478 break;
7479 default:
7480 WARN_ON(1);
7481 return NULL;
7482 }
7483
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007484 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007485 cmd, attr, info, gfp);
7486}
7487EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7488
7489void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7490{
7491 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7492 void *hdr = ((void **)skb->cb)[1];
7493 struct nlattr *data = ((void **)skb->cb)[2];
7494 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7495
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007496 /* clear CB data for netlink core to own from now on */
7497 memset(skb->cb, 0, sizeof(skb->cb));
7498
Johannes Berge03ad6e2014-01-01 17:22:30 +01007499 nla_nest_end(skb, data);
7500 genlmsg_end(skb, hdr);
7501
7502 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7503 mcgrp = NL80211_MCGRP_VENDOR;
7504
7505 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7506 mcgrp, gfp);
7507}
7508EXPORT_SYMBOL(__cfg80211_send_event_skb);
7509
Johannes Bergaff89a92009-07-01 21:26:51 +02007510#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007511static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7512{
Johannes Berg4c476992010-10-04 21:36:35 +02007513 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007514 struct wireless_dev *wdev =
7515 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007516 int err;
7517
David Spinadelfc73f112013-07-31 18:04:15 +03007518 if (!rdev->ops->testmode_cmd)
7519 return -EOPNOTSUPP;
7520
7521 if (IS_ERR(wdev)) {
7522 err = PTR_ERR(wdev);
7523 if (err != -EINVAL)
7524 return err;
7525 wdev = NULL;
7526 } else if (wdev->wiphy != &rdev->wiphy) {
7527 return -EINVAL;
7528 }
7529
Johannes Bergaff89a92009-07-01 21:26:51 +02007530 if (!info->attrs[NL80211_ATTR_TESTDATA])
7531 return -EINVAL;
7532
Johannes Bergad7e7182013-11-13 13:37:47 +01007533 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007534 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007535 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7536 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007537 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007538
Johannes Bergaff89a92009-07-01 21:26:51 +02007539 return err;
7540}
7541
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007542static int nl80211_testmode_dump(struct sk_buff *skb,
7543 struct netlink_callback *cb)
7544{
Johannes Berg00918d32011-12-13 17:22:05 +01007545 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007546 int err;
7547 long phy_idx;
7548 void *data = NULL;
7549 int data_len = 0;
7550
Johannes Berg5fe231e2013-05-08 21:45:15 +02007551 rtnl_lock();
7552
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007553 if (cb->args[0]) {
7554 /*
7555 * 0 is a valid index, but not valid for args[0],
7556 * so we need to offset by 1.
7557 */
7558 phy_idx = cb->args[0] - 1;
7559 } else {
7560 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7561 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7562 nl80211_policy);
7563 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007564 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007565
Johannes Berg2bd7e352012-06-15 14:23:16 +02007566 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7567 nl80211_fam.attrbuf);
7568 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007569 err = PTR_ERR(rdev);
7570 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007571 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007572 phy_idx = rdev->wiphy_idx;
7573 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007574
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007575 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7576 cb->args[1] =
7577 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7578 }
7579
7580 if (cb->args[1]) {
7581 data = nla_data((void *)cb->args[1]);
7582 data_len = nla_len((void *)cb->args[1]);
7583 }
7584
Johannes Berg00918d32011-12-13 17:22:05 +01007585 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7586 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007587 err = -ENOENT;
7588 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007589 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007590
Johannes Berg00918d32011-12-13 17:22:05 +01007591 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007592 err = -EOPNOTSUPP;
7593 goto out_err;
7594 }
7595
7596 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007597 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007598 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7599 NL80211_CMD_TESTMODE);
7600 struct nlattr *tmdata;
7601
Dan Carpentercb35fba2013-08-14 14:50:01 +03007602 if (!hdr)
7603 break;
7604
David S. Miller9360ffd2012-03-29 04:41:26 -04007605 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007606 genlmsg_cancel(skb, hdr);
7607 break;
7608 }
7609
7610 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7611 if (!tmdata) {
7612 genlmsg_cancel(skb, hdr);
7613 break;
7614 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007615 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007616 nla_nest_end(skb, tmdata);
7617
7618 if (err == -ENOBUFS || err == -ENOENT) {
7619 genlmsg_cancel(skb, hdr);
7620 break;
7621 } else if (err) {
7622 genlmsg_cancel(skb, hdr);
7623 goto out_err;
7624 }
7625
7626 genlmsg_end(skb, hdr);
7627 }
7628
7629 err = skb->len;
7630 /* see above */
7631 cb->args[0] = phy_idx + 1;
7632 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007633 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007634 return err;
7635}
Johannes Bergaff89a92009-07-01 21:26:51 +02007636#endif
7637
Samuel Ortizb23aa672009-07-01 21:26:54 +02007638static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7639{
Johannes Berg4c476992010-10-04 21:36:35 +02007640 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7641 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007642 struct cfg80211_connect_params connect;
7643 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007644 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007645 int err;
7646
7647 memset(&connect, 0, sizeof(connect));
7648
7649 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7650 return -EINVAL;
7651
7652 if (!info->attrs[NL80211_ATTR_SSID] ||
7653 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7654 return -EINVAL;
7655
7656 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7657 connect.auth_type =
7658 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007659 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7660 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007661 return -EINVAL;
7662 } else
7663 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7664
7665 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7666
Johannes Bergc0692b82010-08-27 14:26:53 +03007667 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007668 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007669 if (err)
7670 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007671
Johannes Berg074ac8d2010-09-16 14:58:22 +02007672 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007673 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7674 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007675
Johannes Berg79c97e92009-07-07 03:56:12 +02007676 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007677
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307678 connect.bg_scan_period = -1;
7679 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7680 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7681 connect.bg_scan_period =
7682 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7683 }
7684
Samuel Ortizb23aa672009-07-01 21:26:54 +02007685 if (info->attrs[NL80211_ATTR_MAC])
7686 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007687 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7688 connect.bssid_hint =
7689 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007690 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7691 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7692
7693 if (info->attrs[NL80211_ATTR_IE]) {
7694 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7695 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7696 }
7697
Jouni Malinencee00a92013-01-15 17:15:57 +02007698 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7699 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7700 if (connect.mfp != NL80211_MFP_REQUIRED &&
7701 connect.mfp != NL80211_MFP_NO)
7702 return -EINVAL;
7703 } else {
7704 connect.mfp = NL80211_MFP_NO;
7705 }
7706
Samuel Ortizb23aa672009-07-01 21:26:54 +02007707 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007708 connect.channel = nl80211_get_valid_chan(
7709 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7710 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007711 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007712 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007713 connect.channel_hint = nl80211_get_valid_chan(
7714 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7715 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007716 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007717 }
7718
Johannes Bergfffd0932009-07-08 14:22:54 +02007719 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7720 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307721 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007722 if (IS_ERR(connkeys))
7723 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007724 }
7725
Ben Greear7e7c8922011-11-18 11:31:59 -08007726 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7727 connect.flags |= ASSOC_REQ_DISABLE_HT;
7728
7729 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7730 memcpy(&connect.ht_capa_mask,
7731 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7732 sizeof(connect.ht_capa_mask));
7733
7734 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007735 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007736 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007737 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007738 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007739 memcpy(&connect.ht_capa,
7740 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7741 sizeof(connect.ht_capa));
7742 }
7743
Johannes Bergee2aca32013-02-21 17:36:01 +01007744 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7745 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7746
7747 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7748 memcpy(&connect.vht_capa_mask,
7749 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7750 sizeof(connect.vht_capa_mask));
7751
7752 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7753 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007754 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007755 return -EINVAL;
7756 }
7757 memcpy(&connect.vht_capa,
7758 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7759 sizeof(connect.vht_capa));
7760 }
7761
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007762 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7763 if (!(rdev->wiphy.features &
7764 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7765 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7766 return -EINVAL;
7767 connect.flags |= ASSOC_REQ_USE_RRM;
7768 }
7769
Johannes Berg83739b02013-05-15 17:44:01 +02007770 wdev_lock(dev->ieee80211_ptr);
7771 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7772 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007773 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007774 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007775 return err;
7776}
7777
7778static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7779{
Johannes Berg4c476992010-10-04 21:36:35 +02007780 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7781 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007782 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007783 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007784
7785 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7786 reason = WLAN_REASON_DEAUTH_LEAVING;
7787 else
7788 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7789
7790 if (reason == 0)
7791 return -EINVAL;
7792
Johannes Berg074ac8d2010-09-16 14:58:22 +02007793 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007794 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7795 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007796
Johannes Berg83739b02013-05-15 17:44:01 +02007797 wdev_lock(dev->ieee80211_ptr);
7798 ret = cfg80211_disconnect(rdev, dev, reason, true);
7799 wdev_unlock(dev->ieee80211_ptr);
7800 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007801}
7802
Johannes Berg463d0182009-07-14 00:33:35 +02007803static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7804{
Johannes Berg4c476992010-10-04 21:36:35 +02007805 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007806 struct net *net;
7807 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007808
Vadim Kochan4b681c82015-01-12 16:34:05 +02007809 if (info->attrs[NL80211_ATTR_PID]) {
7810 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7811
7812 net = get_net_ns_by_pid(pid);
7813 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7814 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7815
7816 net = get_net_ns_by_fd(fd);
7817 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007818 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007819 }
Johannes Berg463d0182009-07-14 00:33:35 +02007820
Johannes Berg4c476992010-10-04 21:36:35 +02007821 if (IS_ERR(net))
7822 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007823
7824 err = 0;
7825
7826 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007827 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7828 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007829
Johannes Berg463d0182009-07-14 00:33:35 +02007830 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007831 return err;
7832}
7833
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007834static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7835{
Johannes Berg4c476992010-10-04 21:36:35 +02007836 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007837 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7838 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007839 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007840 struct cfg80211_pmksa pmksa;
7841
7842 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7843
7844 if (!info->attrs[NL80211_ATTR_MAC])
7845 return -EINVAL;
7846
7847 if (!info->attrs[NL80211_ATTR_PMKID])
7848 return -EINVAL;
7849
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007850 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7851 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7852
Johannes Berg074ac8d2010-09-16 14:58:22 +02007853 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007854 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7855 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007856
7857 switch (info->genlhdr->cmd) {
7858 case NL80211_CMD_SET_PMKSA:
7859 rdev_ops = rdev->ops->set_pmksa;
7860 break;
7861 case NL80211_CMD_DEL_PMKSA:
7862 rdev_ops = rdev->ops->del_pmksa;
7863 break;
7864 default:
7865 WARN_ON(1);
7866 break;
7867 }
7868
Johannes Berg4c476992010-10-04 21:36:35 +02007869 if (!rdev_ops)
7870 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007871
Johannes Berg4c476992010-10-04 21:36:35 +02007872 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007873}
7874
7875static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7876{
Johannes Berg4c476992010-10-04 21:36:35 +02007877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7878 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007879
Johannes Berg074ac8d2010-09-16 14:58:22 +02007880 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007881 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7882 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007883
Johannes Berg4c476992010-10-04 21:36:35 +02007884 if (!rdev->ops->flush_pmksa)
7885 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007886
Hila Gonene35e4d22012-06-27 17:19:42 +03007887 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007888}
7889
Arik Nemtsov109086c2011-09-28 14:12:50 +03007890static int nl80211_tdls_mgmt(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 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307895 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007896 u16 status_code;
7897 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007898 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007899
7900 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7901 !rdev->ops->tdls_mgmt)
7902 return -EOPNOTSUPP;
7903
7904 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7905 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7906 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7907 !info->attrs[NL80211_ATTR_IE] ||
7908 !info->attrs[NL80211_ATTR_MAC])
7909 return -EINVAL;
7910
7911 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7912 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7913 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7914 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007915 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307916 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7917 peer_capability =
7918 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007919
Hila Gonene35e4d22012-06-27 17:19:42 +03007920 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307921 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007922 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007923 nla_data(info->attrs[NL80211_ATTR_IE]),
7924 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007925}
7926
7927static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7928{
7929 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7930 struct net_device *dev = info->user_ptr[1];
7931 enum nl80211_tdls_operation operation;
7932 u8 *peer;
7933
7934 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7935 !rdev->ops->tdls_oper)
7936 return -EOPNOTSUPP;
7937
7938 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7939 !info->attrs[NL80211_ATTR_MAC])
7940 return -EINVAL;
7941
7942 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7943 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7944
Hila Gonene35e4d22012-06-27 17:19:42 +03007945 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007946}
7947
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007948static int nl80211_remain_on_channel(struct sk_buff *skb,
7949 struct genl_info *info)
7950{
Johannes Berg4c476992010-10-04 21:36:35 +02007951 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007952 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007953 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007954 struct sk_buff *msg;
7955 void *hdr;
7956 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007957 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007958 int err;
7959
7960 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7961 !info->attrs[NL80211_ATTR_DURATION])
7962 return -EINVAL;
7963
7964 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7965
Johannes Berg7c4ef712011-11-18 15:33:48 +01007966 if (!rdev->ops->remain_on_channel ||
7967 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007968 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007969
Johannes Bergebf348f2012-06-01 12:50:54 +02007970 /*
7971 * We should be on that channel for at least a minimum amount of
7972 * time (10ms) but no longer than the driver supports.
7973 */
7974 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7975 duration > rdev->wiphy.max_remain_on_channel_duration)
7976 return -EINVAL;
7977
Johannes Berg683b6d32012-11-08 21:25:48 +01007978 err = nl80211_parse_chandef(rdev, info, &chandef);
7979 if (err)
7980 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007981
7982 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007983 if (!msg)
7984 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007985
Eric W. Biederman15e47302012-09-07 20:12:54 +00007986 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007987 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007988 if (!hdr) {
7989 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007990 goto free_msg;
7991 }
7992
Johannes Berg683b6d32012-11-08 21:25:48 +01007993 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7994 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007995
7996 if (err)
7997 goto free_msg;
7998
David S. Miller9360ffd2012-03-29 04:41:26 -04007999 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8000 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008001
8002 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008003
8004 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008005
8006 nla_put_failure:
8007 err = -ENOBUFS;
8008 free_msg:
8009 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008010 return err;
8011}
8012
8013static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8014 struct genl_info *info)
8015{
Johannes Berg4c476992010-10-04 21:36:35 +02008016 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008017 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008018 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008019
8020 if (!info->attrs[NL80211_ATTR_COOKIE])
8021 return -EINVAL;
8022
Johannes Berg4c476992010-10-04 21:36:35 +02008023 if (!rdev->ops->cancel_remain_on_channel)
8024 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008025
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008026 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8027
Hila Gonene35e4d22012-06-27 17:19:42 +03008028 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008029}
8030
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008031static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8032 u8 *rates, u8 rates_len)
8033{
8034 u8 i;
8035 u32 mask = 0;
8036
8037 for (i = 0; i < rates_len; i++) {
8038 int rate = (rates[i] & 0x7f) * 5;
8039 int ridx;
8040 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8041 struct ieee80211_rate *srate =
8042 &sband->bitrates[ridx];
8043 if (rate == srate->bitrate) {
8044 mask |= 1 << ridx;
8045 break;
8046 }
8047 }
8048 if (ridx == sband->n_bitrates)
8049 return 0; /* rate not found */
8050 }
8051
8052 return mask;
8053}
8054
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008055static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8056 u8 *rates, u8 rates_len,
8057 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8058{
8059 u8 i;
8060
8061 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8062
8063 for (i = 0; i < rates_len; i++) {
8064 int ridx, rbit;
8065
8066 ridx = rates[i] / 8;
8067 rbit = BIT(rates[i] % 8);
8068
8069 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008070 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008071 return false;
8072
8073 /* check availability */
8074 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8075 mcs[ridx] |= rbit;
8076 else
8077 return false;
8078 }
8079
8080 return true;
8081}
8082
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008083static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8084{
8085 u16 mcs_mask = 0;
8086
8087 switch (vht_mcs_map) {
8088 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8089 break;
8090 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8091 mcs_mask = 0x00FF;
8092 break;
8093 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8094 mcs_mask = 0x01FF;
8095 break;
8096 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8097 mcs_mask = 0x03FF;
8098 break;
8099 default:
8100 break;
8101 }
8102
8103 return mcs_mask;
8104}
8105
8106static void vht_build_mcs_mask(u16 vht_mcs_map,
8107 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8108{
8109 u8 nss;
8110
8111 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8112 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8113 vht_mcs_map >>= 2;
8114 }
8115}
8116
8117static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8118 struct nl80211_txrate_vht *txrate,
8119 u16 mcs[NL80211_VHT_NSS_MAX])
8120{
8121 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8122 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8123 u8 i;
8124
8125 if (!sband->vht_cap.vht_supported)
8126 return false;
8127
8128 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8129
8130 /* Build vht_mcs_mask from VHT capabilities */
8131 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8132
8133 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8134 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8135 mcs[i] = txrate->mcs[i];
8136 else
8137 return false;
8138 }
8139
8140 return true;
8141}
8142
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008143static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008144 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8145 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008146 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8147 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008148 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008149 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008150};
8151
8152static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8153 struct genl_info *info)
8154{
8155 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008156 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008157 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008158 int rem, i;
8159 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008160 struct nlattr *tx_rates;
8161 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008162 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008163
Johannes Berg4c476992010-10-04 21:36:35 +02008164 if (!rdev->ops->set_bitrate_mask)
8165 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008166
8167 memset(&mask, 0, sizeof(mask));
8168 /* Default to all rates enabled */
8169 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8170 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008171
8172 if (!sband)
8173 continue;
8174
8175 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008176 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008177 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008178 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008179
8180 if (!sband->vht_cap.vht_supported)
8181 continue;
8182
8183 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8184 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008185 }
8186
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008187 /* if no rates are given set it back to the defaults */
8188 if (!info->attrs[NL80211_ATTR_TX_RATES])
8189 goto out;
8190
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008191 /*
8192 * The nested attribute uses enum nl80211_band as the index. This maps
8193 * directly to the enum ieee80211_band values used in cfg80211.
8194 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008195 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008196 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008197 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008198 int err;
8199
Johannes Berg4c476992010-10-04 21:36:35 +02008200 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8201 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008202 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008203 if (sband == NULL)
8204 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008205 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8206 nla_len(tx_rates), nl80211_txattr_policy);
8207 if (err)
8208 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008209 if (tb[NL80211_TXRATE_LEGACY]) {
8210 mask.control[band].legacy = rateset_to_mask(
8211 sband,
8212 nla_data(tb[NL80211_TXRATE_LEGACY]),
8213 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308214 if ((mask.control[band].legacy == 0) &&
8215 nla_len(tb[NL80211_TXRATE_LEGACY]))
8216 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008217 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008218 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008219 if (!ht_rateset_to_mask(
8220 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008221 nla_data(tb[NL80211_TXRATE_HT]),
8222 nla_len(tb[NL80211_TXRATE_HT]),
8223 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008224 return -EINVAL;
8225 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008226 if (tb[NL80211_TXRATE_VHT]) {
8227 if (!vht_set_mcs_mask(
8228 sband,
8229 nla_data(tb[NL80211_TXRATE_VHT]),
8230 mask.control[band].vht_mcs))
8231 return -EINVAL;
8232 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008233 if (tb[NL80211_TXRATE_GI]) {
8234 mask.control[band].gi =
8235 nla_get_u8(tb[NL80211_TXRATE_GI]);
8236 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8237 return -EINVAL;
8238 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008239
8240 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008241 /* don't allow empty legacy rates if HT or VHT
8242 * are not even supported.
8243 */
8244 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8245 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008246 return -EINVAL;
8247
8248 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008249 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008250 goto out;
8251
8252 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8253 if (mask.control[band].vht_mcs[i])
8254 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008255
8256 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008257 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008258 }
8259 }
8260
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008261out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008262 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008263}
8264
Johannes Berg2e161f72010-08-12 15:38:38 +02008265static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008266{
Johannes Berg4c476992010-10-04 21:36:35 +02008267 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008268 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008269 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008270
8271 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8272 return -EINVAL;
8273
Johannes Berg2e161f72010-08-12 15:38:38 +02008274 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8275 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008276
Johannes Berg71bbc992012-06-15 15:30:18 +02008277 switch (wdev->iftype) {
8278 case NL80211_IFTYPE_STATION:
8279 case NL80211_IFTYPE_ADHOC:
8280 case NL80211_IFTYPE_P2P_CLIENT:
8281 case NL80211_IFTYPE_AP:
8282 case NL80211_IFTYPE_AP_VLAN:
8283 case NL80211_IFTYPE_MESH_POINT:
8284 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008285 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008286 break;
8287 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008288 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008289 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008290
8291 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008292 if (!rdev->ops->mgmt_tx)
8293 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008294
Eric W. Biederman15e47302012-09-07 20:12:54 +00008295 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008296 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8297 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008298}
8299
Johannes Berg2e161f72010-08-12 15:38:38 +02008300static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008301{
Johannes Berg4c476992010-10-04 21:36:35 +02008302 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008303 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008304 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008305 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008306 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008307 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008308 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008309 struct cfg80211_mgmt_tx_params params = {
8310 .dont_wait_for_ack =
8311 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8312 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008313
Johannes Berg683b6d32012-11-08 21:25:48 +01008314 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008315 return -EINVAL;
8316
Johannes Berg4c476992010-10-04 21:36:35 +02008317 if (!rdev->ops->mgmt_tx)
8318 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008319
Johannes Berg71bbc992012-06-15 15:30:18 +02008320 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008321 case NL80211_IFTYPE_P2P_DEVICE:
8322 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8323 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008324 case NL80211_IFTYPE_STATION:
8325 case NL80211_IFTYPE_ADHOC:
8326 case NL80211_IFTYPE_P2P_CLIENT:
8327 case NL80211_IFTYPE_AP:
8328 case NL80211_IFTYPE_AP_VLAN:
8329 case NL80211_IFTYPE_MESH_POINT:
8330 case NL80211_IFTYPE_P2P_GO:
8331 break;
8332 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008333 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008334 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008335
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008336 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008337 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008338 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008339 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008340
8341 /*
8342 * We should wait on the channel for at least a minimum amount
8343 * of time (10ms) but no longer than the driver supports.
8344 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008345 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8346 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008347 return -EINVAL;
8348
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008349 }
8350
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008351 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008352
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008353 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008354 return -EINVAL;
8355
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008356 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308357
Antonio Quartulliea141b752013-06-11 14:20:03 +02008358 /* get the channel if any has been specified, otherwise pass NULL to
8359 * the driver. The latter will use the current one
8360 */
8361 chandef.chan = NULL;
8362 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8363 err = nl80211_parse_chandef(rdev, info, &chandef);
8364 if (err)
8365 return err;
8366 }
8367
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008368 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008369 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008370
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008371 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8372 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8373
8374 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8375 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8376 int i;
8377
8378 if (len % sizeof(u16))
8379 return -EINVAL;
8380
8381 params.n_csa_offsets = len / sizeof(u16);
8382 params.csa_offsets =
8383 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8384
8385 /* check that all the offsets fit the frame */
8386 for (i = 0; i < params.n_csa_offsets; i++) {
8387 if (params.csa_offsets[i] >= params.len)
8388 return -EINVAL;
8389 }
8390 }
8391
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008392 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008393 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8394 if (!msg)
8395 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008396
Eric W. Biederman15e47302012-09-07 20:12:54 +00008397 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008398 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008399 if (!hdr) {
8400 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008401 goto free_msg;
8402 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008403 }
Johannes Berge247bd902011-11-04 11:18:21 +01008404
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008405 params.chan = chandef.chan;
8406 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008407 if (err)
8408 goto free_msg;
8409
Johannes Berge247bd902011-11-04 11:18:21 +01008410 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008411 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8412 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008413
Johannes Berge247bd902011-11-04 11:18:21 +01008414 genlmsg_end(msg, hdr);
8415 return genlmsg_reply(msg, info);
8416 }
8417
8418 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008419
8420 nla_put_failure:
8421 err = -ENOBUFS;
8422 free_msg:
8423 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008424 return err;
8425}
8426
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008427static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8428{
8429 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008430 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008431 u64 cookie;
8432
8433 if (!info->attrs[NL80211_ATTR_COOKIE])
8434 return -EINVAL;
8435
8436 if (!rdev->ops->mgmt_tx_cancel_wait)
8437 return -EOPNOTSUPP;
8438
Johannes Berg71bbc992012-06-15 15:30:18 +02008439 switch (wdev->iftype) {
8440 case NL80211_IFTYPE_STATION:
8441 case NL80211_IFTYPE_ADHOC:
8442 case NL80211_IFTYPE_P2P_CLIENT:
8443 case NL80211_IFTYPE_AP:
8444 case NL80211_IFTYPE_AP_VLAN:
8445 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008446 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008447 break;
8448 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008449 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008450 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008451
8452 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8453
Hila Gonene35e4d22012-06-27 17:19:42 +03008454 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008455}
8456
Kalle Valoffb9eb32010-02-17 17:58:10 +02008457static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8458{
Johannes Berg4c476992010-10-04 21:36:35 +02008459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008460 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008461 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008462 u8 ps_state;
8463 bool state;
8464 int err;
8465
Johannes Berg4c476992010-10-04 21:36:35 +02008466 if (!info->attrs[NL80211_ATTR_PS_STATE])
8467 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008468
8469 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8470
Johannes Berg4c476992010-10-04 21:36:35 +02008471 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8472 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008473
8474 wdev = dev->ieee80211_ptr;
8475
Johannes Berg4c476992010-10-04 21:36:35 +02008476 if (!rdev->ops->set_power_mgmt)
8477 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008478
8479 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8480
8481 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008482 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008483
Hila Gonene35e4d22012-06-27 17:19:42 +03008484 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008485 if (!err)
8486 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008487 return err;
8488}
8489
8490static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8491{
Johannes Berg4c476992010-10-04 21:36:35 +02008492 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008493 enum nl80211_ps_state ps_state;
8494 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008495 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008496 struct sk_buff *msg;
8497 void *hdr;
8498 int err;
8499
Kalle Valoffb9eb32010-02-17 17:58:10 +02008500 wdev = dev->ieee80211_ptr;
8501
Johannes Berg4c476992010-10-04 21:36:35 +02008502 if (!rdev->ops->set_power_mgmt)
8503 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008504
8505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008506 if (!msg)
8507 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008508
Eric W. Biederman15e47302012-09-07 20:12:54 +00008509 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008510 NL80211_CMD_GET_POWER_SAVE);
8511 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008512 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008513 goto free_msg;
8514 }
8515
8516 if (wdev->ps)
8517 ps_state = NL80211_PS_ENABLED;
8518 else
8519 ps_state = NL80211_PS_DISABLED;
8520
David S. Miller9360ffd2012-03-29 04:41:26 -04008521 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8522 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008523
8524 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008525 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008526
Johannes Berg4c476992010-10-04 21:36:35 +02008527 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008528 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008529 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008530 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008531 return err;
8532}
8533
Johannes Berg94e860f2014-01-20 23:58:15 +01008534static const struct nla_policy
8535nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008536 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8537 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8538 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008539 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8540 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8541 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008542};
8543
Thomas Pedersen84f10702012-07-12 16:17:33 -07008544static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008545 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008546{
8547 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008548 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008549 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008550
Johannes Bergd9d8b012012-11-26 12:51:52 +01008551 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008552 return -EINVAL;
8553
Thomas Pedersen84f10702012-07-12 16:17:33 -07008554 if (!rdev->ops->set_cqm_txe_config)
8555 return -EOPNOTSUPP;
8556
8557 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8558 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8559 return -EOPNOTSUPP;
8560
Hila Gonene35e4d22012-06-27 17:19:42 +03008561 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008562}
8563
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008564static int nl80211_set_cqm_rssi(struct genl_info *info,
8565 s32 threshold, u32 hysteresis)
8566{
Johannes Berg4c476992010-10-04 21:36:35 +02008567 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008568 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008569 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008570
8571 if (threshold > 0)
8572 return -EINVAL;
8573
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008574 /* disabling - hysteresis should also be zero then */
8575 if (threshold == 0)
8576 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008577
Johannes Berg4c476992010-10-04 21:36:35 +02008578 if (!rdev->ops->set_cqm_rssi_config)
8579 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008580
Johannes Berg074ac8d2010-09-16 14:58:22 +02008581 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008582 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8583 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008584
Hila Gonene35e4d22012-06-27 17:19:42 +03008585 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008586}
8587
8588static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8589{
8590 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8591 struct nlattr *cqm;
8592 int err;
8593
8594 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008595 if (!cqm)
8596 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008597
8598 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8599 nl80211_attr_cqm_policy);
8600 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008601 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008602
8603 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8604 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008605 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8606 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008607
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008608 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8609 }
8610
8611 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8612 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8613 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8614 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8615 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8616 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8617
8618 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8619 }
8620
8621 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008622}
8623
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008624static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8625{
8626 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8627 struct net_device *dev = info->user_ptr[1];
8628 struct ocb_setup setup = {};
8629 int err;
8630
8631 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8632 if (err)
8633 return err;
8634
8635 return cfg80211_join_ocb(rdev, dev, &setup);
8636}
8637
8638static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8639{
8640 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8641 struct net_device *dev = info->user_ptr[1];
8642
8643 return cfg80211_leave_ocb(rdev, dev);
8644}
8645
Johannes Berg29cbe682010-12-03 09:20:44 +01008646static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8647{
8648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8649 struct net_device *dev = info->user_ptr[1];
8650 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008651 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008652 int err;
8653
8654 /* start with default */
8655 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008656 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008657
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008658 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008659 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008660 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008661 if (err)
8662 return err;
8663 }
8664
8665 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8666 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8667 return -EINVAL;
8668
Javier Cardonac80d5452010-12-16 17:37:49 -08008669 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8670 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8671
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008672 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8673 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8674 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8675 return -EINVAL;
8676
Marco Porsch9bdbf042013-01-07 16:04:51 +01008677 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8678 setup.beacon_interval =
8679 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8680 if (setup.beacon_interval < 10 ||
8681 setup.beacon_interval > 10000)
8682 return -EINVAL;
8683 }
8684
8685 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8686 setup.dtim_period =
8687 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8688 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8689 return -EINVAL;
8690 }
8691
Javier Cardonac80d5452010-12-16 17:37:49 -08008692 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8693 /* parse additional setup parameters if given */
8694 err = nl80211_parse_mesh_setup(info, &setup);
8695 if (err)
8696 return err;
8697 }
8698
Thomas Pedersend37bb182013-03-04 13:06:13 -08008699 if (setup.user_mpm)
8700 cfg.auto_open_plinks = false;
8701
Johannes Bergcc1d2802012-05-16 23:50:20 +02008702 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008703 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8704 if (err)
8705 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008706 } else {
8707 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008708 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008709 }
8710
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008711 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8712 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8713 int n_rates =
8714 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8715 struct ieee80211_supported_band *sband;
8716
8717 if (!setup.chandef.chan)
8718 return -EINVAL;
8719
8720 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8721
8722 err = ieee80211_get_ratemask(sband, rates, n_rates,
8723 &setup.basic_rates);
8724 if (err)
8725 return err;
8726 }
8727
Javier Cardonac80d5452010-12-16 17:37:49 -08008728 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008729}
8730
8731static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8732{
8733 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8734 struct net_device *dev = info->user_ptr[1];
8735
8736 return cfg80211_leave_mesh(rdev, dev);
8737}
8738
Johannes Bergdfb89c52012-06-27 09:23:48 +02008739#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008740static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8741 struct cfg80211_registered_device *rdev)
8742{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008743 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008744 struct nlattr *nl_pats, *nl_pat;
8745 int i, pat_len;
8746
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008747 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008748 return 0;
8749
8750 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8751 if (!nl_pats)
8752 return -ENOBUFS;
8753
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008754 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008755 nl_pat = nla_nest_start(msg, i + 1);
8756 if (!nl_pat)
8757 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008758 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008759 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008760 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008761 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8762 wowlan->patterns[i].pattern) ||
8763 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008764 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008765 return -ENOBUFS;
8766 nla_nest_end(msg, nl_pat);
8767 }
8768 nla_nest_end(msg, nl_pats);
8769
8770 return 0;
8771}
8772
Johannes Berg2a0e0472013-01-23 22:57:40 +01008773static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8774 struct cfg80211_wowlan_tcp *tcp)
8775{
8776 struct nlattr *nl_tcp;
8777
8778 if (!tcp)
8779 return 0;
8780
8781 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8782 if (!nl_tcp)
8783 return -ENOBUFS;
8784
8785 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8786 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8787 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8788 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8789 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8790 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8791 tcp->payload_len, tcp->payload) ||
8792 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8793 tcp->data_interval) ||
8794 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8795 tcp->wake_len, tcp->wake_data) ||
8796 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8797 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8798 return -ENOBUFS;
8799
8800 if (tcp->payload_seq.len &&
8801 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8802 sizeof(tcp->payload_seq), &tcp->payload_seq))
8803 return -ENOBUFS;
8804
8805 if (tcp->payload_tok.len &&
8806 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8807 sizeof(tcp->payload_tok) + tcp->tokens_size,
8808 &tcp->payload_tok))
8809 return -ENOBUFS;
8810
Johannes Berge248ad32013-05-16 10:24:28 +02008811 nla_nest_end(msg, nl_tcp);
8812
Johannes Berg2a0e0472013-01-23 22:57:40 +01008813 return 0;
8814}
8815
Luciano Coelho75453cc2015-01-09 14:06:37 +02008816static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8817 struct cfg80211_sched_scan_request *req)
8818{
8819 struct nlattr *nd, *freqs, *matches, *match;
8820 int i;
8821
8822 if (!req)
8823 return 0;
8824
8825 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
8826 if (!nd)
8827 return -ENOBUFS;
8828
8829 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval))
8830 return -ENOBUFS;
8831
Luciano Coelho21fea562015-03-17 16:36:01 +02008832 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
8833 return -ENOBUFS;
8834
Luciano Coelho75453cc2015-01-09 14:06:37 +02008835 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8836 if (!freqs)
8837 return -ENOBUFS;
8838
8839 for (i = 0; i < req->n_channels; i++)
8840 nla_put_u32(msg, i, req->channels[i]->center_freq);
8841
8842 nla_nest_end(msg, freqs);
8843
8844 if (req->n_match_sets) {
8845 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
8846 for (i = 0; i < req->n_match_sets; i++) {
8847 match = nla_nest_start(msg, i);
8848 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
8849 req->match_sets[i].ssid.ssid_len,
8850 req->match_sets[i].ssid.ssid);
8851 nla_nest_end(msg, match);
8852 }
8853 nla_nest_end(msg, matches);
8854 }
8855
8856 nla_nest_end(msg, nd);
8857
8858 return 0;
8859}
8860
Johannes Bergff1b6e62011-05-04 15:37:28 +02008861static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8862{
8863 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8864 struct sk_buff *msg;
8865 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008866 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008867
Johannes Berg964dc9e2013-06-03 17:25:34 +02008868 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008869 return -EOPNOTSUPP;
8870
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008871 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008872 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008873 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8874 rdev->wiphy.wowlan_config->tcp->payload_len +
8875 rdev->wiphy.wowlan_config->tcp->wake_len +
8876 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008877 }
8878
8879 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008880 if (!msg)
8881 return -ENOMEM;
8882
Eric W. Biederman15e47302012-09-07 20:12:54 +00008883 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008884 NL80211_CMD_GET_WOWLAN);
8885 if (!hdr)
8886 goto nla_put_failure;
8887
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008888 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008889 struct nlattr *nl_wowlan;
8890
8891 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8892 if (!nl_wowlan)
8893 goto nla_put_failure;
8894
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008895 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008896 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008897 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008898 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008899 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008900 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008901 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008902 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008903 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008904 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008905 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008906 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008907 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008908 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8909 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008910
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008911 if (nl80211_send_wowlan_patterns(msg, rdev))
8912 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008913
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008914 if (nl80211_send_wowlan_tcp(msg,
8915 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008916 goto nla_put_failure;
8917
Luciano Coelho75453cc2015-01-09 14:06:37 +02008918 if (nl80211_send_wowlan_nd(
8919 msg,
8920 rdev->wiphy.wowlan_config->nd_config))
8921 goto nla_put_failure;
8922
Johannes Bergff1b6e62011-05-04 15:37:28 +02008923 nla_nest_end(msg, nl_wowlan);
8924 }
8925
8926 genlmsg_end(msg, hdr);
8927 return genlmsg_reply(msg, info);
8928
8929nla_put_failure:
8930 nlmsg_free(msg);
8931 return -ENOBUFS;
8932}
8933
Johannes Berg2a0e0472013-01-23 22:57:40 +01008934static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8935 struct nlattr *attr,
8936 struct cfg80211_wowlan *trig)
8937{
8938 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8939 struct cfg80211_wowlan_tcp *cfg;
8940 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8941 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8942 u32 size;
8943 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8944 int err, port;
8945
Johannes Berg964dc9e2013-06-03 17:25:34 +02008946 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008947 return -EINVAL;
8948
8949 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8950 nla_data(attr), nla_len(attr),
8951 nl80211_wowlan_tcp_policy);
8952 if (err)
8953 return err;
8954
8955 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8956 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8957 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8958 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8959 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8960 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8961 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8962 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8963 return -EINVAL;
8964
8965 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008966 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008967 return -EINVAL;
8968
8969 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008970 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008971 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008972 return -EINVAL;
8973
8974 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008975 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008976 return -EINVAL;
8977
8978 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8979 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8980 return -EINVAL;
8981
8982 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8983 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8984
8985 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8986 tokens_size = tokln - sizeof(*tok);
8987
8988 if (!tok->len || tokens_size % tok->len)
8989 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008990 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008991 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008992 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008993 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008994 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008995 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008996 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008997 return -EINVAL;
8998 if (tok->offset + tok->len > data_size)
8999 return -EINVAL;
9000 }
9001
9002 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9003 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009004 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009005 return -EINVAL;
9006 if (seq->len == 0 || seq->len > 4)
9007 return -EINVAL;
9008 if (seq->len + seq->offset > data_size)
9009 return -EINVAL;
9010 }
9011
9012 size = sizeof(*cfg);
9013 size += data_size;
9014 size += wake_size + wake_mask_size;
9015 size += tokens_size;
9016
9017 cfg = kzalloc(size, GFP_KERNEL);
9018 if (!cfg)
9019 return -ENOMEM;
9020 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9021 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
9022 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9023 ETH_ALEN);
9024 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9025 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9026 else
9027 port = 0;
9028#ifdef CONFIG_INET
9029 /* allocate a socket and port for it and use it */
9030 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9031 IPPROTO_TCP, &cfg->sock, 1);
9032 if (err) {
9033 kfree(cfg);
9034 return err;
9035 }
9036 if (inet_csk_get_port(cfg->sock->sk, port)) {
9037 sock_release(cfg->sock);
9038 kfree(cfg);
9039 return -EADDRINUSE;
9040 }
9041 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9042#else
9043 if (!port) {
9044 kfree(cfg);
9045 return -EINVAL;
9046 }
9047 cfg->src_port = port;
9048#endif
9049
9050 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9051 cfg->payload_len = data_size;
9052 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9053 memcpy((void *)cfg->payload,
9054 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9055 data_size);
9056 if (seq)
9057 cfg->payload_seq = *seq;
9058 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9059 cfg->wake_len = wake_size;
9060 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9061 memcpy((void *)cfg->wake_data,
9062 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9063 wake_size);
9064 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9065 data_size + wake_size;
9066 memcpy((void *)cfg->wake_mask,
9067 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9068 wake_mask_size);
9069 if (tok) {
9070 cfg->tokens_size = tokens_size;
9071 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9072 }
9073
9074 trig->tcp = cfg;
9075
9076 return 0;
9077}
9078
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009079static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9080 const struct wiphy_wowlan_support *wowlan,
9081 struct nlattr *attr,
9082 struct cfg80211_wowlan *trig)
9083{
9084 struct nlattr **tb;
9085 int err;
9086
9087 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9088 if (!tb)
9089 return -ENOMEM;
9090
9091 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9092 err = -EOPNOTSUPP;
9093 goto out;
9094 }
9095
9096 err = nla_parse(tb, NL80211_ATTR_MAX,
9097 nla_data(attr), nla_len(attr),
9098 nl80211_policy);
9099 if (err)
9100 goto out;
9101
Johannes Bergad2b26a2014-06-12 21:39:05 +02009102 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009103 err = PTR_ERR_OR_ZERO(trig->nd_config);
9104 if (err)
9105 trig->nd_config = NULL;
9106
9107out:
9108 kfree(tb);
9109 return err;
9110}
9111
Johannes Bergff1b6e62011-05-04 15:37:28 +02009112static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9113{
9114 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9115 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009116 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009117 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009118 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009119 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009120 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009121 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009122
Johannes Berg964dc9e2013-06-03 17:25:34 +02009123 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009124 return -EOPNOTSUPP;
9125
Johannes Bergae33bd82012-07-12 16:25:02 +02009126 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9127 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009128 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009129 goto set_wakeup;
9130 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009131
9132 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9133 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9134 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9135 nl80211_wowlan_policy);
9136 if (err)
9137 return err;
9138
9139 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9140 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9141 return -EINVAL;
9142 new_triggers.any = true;
9143 }
9144
9145 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9146 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9147 return -EINVAL;
9148 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009149 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009150 }
9151
9152 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9153 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9154 return -EINVAL;
9155 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009156 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009157 }
9158
Johannes Berg77dbbb12011-07-13 10:48:55 +02009159 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9160 return -EINVAL;
9161
9162 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9163 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9164 return -EINVAL;
9165 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009166 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009167 }
9168
9169 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9170 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9171 return -EINVAL;
9172 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009173 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009174 }
9175
9176 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9177 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9178 return -EINVAL;
9179 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009180 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009181 }
9182
9183 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9184 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9185 return -EINVAL;
9186 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009187 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009188 }
9189
Johannes Bergff1b6e62011-05-04 15:37:28 +02009190 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9191 struct nlattr *pat;
9192 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009193 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009194 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009195
Johannes Berg98fc4382015-03-01 09:10:13 +02009196 regular = true;
9197
Johannes Bergff1b6e62011-05-04 15:37:28 +02009198 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9199 rem)
9200 n_patterns++;
9201 if (n_patterns > wowlan->n_patterns)
9202 return -EINVAL;
9203
9204 new_triggers.patterns = kcalloc(n_patterns,
9205 sizeof(new_triggers.patterns[0]),
9206 GFP_KERNEL);
9207 if (!new_triggers.patterns)
9208 return -ENOMEM;
9209
9210 new_triggers.n_patterns = n_patterns;
9211 i = 0;
9212
9213 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9214 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009215 u8 *mask_pat;
9216
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009217 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9218 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009219 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009220 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9221 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009222 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009223 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009224 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009225 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009226 goto error;
9227 if (pat_len > wowlan->pattern_max_len ||
9228 pat_len < wowlan->pattern_min_len)
9229 goto error;
9230
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009231 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009232 pkt_offset = 0;
9233 else
9234 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009235 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009236 if (pkt_offset > wowlan->max_pkt_offset)
9237 goto error;
9238 new_triggers.patterns[i].pkt_offset = pkt_offset;
9239
Johannes Berg922bd802014-05-19 17:59:50 +02009240 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9241 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009242 err = -ENOMEM;
9243 goto error;
9244 }
Johannes Berg922bd802014-05-19 17:59:50 +02009245 new_triggers.patterns[i].mask = mask_pat;
9246 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009247 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009248 mask_pat += mask_len;
9249 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009250 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009251 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009252 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009253 pat_len);
9254 i++;
9255 }
9256 }
9257
Johannes Berg2a0e0472013-01-23 22:57:40 +01009258 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009259 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009260 err = nl80211_parse_wowlan_tcp(
9261 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9262 &new_triggers);
9263 if (err)
9264 goto error;
9265 }
9266
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009267 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009268 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009269 err = nl80211_parse_wowlan_nd(
9270 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9271 &new_triggers);
9272 if (err)
9273 goto error;
9274 }
9275
Johannes Berg98fc4382015-03-01 09:10:13 +02009276 /* The 'any' trigger means the device continues operating more or less
9277 * as in its normal operation mode and wakes up the host on most of the
9278 * normal interrupts (like packet RX, ...)
9279 * It therefore makes little sense to combine with the more constrained
9280 * wakeup trigger modes.
9281 */
9282 if (new_triggers.any && regular) {
9283 err = -EINVAL;
9284 goto error;
9285 }
9286
Johannes Bergae33bd82012-07-12 16:25:02 +02009287 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9288 if (!ntrig) {
9289 err = -ENOMEM;
9290 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009291 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009292 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009293 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009294
Johannes Bergae33bd82012-07-12 16:25:02 +02009295 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009296 if (rdev->ops->set_wakeup &&
9297 prev_enabled != !!rdev->wiphy.wowlan_config)
9298 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009299
Johannes Bergff1b6e62011-05-04 15:37:28 +02009300 return 0;
9301 error:
9302 for (i = 0; i < new_triggers.n_patterns; i++)
9303 kfree(new_triggers.patterns[i].mask);
9304 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009305 if (new_triggers.tcp && new_triggers.tcp->sock)
9306 sock_release(new_triggers.tcp->sock);
9307 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009308 return err;
9309}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009310#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009311
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009312static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9313 struct cfg80211_registered_device *rdev)
9314{
9315 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9316 int i, j, pat_len;
9317 struct cfg80211_coalesce_rules *rule;
9318
9319 if (!rdev->coalesce->n_rules)
9320 return 0;
9321
9322 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9323 if (!nl_rules)
9324 return -ENOBUFS;
9325
9326 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9327 nl_rule = nla_nest_start(msg, i + 1);
9328 if (!nl_rule)
9329 return -ENOBUFS;
9330
9331 rule = &rdev->coalesce->rules[i];
9332 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9333 rule->delay))
9334 return -ENOBUFS;
9335
9336 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9337 rule->condition))
9338 return -ENOBUFS;
9339
9340 nl_pats = nla_nest_start(msg,
9341 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9342 if (!nl_pats)
9343 return -ENOBUFS;
9344
9345 for (j = 0; j < rule->n_patterns; j++) {
9346 nl_pat = nla_nest_start(msg, j + 1);
9347 if (!nl_pat)
9348 return -ENOBUFS;
9349 pat_len = rule->patterns[j].pattern_len;
9350 if (nla_put(msg, NL80211_PKTPAT_MASK,
9351 DIV_ROUND_UP(pat_len, 8),
9352 rule->patterns[j].mask) ||
9353 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9354 rule->patterns[j].pattern) ||
9355 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9356 rule->patterns[j].pkt_offset))
9357 return -ENOBUFS;
9358 nla_nest_end(msg, nl_pat);
9359 }
9360 nla_nest_end(msg, nl_pats);
9361 nla_nest_end(msg, nl_rule);
9362 }
9363 nla_nest_end(msg, nl_rules);
9364
9365 return 0;
9366}
9367
9368static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9369{
9370 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9371 struct sk_buff *msg;
9372 void *hdr;
9373
9374 if (!rdev->wiphy.coalesce)
9375 return -EOPNOTSUPP;
9376
9377 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9378 if (!msg)
9379 return -ENOMEM;
9380
9381 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9382 NL80211_CMD_GET_COALESCE);
9383 if (!hdr)
9384 goto nla_put_failure;
9385
9386 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9387 goto nla_put_failure;
9388
9389 genlmsg_end(msg, hdr);
9390 return genlmsg_reply(msg, info);
9391
9392nla_put_failure:
9393 nlmsg_free(msg);
9394 return -ENOBUFS;
9395}
9396
9397void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9398{
9399 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9400 int i, j;
9401 struct cfg80211_coalesce_rules *rule;
9402
9403 if (!coalesce)
9404 return;
9405
9406 for (i = 0; i < coalesce->n_rules; i++) {
9407 rule = &coalesce->rules[i];
9408 for (j = 0; j < rule->n_patterns; j++)
9409 kfree(rule->patterns[j].mask);
9410 kfree(rule->patterns);
9411 }
9412 kfree(coalesce->rules);
9413 kfree(coalesce);
9414 rdev->coalesce = NULL;
9415}
9416
9417static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9418 struct nlattr *rule,
9419 struct cfg80211_coalesce_rules *new_rule)
9420{
9421 int err, i;
9422 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9423 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9424 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9425 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9426
9427 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9428 nla_len(rule), nl80211_coalesce_policy);
9429 if (err)
9430 return err;
9431
9432 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9433 new_rule->delay =
9434 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9435 if (new_rule->delay > coalesce->max_delay)
9436 return -EINVAL;
9437
9438 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9439 new_rule->condition =
9440 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9441 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9442 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9443 return -EINVAL;
9444
9445 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9446 return -EINVAL;
9447
9448 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9449 rem)
9450 n_patterns++;
9451 if (n_patterns > coalesce->n_patterns)
9452 return -EINVAL;
9453
9454 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9455 GFP_KERNEL);
9456 if (!new_rule->patterns)
9457 return -ENOMEM;
9458
9459 new_rule->n_patterns = n_patterns;
9460 i = 0;
9461
9462 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9463 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009464 u8 *mask_pat;
9465
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009466 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9467 nla_len(pat), NULL);
9468 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9469 !pat_tb[NL80211_PKTPAT_PATTERN])
9470 return -EINVAL;
9471 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9472 mask_len = DIV_ROUND_UP(pat_len, 8);
9473 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9474 return -EINVAL;
9475 if (pat_len > coalesce->pattern_max_len ||
9476 pat_len < coalesce->pattern_min_len)
9477 return -EINVAL;
9478
9479 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9480 pkt_offset = 0;
9481 else
9482 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9483 if (pkt_offset > coalesce->max_pkt_offset)
9484 return -EINVAL;
9485 new_rule->patterns[i].pkt_offset = pkt_offset;
9486
Johannes Berg922bd802014-05-19 17:59:50 +02009487 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9488 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009489 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009490
9491 new_rule->patterns[i].mask = mask_pat;
9492 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9493 mask_len);
9494
9495 mask_pat += mask_len;
9496 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009497 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009498 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9499 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009500 i++;
9501 }
9502
9503 return 0;
9504}
9505
9506static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9507{
9508 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9509 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9510 struct cfg80211_coalesce new_coalesce = {};
9511 struct cfg80211_coalesce *n_coalesce;
9512 int err, rem_rule, n_rules = 0, i, j;
9513 struct nlattr *rule;
9514 struct cfg80211_coalesce_rules *tmp_rule;
9515
9516 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9517 return -EOPNOTSUPP;
9518
9519 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9520 cfg80211_rdev_free_coalesce(rdev);
9521 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9522 return 0;
9523 }
9524
9525 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9526 rem_rule)
9527 n_rules++;
9528 if (n_rules > coalesce->n_rules)
9529 return -EINVAL;
9530
9531 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9532 GFP_KERNEL);
9533 if (!new_coalesce.rules)
9534 return -ENOMEM;
9535
9536 new_coalesce.n_rules = n_rules;
9537 i = 0;
9538
9539 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9540 rem_rule) {
9541 err = nl80211_parse_coalesce_rule(rdev, rule,
9542 &new_coalesce.rules[i]);
9543 if (err)
9544 goto error;
9545
9546 i++;
9547 }
9548
9549 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9550 if (err)
9551 goto error;
9552
9553 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9554 if (!n_coalesce) {
9555 err = -ENOMEM;
9556 goto error;
9557 }
9558 cfg80211_rdev_free_coalesce(rdev);
9559 rdev->coalesce = n_coalesce;
9560
9561 return 0;
9562error:
9563 for (i = 0; i < new_coalesce.n_rules; i++) {
9564 tmp_rule = &new_coalesce.rules[i];
9565 for (j = 0; j < tmp_rule->n_patterns; j++)
9566 kfree(tmp_rule->patterns[j].mask);
9567 kfree(tmp_rule->patterns);
9568 }
9569 kfree(new_coalesce.rules);
9570
9571 return err;
9572}
9573
Johannes Berge5497d72011-07-05 16:35:40 +02009574static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9575{
9576 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9577 struct net_device *dev = info->user_ptr[1];
9578 struct wireless_dev *wdev = dev->ieee80211_ptr;
9579 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9580 struct cfg80211_gtk_rekey_data rekey_data;
9581 int err;
9582
9583 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9584 return -EINVAL;
9585
9586 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9587 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9588 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9589 nl80211_rekey_policy);
9590 if (err)
9591 return err;
9592
9593 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9594 return -ERANGE;
9595 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9596 return -ERANGE;
9597 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9598 return -ERANGE;
9599
Johannes Berg78f686c2014-09-10 22:28:06 +03009600 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9601 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9602 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009603
9604 wdev_lock(wdev);
9605 if (!wdev->current_bss) {
9606 err = -ENOTCONN;
9607 goto out;
9608 }
9609
9610 if (!rdev->ops->set_rekey_data) {
9611 err = -EOPNOTSUPP;
9612 goto out;
9613 }
9614
Hila Gonene35e4d22012-06-27 17:19:42 +03009615 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009616 out:
9617 wdev_unlock(wdev);
9618 return err;
9619}
9620
Johannes Berg28946da2011-11-04 11:18:12 +01009621static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9622 struct genl_info *info)
9623{
9624 struct net_device *dev = info->user_ptr[1];
9625 struct wireless_dev *wdev = dev->ieee80211_ptr;
9626
9627 if (wdev->iftype != NL80211_IFTYPE_AP &&
9628 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9629 return -EINVAL;
9630
Eric W. Biederman15e47302012-09-07 20:12:54 +00009631 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009632 return -EBUSY;
9633
Eric W. Biederman15e47302012-09-07 20:12:54 +00009634 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009635 return 0;
9636}
9637
Johannes Berg7f6cf312011-11-04 11:18:15 +01009638static int nl80211_probe_client(struct sk_buff *skb,
9639 struct genl_info *info)
9640{
9641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9642 struct net_device *dev = info->user_ptr[1];
9643 struct wireless_dev *wdev = dev->ieee80211_ptr;
9644 struct sk_buff *msg;
9645 void *hdr;
9646 const u8 *addr;
9647 u64 cookie;
9648 int err;
9649
9650 if (wdev->iftype != NL80211_IFTYPE_AP &&
9651 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9652 return -EOPNOTSUPP;
9653
9654 if (!info->attrs[NL80211_ATTR_MAC])
9655 return -EINVAL;
9656
9657 if (!rdev->ops->probe_client)
9658 return -EOPNOTSUPP;
9659
9660 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9661 if (!msg)
9662 return -ENOMEM;
9663
Eric W. Biederman15e47302012-09-07 20:12:54 +00009664 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009665 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009666 if (!hdr) {
9667 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009668 goto free_msg;
9669 }
9670
9671 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9672
Hila Gonene35e4d22012-06-27 17:19:42 +03009673 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009674 if (err)
9675 goto free_msg;
9676
David S. Miller9360ffd2012-03-29 04:41:26 -04009677 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9678 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009679
9680 genlmsg_end(msg, hdr);
9681
9682 return genlmsg_reply(msg, info);
9683
9684 nla_put_failure:
9685 err = -ENOBUFS;
9686 free_msg:
9687 nlmsg_free(msg);
9688 return err;
9689}
9690
Johannes Berg5e760232011-11-04 11:18:17 +01009691static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9692{
9693 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009694 struct cfg80211_beacon_registration *reg, *nreg;
9695 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009696
9697 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9698 return -EOPNOTSUPP;
9699
Ben Greear37c73b52012-10-26 14:49:25 -07009700 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9701 if (!nreg)
9702 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009703
Ben Greear37c73b52012-10-26 14:49:25 -07009704 /* First, check if already registered. */
9705 spin_lock_bh(&rdev->beacon_registrations_lock);
9706 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9707 if (reg->nlportid == info->snd_portid) {
9708 rv = -EALREADY;
9709 goto out_err;
9710 }
9711 }
9712 /* Add it to the list */
9713 nreg->nlportid = info->snd_portid;
9714 list_add(&nreg->list, &rdev->beacon_registrations);
9715
9716 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009717
9718 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009719out_err:
9720 spin_unlock_bh(&rdev->beacon_registrations_lock);
9721 kfree(nreg);
9722 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009723}
9724
Johannes Berg98104fde2012-06-16 00:19:54 +02009725static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9726{
9727 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9728 struct wireless_dev *wdev = info->user_ptr[1];
9729 int err;
9730
9731 if (!rdev->ops->start_p2p_device)
9732 return -EOPNOTSUPP;
9733
9734 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9735 return -EOPNOTSUPP;
9736
9737 if (wdev->p2p_started)
9738 return 0;
9739
Luciano Coelhob6a55012014-02-27 11:07:21 +02009740 if (rfkill_blocked(rdev->rfkill))
9741 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009742
Johannes Bergeeb126e2012-10-23 15:16:50 +02009743 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009744 if (err)
9745 return err;
9746
9747 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009748 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009749
9750 return 0;
9751}
9752
9753static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9754{
9755 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9756 struct wireless_dev *wdev = info->user_ptr[1];
9757
9758 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9759 return -EOPNOTSUPP;
9760
9761 if (!rdev->ops->stop_p2p_device)
9762 return -EOPNOTSUPP;
9763
Johannes Bergf9f47522013-03-19 15:04:07 +01009764 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009765
9766 return 0;
9767}
9768
Johannes Berg3713b4e2013-02-14 16:19:38 +01009769static int nl80211_get_protocol_features(struct sk_buff *skb,
9770 struct genl_info *info)
9771{
9772 void *hdr;
9773 struct sk_buff *msg;
9774
9775 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9776 if (!msg)
9777 return -ENOMEM;
9778
9779 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9780 NL80211_CMD_GET_PROTOCOL_FEATURES);
9781 if (!hdr)
9782 goto nla_put_failure;
9783
9784 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9785 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9786 goto nla_put_failure;
9787
9788 genlmsg_end(msg, hdr);
9789 return genlmsg_reply(msg, info);
9790
9791 nla_put_failure:
9792 kfree_skb(msg);
9793 return -ENOBUFS;
9794}
9795
Jouni Malinen355199e2013-02-27 17:14:27 +02009796static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9797{
9798 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9799 struct cfg80211_update_ft_ies_params ft_params;
9800 struct net_device *dev = info->user_ptr[1];
9801
9802 if (!rdev->ops->update_ft_ies)
9803 return -EOPNOTSUPP;
9804
9805 if (!info->attrs[NL80211_ATTR_MDID] ||
9806 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9807 return -EINVAL;
9808
9809 memset(&ft_params, 0, sizeof(ft_params));
9810 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9811 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9812 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9813
9814 return rdev_update_ft_ies(rdev, dev, &ft_params);
9815}
9816
Arend van Spriel5de17982013-04-18 15:49:00 +02009817static int nl80211_crit_protocol_start(struct sk_buff *skb,
9818 struct genl_info *info)
9819{
9820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9821 struct wireless_dev *wdev = info->user_ptr[1];
9822 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9823 u16 duration;
9824 int ret;
9825
9826 if (!rdev->ops->crit_proto_start)
9827 return -EOPNOTSUPP;
9828
9829 if (WARN_ON(!rdev->ops->crit_proto_stop))
9830 return -EINVAL;
9831
9832 if (rdev->crit_proto_nlportid)
9833 return -EBUSY;
9834
9835 /* determine protocol if provided */
9836 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9837 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9838
9839 if (proto >= NUM_NL80211_CRIT_PROTO)
9840 return -EINVAL;
9841
9842 /* timeout must be provided */
9843 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9844 return -EINVAL;
9845
9846 duration =
9847 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9848
9849 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9850 return -ERANGE;
9851
9852 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9853 if (!ret)
9854 rdev->crit_proto_nlportid = info->snd_portid;
9855
9856 return ret;
9857}
9858
9859static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9860 struct genl_info *info)
9861{
9862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9863 struct wireless_dev *wdev = info->user_ptr[1];
9864
9865 if (!rdev->ops->crit_proto_stop)
9866 return -EOPNOTSUPP;
9867
9868 if (rdev->crit_proto_nlportid) {
9869 rdev->crit_proto_nlportid = 0;
9870 rdev_crit_proto_stop(rdev, wdev);
9871 }
9872 return 0;
9873}
9874
Johannes Bergad7e7182013-11-13 13:37:47 +01009875static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9876{
9877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9878 struct wireless_dev *wdev =
9879 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9880 int i, err;
9881 u32 vid, subcmd;
9882
9883 if (!rdev->wiphy.vendor_commands)
9884 return -EOPNOTSUPP;
9885
9886 if (IS_ERR(wdev)) {
9887 err = PTR_ERR(wdev);
9888 if (err != -EINVAL)
9889 return err;
9890 wdev = NULL;
9891 } else if (wdev->wiphy != &rdev->wiphy) {
9892 return -EINVAL;
9893 }
9894
9895 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9896 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9897 return -EINVAL;
9898
9899 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9900 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9901 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9902 const struct wiphy_vendor_command *vcmd;
9903 void *data = NULL;
9904 int len = 0;
9905
9906 vcmd = &rdev->wiphy.vendor_commands[i];
9907
9908 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9909 continue;
9910
9911 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9912 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9913 if (!wdev)
9914 return -EINVAL;
9915 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9916 !wdev->netdev)
9917 return -EINVAL;
9918
9919 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9920 if (wdev->netdev &&
9921 !netif_running(wdev->netdev))
9922 return -ENETDOWN;
9923 if (!wdev->netdev && !wdev->p2p_started)
9924 return -ENETDOWN;
9925 }
9926 } else {
9927 wdev = NULL;
9928 }
9929
9930 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9931 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9932 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9933 }
9934
9935 rdev->cur_cmd_info = info;
9936 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9937 data, len);
9938 rdev->cur_cmd_info = NULL;
9939 return err;
9940 }
9941
9942 return -EOPNOTSUPP;
9943}
9944
9945struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9946 enum nl80211_commands cmd,
9947 enum nl80211_attrs attr,
9948 int approxlen)
9949{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009950 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009951
9952 if (WARN_ON(!rdev->cur_cmd_info))
9953 return NULL;
9954
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009955 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +01009956 rdev->cur_cmd_info->snd_portid,
9957 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009958 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009959}
9960EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9961
9962int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9963{
9964 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9965 void *hdr = ((void **)skb->cb)[1];
9966 struct nlattr *data = ((void **)skb->cb)[2];
9967
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009968 /* clear CB data for netlink core to own from now on */
9969 memset(skb->cb, 0, sizeof(skb->cb));
9970
Johannes Bergad7e7182013-11-13 13:37:47 +01009971 if (WARN_ON(!rdev->cur_cmd_info)) {
9972 kfree_skb(skb);
9973 return -EINVAL;
9974 }
9975
9976 nla_nest_end(skb, data);
9977 genlmsg_end(skb, hdr);
9978 return genlmsg_reply(skb, rdev->cur_cmd_info);
9979}
9980EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9981
9982
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009983static int nl80211_set_qos_map(struct sk_buff *skb,
9984 struct genl_info *info)
9985{
9986 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9987 struct cfg80211_qos_map *qos_map = NULL;
9988 struct net_device *dev = info->user_ptr[1];
9989 u8 *pos, len, num_des, des_len, des;
9990 int ret;
9991
9992 if (!rdev->ops->set_qos_map)
9993 return -EOPNOTSUPP;
9994
9995 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9996 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9997 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9998
9999 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10000 len > IEEE80211_QOS_MAP_LEN_MAX)
10001 return -EINVAL;
10002
10003 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10004 if (!qos_map)
10005 return -ENOMEM;
10006
10007 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10008 if (num_des) {
10009 des_len = num_des *
10010 sizeof(struct cfg80211_dscp_exception);
10011 memcpy(qos_map->dscp_exception, pos, des_len);
10012 qos_map->num_des = num_des;
10013 for (des = 0; des < num_des; des++) {
10014 if (qos_map->dscp_exception[des].up > 7) {
10015 kfree(qos_map);
10016 return -EINVAL;
10017 }
10018 }
10019 pos += des_len;
10020 }
10021 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10022 }
10023
10024 wdev_lock(dev->ieee80211_ptr);
10025 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10026 if (!ret)
10027 ret = rdev_set_qos_map(rdev, dev, qos_map);
10028 wdev_unlock(dev->ieee80211_ptr);
10029
10030 kfree(qos_map);
10031 return ret;
10032}
10033
Johannes Berg960d01a2014-09-09 22:55:35 +030010034static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10035{
10036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10037 struct net_device *dev = info->user_ptr[1];
10038 struct wireless_dev *wdev = dev->ieee80211_ptr;
10039 const u8 *peer;
10040 u8 tsid, up;
10041 u16 admitted_time = 0;
10042 int err;
10043
Johannes Berg723e73a2014-10-22 09:25:06 +020010044 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010045 return -EOPNOTSUPP;
10046
10047 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10048 !info->attrs[NL80211_ATTR_USER_PRIO])
10049 return -EINVAL;
10050
10051 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10052 if (tsid >= IEEE80211_NUM_TIDS)
10053 return -EINVAL;
10054
10055 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10056 if (up >= IEEE80211_NUM_UPS)
10057 return -EINVAL;
10058
10059 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010060 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010061 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010062 * need more attributes for that (e.g. BA session requirement);
10063 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010064 */
10065 return -EINVAL;
10066 }
10067
10068 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10069
10070 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10071 admitted_time =
10072 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10073 if (!admitted_time)
10074 return -EINVAL;
10075 }
10076
10077 wdev_lock(wdev);
10078 switch (wdev->iftype) {
10079 case NL80211_IFTYPE_STATION:
10080 case NL80211_IFTYPE_P2P_CLIENT:
10081 if (wdev->current_bss)
10082 break;
10083 err = -ENOTCONN;
10084 goto out;
10085 default:
10086 err = -EOPNOTSUPP;
10087 goto out;
10088 }
10089
10090 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10091
10092 out:
10093 wdev_unlock(wdev);
10094 return err;
10095}
10096
10097static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10098{
10099 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10100 struct net_device *dev = info->user_ptr[1];
10101 struct wireless_dev *wdev = dev->ieee80211_ptr;
10102 const u8 *peer;
10103 u8 tsid;
10104 int err;
10105
10106 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10107 return -EINVAL;
10108
10109 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10110 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10111
10112 wdev_lock(wdev);
10113 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10114 wdev_unlock(wdev);
10115
10116 return err;
10117}
10118
Arik Nemtsov1057d352014-11-19 12:54:26 +020010119static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10120 struct genl_info *info)
10121{
10122 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10123 struct net_device *dev = info->user_ptr[1];
10124 struct wireless_dev *wdev = dev->ieee80211_ptr;
10125 struct cfg80211_chan_def chandef = {};
10126 const u8 *addr;
10127 u8 oper_class;
10128 int err;
10129
10130 if (!rdev->ops->tdls_channel_switch ||
10131 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10132 return -EOPNOTSUPP;
10133
10134 switch (dev->ieee80211_ptr->iftype) {
10135 case NL80211_IFTYPE_STATION:
10136 case NL80211_IFTYPE_P2P_CLIENT:
10137 break;
10138 default:
10139 return -EOPNOTSUPP;
10140 }
10141
10142 if (!info->attrs[NL80211_ATTR_MAC] ||
10143 !info->attrs[NL80211_ATTR_OPER_CLASS])
10144 return -EINVAL;
10145
10146 err = nl80211_parse_chandef(rdev, info, &chandef);
10147 if (err)
10148 return err;
10149
10150 /*
10151 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10152 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10153 * specification is not defined for them.
10154 */
10155 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10156 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10157 chandef.width != NL80211_CHAN_WIDTH_20)
10158 return -EINVAL;
10159
10160 /* we will be active on the TDLS link */
10161 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
10162 return -EINVAL;
10163
10164 /* don't allow switching to DFS channels */
10165 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10166 return -EINVAL;
10167
10168 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10169 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10170
10171 wdev_lock(wdev);
10172 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10173 wdev_unlock(wdev);
10174
10175 return err;
10176}
10177
10178static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10179 struct genl_info *info)
10180{
10181 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10182 struct net_device *dev = info->user_ptr[1];
10183 struct wireless_dev *wdev = dev->ieee80211_ptr;
10184 const u8 *addr;
10185
10186 if (!rdev->ops->tdls_channel_switch ||
10187 !rdev->ops->tdls_cancel_channel_switch ||
10188 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10189 return -EOPNOTSUPP;
10190
10191 switch (dev->ieee80211_ptr->iftype) {
10192 case NL80211_IFTYPE_STATION:
10193 case NL80211_IFTYPE_P2P_CLIENT:
10194 break;
10195 default:
10196 return -EOPNOTSUPP;
10197 }
10198
10199 if (!info->attrs[NL80211_ATTR_MAC])
10200 return -EINVAL;
10201
10202 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10203
10204 wdev_lock(wdev);
10205 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10206 wdev_unlock(wdev);
10207
10208 return 0;
10209}
10210
Johannes Berg4c476992010-10-04 21:36:35 +020010211#define NL80211_FLAG_NEED_WIPHY 0x01
10212#define NL80211_FLAG_NEED_NETDEV 0x02
10213#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010214#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10215#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10216 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010217#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010218/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010219#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10220 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010221#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010222
Johannes Bergf84f7712013-11-14 17:14:45 +010010223static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010224 struct genl_info *info)
10225{
10226 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010227 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010228 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010229 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10230
10231 if (rtnl)
10232 rtnl_lock();
10233
10234 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010235 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010236 if (IS_ERR(rdev)) {
10237 if (rtnl)
10238 rtnl_unlock();
10239 return PTR_ERR(rdev);
10240 }
10241 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010242 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10243 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010244 ASSERT_RTNL();
10245
Johannes Berg89a54e42012-06-15 14:33:17 +020010246 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10247 info->attrs);
10248 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010249 if (rtnl)
10250 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010251 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010252 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010253
Johannes Berg89a54e42012-06-15 14:33:17 +020010254 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010255 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010256
Johannes Berg1bf614e2012-06-15 15:23:36 +020010257 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10258 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010259 if (rtnl)
10260 rtnl_unlock();
10261 return -EINVAL;
10262 }
10263
10264 info->user_ptr[1] = dev;
10265 } else {
10266 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010267 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010268
Johannes Berg1bf614e2012-06-15 15:23:36 +020010269 if (dev) {
10270 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10271 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010272 if (rtnl)
10273 rtnl_unlock();
10274 return -ENETDOWN;
10275 }
10276
10277 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010278 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10279 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010280 if (rtnl)
10281 rtnl_unlock();
10282 return -ENETDOWN;
10283 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010284 }
10285
Johannes Berg4c476992010-10-04 21:36:35 +020010286 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010287 }
10288
10289 return 0;
10290}
10291
Johannes Bergf84f7712013-11-14 17:14:45 +010010292static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010293 struct genl_info *info)
10294{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010295 if (info->user_ptr[1]) {
10296 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10297 struct wireless_dev *wdev = info->user_ptr[1];
10298
10299 if (wdev->netdev)
10300 dev_put(wdev->netdev);
10301 } else {
10302 dev_put(info->user_ptr[1]);
10303 }
10304 }
Johannes Berg5393b912014-09-10 15:00:16 +030010305
Johannes Berg4c476992010-10-04 21:36:35 +020010306 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10307 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010308
10309 /* If needed, clear the netlink message payload from the SKB
10310 * as it might contain key data that shouldn't stick around on
10311 * the heap after the SKB is freed. The netlink message header
10312 * is still needed for further processing, so leave it intact.
10313 */
10314 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10315 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10316
10317 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10318 }
Johannes Berg4c476992010-10-04 21:36:35 +020010319}
10320
Johannes Berg4534de82013-11-14 17:14:46 +010010321static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010322 {
10323 .cmd = NL80211_CMD_GET_WIPHY,
10324 .doit = nl80211_get_wiphy,
10325 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010326 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010327 .policy = nl80211_policy,
10328 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010329 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10330 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010331 },
10332 {
10333 .cmd = NL80211_CMD_SET_WIPHY,
10334 .doit = nl80211_set_wiphy,
10335 .policy = nl80211_policy,
10336 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010337 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010338 },
10339 {
10340 .cmd = NL80211_CMD_GET_INTERFACE,
10341 .doit = nl80211_get_interface,
10342 .dumpit = nl80211_dump_interface,
10343 .policy = nl80211_policy,
10344 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010345 .internal_flags = NL80211_FLAG_NEED_WDEV |
10346 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010347 },
10348 {
10349 .cmd = NL80211_CMD_SET_INTERFACE,
10350 .doit = nl80211_set_interface,
10351 .policy = nl80211_policy,
10352 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010353 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10354 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010355 },
10356 {
10357 .cmd = NL80211_CMD_NEW_INTERFACE,
10358 .doit = nl80211_new_interface,
10359 .policy = nl80211_policy,
10360 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010361 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10362 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010363 },
10364 {
10365 .cmd = NL80211_CMD_DEL_INTERFACE,
10366 .doit = nl80211_del_interface,
10367 .policy = nl80211_policy,
10368 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010369 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010370 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010371 },
Johannes Berg41ade002007-12-19 02:03:29 +010010372 {
10373 .cmd = NL80211_CMD_GET_KEY,
10374 .doit = nl80211_get_key,
10375 .policy = nl80211_policy,
10376 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010377 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010378 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010379 },
10380 {
10381 .cmd = NL80211_CMD_SET_KEY,
10382 .doit = nl80211_set_key,
10383 .policy = nl80211_policy,
10384 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010385 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010386 NL80211_FLAG_NEED_RTNL |
10387 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010388 },
10389 {
10390 .cmd = NL80211_CMD_NEW_KEY,
10391 .doit = nl80211_new_key,
10392 .policy = nl80211_policy,
10393 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010394 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010395 NL80211_FLAG_NEED_RTNL |
10396 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010397 },
10398 {
10399 .cmd = NL80211_CMD_DEL_KEY,
10400 .doit = nl80211_del_key,
10401 .policy = nl80211_policy,
10402 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010403 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010404 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010405 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010406 {
10407 .cmd = NL80211_CMD_SET_BEACON,
10408 .policy = nl80211_policy,
10409 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010410 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010411 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010412 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010413 },
10414 {
Johannes Berg88600202012-02-13 15:17:18 +010010415 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010416 .policy = nl80211_policy,
10417 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010418 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010420 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010421 },
10422 {
Johannes Berg88600202012-02-13 15:17:18 +010010423 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010424 .policy = nl80211_policy,
10425 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010426 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010428 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010429 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010430 {
10431 .cmd = NL80211_CMD_GET_STATION,
10432 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010433 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010434 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010435 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10436 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010437 },
10438 {
10439 .cmd = NL80211_CMD_SET_STATION,
10440 .doit = nl80211_set_station,
10441 .policy = nl80211_policy,
10442 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010444 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010445 },
10446 {
10447 .cmd = NL80211_CMD_NEW_STATION,
10448 .doit = nl80211_new_station,
10449 .policy = nl80211_policy,
10450 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010451 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010452 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010453 },
10454 {
10455 .cmd = NL80211_CMD_DEL_STATION,
10456 .doit = nl80211_del_station,
10457 .policy = nl80211_policy,
10458 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010460 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010461 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010462 {
10463 .cmd = NL80211_CMD_GET_MPATH,
10464 .doit = nl80211_get_mpath,
10465 .dumpit = nl80211_dump_mpath,
10466 .policy = nl80211_policy,
10467 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010468 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010469 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010470 },
10471 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010472 .cmd = NL80211_CMD_GET_MPP,
10473 .doit = nl80211_get_mpp,
10474 .dumpit = nl80211_dump_mpp,
10475 .policy = nl80211_policy,
10476 .flags = GENL_ADMIN_PERM,
10477 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10478 NL80211_FLAG_NEED_RTNL,
10479 },
10480 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010481 .cmd = NL80211_CMD_SET_MPATH,
10482 .doit = nl80211_set_mpath,
10483 .policy = nl80211_policy,
10484 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010485 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010486 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010487 },
10488 {
10489 .cmd = NL80211_CMD_NEW_MPATH,
10490 .doit = nl80211_new_mpath,
10491 .policy = nl80211_policy,
10492 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010494 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010495 },
10496 {
10497 .cmd = NL80211_CMD_DEL_MPATH,
10498 .doit = nl80211_del_mpath,
10499 .policy = nl80211_policy,
10500 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010502 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010503 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010504 {
10505 .cmd = NL80211_CMD_SET_BSS,
10506 .doit = nl80211_set_bss,
10507 .policy = nl80211_policy,
10508 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010510 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010511 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010512 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010513 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010514 .doit = nl80211_get_reg_do,
10515 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010516 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010517 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010518 /* can be retrieved by unprivileged users */
10519 },
10520 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010521 .cmd = NL80211_CMD_SET_REG,
10522 .doit = nl80211_set_reg,
10523 .policy = nl80211_policy,
10524 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010525 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010526 },
10527 {
10528 .cmd = NL80211_CMD_REQ_SET_REG,
10529 .doit = nl80211_req_set_reg,
10530 .policy = nl80211_policy,
10531 .flags = GENL_ADMIN_PERM,
10532 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010533 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010534 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10535 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010536 .policy = nl80211_policy,
10537 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010538 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010539 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010540 },
10541 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010542 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10543 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010544 .policy = nl80211_policy,
10545 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010547 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010548 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010549 {
Johannes Berg2a519312009-02-10 21:25:55 +010010550 .cmd = NL80211_CMD_TRIGGER_SCAN,
10551 .doit = nl80211_trigger_scan,
10552 .policy = nl80211_policy,
10553 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010554 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010555 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010556 },
10557 {
10558 .cmd = NL80211_CMD_GET_SCAN,
10559 .policy = nl80211_policy,
10560 .dumpit = nl80211_dump_scan,
10561 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010562 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010563 .cmd = NL80211_CMD_START_SCHED_SCAN,
10564 .doit = nl80211_start_sched_scan,
10565 .policy = nl80211_policy,
10566 .flags = GENL_ADMIN_PERM,
10567 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10568 NL80211_FLAG_NEED_RTNL,
10569 },
10570 {
10571 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10572 .doit = nl80211_stop_sched_scan,
10573 .policy = nl80211_policy,
10574 .flags = GENL_ADMIN_PERM,
10575 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10576 NL80211_FLAG_NEED_RTNL,
10577 },
10578 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010579 .cmd = NL80211_CMD_AUTHENTICATE,
10580 .doit = nl80211_authenticate,
10581 .policy = nl80211_policy,
10582 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010583 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010584 NL80211_FLAG_NEED_RTNL |
10585 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010586 },
10587 {
10588 .cmd = NL80211_CMD_ASSOCIATE,
10589 .doit = nl80211_associate,
10590 .policy = nl80211_policy,
10591 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010592 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010593 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010594 },
10595 {
10596 .cmd = NL80211_CMD_DEAUTHENTICATE,
10597 .doit = nl80211_deauthenticate,
10598 .policy = nl80211_policy,
10599 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010600 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010601 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010602 },
10603 {
10604 .cmd = NL80211_CMD_DISASSOCIATE,
10605 .doit = nl80211_disassociate,
10606 .policy = nl80211_policy,
10607 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010608 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010609 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010610 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010611 {
10612 .cmd = NL80211_CMD_JOIN_IBSS,
10613 .doit = nl80211_join_ibss,
10614 .policy = nl80211_policy,
10615 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010616 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010617 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010618 },
10619 {
10620 .cmd = NL80211_CMD_LEAVE_IBSS,
10621 .doit = nl80211_leave_ibss,
10622 .policy = nl80211_policy,
10623 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010624 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010625 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010626 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010627#ifdef CONFIG_NL80211_TESTMODE
10628 {
10629 .cmd = NL80211_CMD_TESTMODE,
10630 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010631 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010632 .policy = nl80211_policy,
10633 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010634 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10635 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010636 },
10637#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010638 {
10639 .cmd = NL80211_CMD_CONNECT,
10640 .doit = nl80211_connect,
10641 .policy = nl80211_policy,
10642 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010643 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010644 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010645 },
10646 {
10647 .cmd = NL80211_CMD_DISCONNECT,
10648 .doit = nl80211_disconnect,
10649 .policy = nl80211_policy,
10650 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010651 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010652 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010653 },
Johannes Berg463d0182009-07-14 00:33:35 +020010654 {
10655 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10656 .doit = nl80211_wiphy_netns,
10657 .policy = nl80211_policy,
10658 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010659 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10660 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010661 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010662 {
10663 .cmd = NL80211_CMD_GET_SURVEY,
10664 .policy = nl80211_policy,
10665 .dumpit = nl80211_dump_survey,
10666 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010667 {
10668 .cmd = NL80211_CMD_SET_PMKSA,
10669 .doit = nl80211_setdel_pmksa,
10670 .policy = nl80211_policy,
10671 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010672 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010673 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010674 },
10675 {
10676 .cmd = NL80211_CMD_DEL_PMKSA,
10677 .doit = nl80211_setdel_pmksa,
10678 .policy = nl80211_policy,
10679 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010680 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010681 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010682 },
10683 {
10684 .cmd = NL80211_CMD_FLUSH_PMKSA,
10685 .doit = nl80211_flush_pmksa,
10686 .policy = nl80211_policy,
10687 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010688 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010689 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010690 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010691 {
10692 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10693 .doit = nl80211_remain_on_channel,
10694 .policy = nl80211_policy,
10695 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010696 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010697 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010698 },
10699 {
10700 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10701 .doit = nl80211_cancel_remain_on_channel,
10702 .policy = nl80211_policy,
10703 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010704 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010705 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010706 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010707 {
10708 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10709 .doit = nl80211_set_tx_bitrate_mask,
10710 .policy = nl80211_policy,
10711 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010712 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10713 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010714 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010715 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010716 .cmd = NL80211_CMD_REGISTER_FRAME,
10717 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010718 .policy = nl80211_policy,
10719 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010720 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010721 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010722 },
10723 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010724 .cmd = NL80211_CMD_FRAME,
10725 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010726 .policy = nl80211_policy,
10727 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010728 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010729 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010730 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010731 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010732 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10733 .doit = nl80211_tx_mgmt_cancel_wait,
10734 .policy = nl80211_policy,
10735 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010736 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010737 NL80211_FLAG_NEED_RTNL,
10738 },
10739 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010740 .cmd = NL80211_CMD_SET_POWER_SAVE,
10741 .doit = nl80211_set_power_save,
10742 .policy = nl80211_policy,
10743 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010744 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10745 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010746 },
10747 {
10748 .cmd = NL80211_CMD_GET_POWER_SAVE,
10749 .doit = nl80211_get_power_save,
10750 .policy = nl80211_policy,
10751 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010752 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10753 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010754 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010755 {
10756 .cmd = NL80211_CMD_SET_CQM,
10757 .doit = nl80211_set_cqm,
10758 .policy = nl80211_policy,
10759 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010760 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10761 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010762 },
Johannes Bergf444de02010-05-05 15:25:02 +020010763 {
10764 .cmd = NL80211_CMD_SET_CHANNEL,
10765 .doit = nl80211_set_channel,
10766 .policy = nl80211_policy,
10767 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010768 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10769 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010770 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010771 {
10772 .cmd = NL80211_CMD_SET_WDS_PEER,
10773 .doit = nl80211_set_wds_peer,
10774 .policy = nl80211_policy,
10775 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010776 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10777 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010778 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010779 {
10780 .cmd = NL80211_CMD_JOIN_MESH,
10781 .doit = nl80211_join_mesh,
10782 .policy = nl80211_policy,
10783 .flags = GENL_ADMIN_PERM,
10784 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10785 NL80211_FLAG_NEED_RTNL,
10786 },
10787 {
10788 .cmd = NL80211_CMD_LEAVE_MESH,
10789 .doit = nl80211_leave_mesh,
10790 .policy = nl80211_policy,
10791 .flags = GENL_ADMIN_PERM,
10792 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10793 NL80211_FLAG_NEED_RTNL,
10794 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010795 {
10796 .cmd = NL80211_CMD_JOIN_OCB,
10797 .doit = nl80211_join_ocb,
10798 .policy = nl80211_policy,
10799 .flags = GENL_ADMIN_PERM,
10800 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10801 NL80211_FLAG_NEED_RTNL,
10802 },
10803 {
10804 .cmd = NL80211_CMD_LEAVE_OCB,
10805 .doit = nl80211_leave_ocb,
10806 .policy = nl80211_policy,
10807 .flags = GENL_ADMIN_PERM,
10808 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10809 NL80211_FLAG_NEED_RTNL,
10810 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010811#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010812 {
10813 .cmd = NL80211_CMD_GET_WOWLAN,
10814 .doit = nl80211_get_wowlan,
10815 .policy = nl80211_policy,
10816 /* can be retrieved by unprivileged users */
10817 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10818 NL80211_FLAG_NEED_RTNL,
10819 },
10820 {
10821 .cmd = NL80211_CMD_SET_WOWLAN,
10822 .doit = nl80211_set_wowlan,
10823 .policy = nl80211_policy,
10824 .flags = GENL_ADMIN_PERM,
10825 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10826 NL80211_FLAG_NEED_RTNL,
10827 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010828#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010829 {
10830 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10831 .doit = nl80211_set_rekey_data,
10832 .policy = nl80211_policy,
10833 .flags = GENL_ADMIN_PERM,
10834 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010835 NL80211_FLAG_NEED_RTNL |
10836 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010837 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010838 {
10839 .cmd = NL80211_CMD_TDLS_MGMT,
10840 .doit = nl80211_tdls_mgmt,
10841 .policy = nl80211_policy,
10842 .flags = GENL_ADMIN_PERM,
10843 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10844 NL80211_FLAG_NEED_RTNL,
10845 },
10846 {
10847 .cmd = NL80211_CMD_TDLS_OPER,
10848 .doit = nl80211_tdls_oper,
10849 .policy = nl80211_policy,
10850 .flags = GENL_ADMIN_PERM,
10851 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10852 NL80211_FLAG_NEED_RTNL,
10853 },
Johannes Berg28946da2011-11-04 11:18:12 +010010854 {
10855 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10856 .doit = nl80211_register_unexpected_frame,
10857 .policy = nl80211_policy,
10858 .flags = GENL_ADMIN_PERM,
10859 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10860 NL80211_FLAG_NEED_RTNL,
10861 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010862 {
10863 .cmd = NL80211_CMD_PROBE_CLIENT,
10864 .doit = nl80211_probe_client,
10865 .policy = nl80211_policy,
10866 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010867 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010868 NL80211_FLAG_NEED_RTNL,
10869 },
Johannes Berg5e760232011-11-04 11:18:17 +010010870 {
10871 .cmd = NL80211_CMD_REGISTER_BEACONS,
10872 .doit = nl80211_register_beacons,
10873 .policy = nl80211_policy,
10874 .flags = GENL_ADMIN_PERM,
10875 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10876 NL80211_FLAG_NEED_RTNL,
10877 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010878 {
10879 .cmd = NL80211_CMD_SET_NOACK_MAP,
10880 .doit = nl80211_set_noack_map,
10881 .policy = nl80211_policy,
10882 .flags = GENL_ADMIN_PERM,
10883 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10884 NL80211_FLAG_NEED_RTNL,
10885 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010886 {
10887 .cmd = NL80211_CMD_START_P2P_DEVICE,
10888 .doit = nl80211_start_p2p_device,
10889 .policy = nl80211_policy,
10890 .flags = GENL_ADMIN_PERM,
10891 .internal_flags = NL80211_FLAG_NEED_WDEV |
10892 NL80211_FLAG_NEED_RTNL,
10893 },
10894 {
10895 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10896 .doit = nl80211_stop_p2p_device,
10897 .policy = nl80211_policy,
10898 .flags = GENL_ADMIN_PERM,
10899 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10900 NL80211_FLAG_NEED_RTNL,
10901 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010902 {
10903 .cmd = NL80211_CMD_SET_MCAST_RATE,
10904 .doit = nl80211_set_mcast_rate,
10905 .policy = nl80211_policy,
10906 .flags = GENL_ADMIN_PERM,
10907 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10908 NL80211_FLAG_NEED_RTNL,
10909 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010910 {
10911 .cmd = NL80211_CMD_SET_MAC_ACL,
10912 .doit = nl80211_set_mac_acl,
10913 .policy = nl80211_policy,
10914 .flags = GENL_ADMIN_PERM,
10915 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10916 NL80211_FLAG_NEED_RTNL,
10917 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010918 {
10919 .cmd = NL80211_CMD_RADAR_DETECT,
10920 .doit = nl80211_start_radar_detection,
10921 .policy = nl80211_policy,
10922 .flags = GENL_ADMIN_PERM,
10923 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10924 NL80211_FLAG_NEED_RTNL,
10925 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010926 {
10927 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10928 .doit = nl80211_get_protocol_features,
10929 .policy = nl80211_policy,
10930 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010931 {
10932 .cmd = NL80211_CMD_UPDATE_FT_IES,
10933 .doit = nl80211_update_ft_ies,
10934 .policy = nl80211_policy,
10935 .flags = GENL_ADMIN_PERM,
10936 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10937 NL80211_FLAG_NEED_RTNL,
10938 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010939 {
10940 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10941 .doit = nl80211_crit_protocol_start,
10942 .policy = nl80211_policy,
10943 .flags = GENL_ADMIN_PERM,
10944 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10945 NL80211_FLAG_NEED_RTNL,
10946 },
10947 {
10948 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10949 .doit = nl80211_crit_protocol_stop,
10950 .policy = nl80211_policy,
10951 .flags = GENL_ADMIN_PERM,
10952 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10953 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010954 },
10955 {
10956 .cmd = NL80211_CMD_GET_COALESCE,
10957 .doit = nl80211_get_coalesce,
10958 .policy = nl80211_policy,
10959 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10960 NL80211_FLAG_NEED_RTNL,
10961 },
10962 {
10963 .cmd = NL80211_CMD_SET_COALESCE,
10964 .doit = nl80211_set_coalesce,
10965 .policy = nl80211_policy,
10966 .flags = GENL_ADMIN_PERM,
10967 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10968 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010969 },
10970 {
10971 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10972 .doit = nl80211_channel_switch,
10973 .policy = nl80211_policy,
10974 .flags = GENL_ADMIN_PERM,
10975 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10976 NL80211_FLAG_NEED_RTNL,
10977 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010978 {
10979 .cmd = NL80211_CMD_VENDOR,
10980 .doit = nl80211_vendor_cmd,
10981 .policy = nl80211_policy,
10982 .flags = GENL_ADMIN_PERM,
10983 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10984 NL80211_FLAG_NEED_RTNL,
10985 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010986 {
10987 .cmd = NL80211_CMD_SET_QOS_MAP,
10988 .doit = nl80211_set_qos_map,
10989 .policy = nl80211_policy,
10990 .flags = GENL_ADMIN_PERM,
10991 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10992 NL80211_FLAG_NEED_RTNL,
10993 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010994 {
10995 .cmd = NL80211_CMD_ADD_TX_TS,
10996 .doit = nl80211_add_tx_ts,
10997 .policy = nl80211_policy,
10998 .flags = GENL_ADMIN_PERM,
10999 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11000 NL80211_FLAG_NEED_RTNL,
11001 },
11002 {
11003 .cmd = NL80211_CMD_DEL_TX_TS,
11004 .doit = nl80211_del_tx_ts,
11005 .policy = nl80211_policy,
11006 .flags = GENL_ADMIN_PERM,
11007 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11008 NL80211_FLAG_NEED_RTNL,
11009 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011010 {
11011 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11012 .doit = nl80211_tdls_channel_switch,
11013 .policy = nl80211_policy,
11014 .flags = GENL_ADMIN_PERM,
11015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11016 NL80211_FLAG_NEED_RTNL,
11017 },
11018 {
11019 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11020 .doit = nl80211_tdls_cancel_channel_switch,
11021 .policy = nl80211_policy,
11022 .flags = GENL_ADMIN_PERM,
11023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11024 NL80211_FLAG_NEED_RTNL,
11025 },
Johannes Berg55682962007-09-20 13:09:35 -040011026};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011027
Johannes Berg55682962007-09-20 13:09:35 -040011028/* notification functions */
11029
Johannes Berg3bb20552014-05-26 13:52:25 +020011030void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11031 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011032{
11033 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011034 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011035
Johannes Berg3bb20552014-05-26 13:52:25 +020011036 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11037 cmd != NL80211_CMD_DEL_WIPHY);
11038
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011039 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011040 if (!msg)
11041 return;
11042
Johannes Berg3bb20552014-05-26 13:52:25 +020011043 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011044 nlmsg_free(msg);
11045 return;
11046 }
11047
Johannes Berg68eb5502013-11-19 15:19:38 +010011048 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011049 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011050}
11051
Johannes Berg362a4152009-05-24 16:43:15 +020011052static int nl80211_add_scan_req(struct sk_buff *msg,
11053 struct cfg80211_registered_device *rdev)
11054{
11055 struct cfg80211_scan_request *req = rdev->scan_req;
11056 struct nlattr *nest;
11057 int i;
11058
11059 if (WARN_ON(!req))
11060 return 0;
11061
11062 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11063 if (!nest)
11064 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011065 for (i = 0; i < req->n_ssids; i++) {
11066 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11067 goto nla_put_failure;
11068 }
Johannes Berg362a4152009-05-24 16:43:15 +020011069 nla_nest_end(msg, nest);
11070
11071 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11072 if (!nest)
11073 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011074 for (i = 0; i < req->n_channels; i++) {
11075 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11076 goto nla_put_failure;
11077 }
Johannes Berg362a4152009-05-24 16:43:15 +020011078 nla_nest_end(msg, nest);
11079
David S. Miller9360ffd2012-03-29 04:41:26 -040011080 if (req->ie &&
11081 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11082 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011083
Johannes Bergae917c92013-10-25 11:05:22 +020011084 if (req->flags &&
11085 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11086 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011087
Johannes Berg362a4152009-05-24 16:43:15 +020011088 return 0;
11089 nla_put_failure:
11090 return -ENOBUFS;
11091}
11092
Johannes Berga538e2d2009-06-16 19:56:42 +020011093static int nl80211_send_scan_msg(struct sk_buff *msg,
11094 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011095 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011096 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011097 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011098{
11099 void *hdr;
11100
Eric W. Biederman15e47302012-09-07 20:12:54 +000011101 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011102 if (!hdr)
11103 return -1;
11104
David S. Miller9360ffd2012-03-29 04:41:26 -040011105 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011106 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11107 wdev->netdev->ifindex)) ||
11108 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011109 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011110
Johannes Berg362a4152009-05-24 16:43:15 +020011111 /* ignore errors and send incomplete event anyway */
11112 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011113
Johannes Berg053c0952015-01-16 22:09:00 +010011114 genlmsg_end(msg, hdr);
11115 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011116
11117 nla_put_failure:
11118 genlmsg_cancel(msg, hdr);
11119 return -EMSGSIZE;
11120}
11121
Luciano Coelho807f8a82011-05-11 17:09:35 +030011122static int
11123nl80211_send_sched_scan_msg(struct sk_buff *msg,
11124 struct cfg80211_registered_device *rdev,
11125 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011126 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011127{
11128 void *hdr;
11129
Eric W. Biederman15e47302012-09-07 20:12:54 +000011130 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011131 if (!hdr)
11132 return -1;
11133
David S. Miller9360ffd2012-03-29 04:41:26 -040011134 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11135 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11136 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011137
Johannes Berg053c0952015-01-16 22:09:00 +010011138 genlmsg_end(msg, hdr);
11139 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011140
11141 nla_put_failure:
11142 genlmsg_cancel(msg, hdr);
11143 return -EMSGSIZE;
11144}
11145
Johannes Berga538e2d2009-06-16 19:56:42 +020011146void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011147 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011148{
11149 struct sk_buff *msg;
11150
Thomas Graf58050fc2012-06-28 03:57:45 +000011151 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011152 if (!msg)
11153 return;
11154
Johannes Bergfd014282012-06-18 19:17:03 +020011155 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011156 NL80211_CMD_TRIGGER_SCAN) < 0) {
11157 nlmsg_free(msg);
11158 return;
11159 }
11160
Johannes Berg68eb5502013-11-19 15:19:38 +010011161 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011162 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011163}
11164
Johannes Bergf9d15d12014-01-22 11:14:19 +020011165struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11166 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011167{
11168 struct sk_buff *msg;
11169
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011170 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011171 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011172 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011173
Johannes Bergfd014282012-06-18 19:17:03 +020011174 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011175 aborted ? NL80211_CMD_SCAN_ABORTED :
11176 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011177 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011178 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011179 }
11180
Johannes Bergf9d15d12014-01-22 11:14:19 +020011181 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011182}
11183
Johannes Bergf9d15d12014-01-22 11:14:19 +020011184void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11185 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011186{
Johannes Berg2a519312009-02-10 21:25:55 +010011187 if (!msg)
11188 return;
11189
Johannes Berg68eb5502013-11-19 15:19:38 +010011190 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011191 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011192}
11193
Luciano Coelho807f8a82011-05-11 17:09:35 +030011194void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11195 struct net_device *netdev)
11196{
11197 struct sk_buff *msg;
11198
11199 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11200 if (!msg)
11201 return;
11202
11203 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11204 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11205 nlmsg_free(msg);
11206 return;
11207 }
11208
Johannes Berg68eb5502013-11-19 15:19:38 +010011209 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011210 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011211}
11212
11213void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11214 struct net_device *netdev, u32 cmd)
11215{
11216 struct sk_buff *msg;
11217
Thomas Graf58050fc2012-06-28 03:57:45 +000011218 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011219 if (!msg)
11220 return;
11221
11222 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11223 nlmsg_free(msg);
11224 return;
11225 }
11226
Johannes Berg68eb5502013-11-19 15:19:38 +010011227 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011228 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011229}
11230
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011231static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11232 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011233{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011234 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011235 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11236 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011237
David S. Miller9360ffd2012-03-29 04:41:26 -040011238 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11239 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11240 NL80211_REGDOM_TYPE_WORLD))
11241 goto nla_put_failure;
11242 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11243 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11244 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11245 goto nla_put_failure;
11246 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11247 request->intersect) {
11248 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11249 NL80211_REGDOM_TYPE_INTERSECTION))
11250 goto nla_put_failure;
11251 } else {
11252 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11253 NL80211_REGDOM_TYPE_COUNTRY) ||
11254 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11255 request->alpha2))
11256 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011257 }
11258
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011259 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11260 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11261
11262 if (wiphy &&
11263 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11264 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011265
11266 if (wiphy &&
11267 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11268 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11269 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011270 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011271
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011272 return true;
11273
11274nla_put_failure:
11275 return false;
11276}
11277
11278/*
11279 * This can happen on global regulatory changes or device specific settings
11280 * based on custom regulatory domains.
11281 */
11282void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11283 struct regulatory_request *request)
11284{
11285 struct sk_buff *msg;
11286 void *hdr;
11287
11288 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11289 if (!msg)
11290 return;
11291
11292 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11293 if (!hdr) {
11294 nlmsg_free(msg);
11295 return;
11296 }
11297
11298 if (nl80211_reg_change_event_fill(msg, request) == false)
11299 goto nla_put_failure;
11300
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011301 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011302
Johannes Bergbc43b282009-07-25 10:54:13 +020011303 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011304 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011305 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011306 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011307
11308 return;
11309
11310nla_put_failure:
11311 genlmsg_cancel(msg, hdr);
11312 nlmsg_free(msg);
11313}
11314
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011315static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11316 struct net_device *netdev,
11317 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011318 enum nl80211_commands cmd, gfp_t gfp,
11319 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011320{
11321 struct sk_buff *msg;
11322 void *hdr;
11323
Johannes Berge6d6e342009-07-01 21:26:47 +020011324 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011325 if (!msg)
11326 return;
11327
11328 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11329 if (!hdr) {
11330 nlmsg_free(msg);
11331 return;
11332 }
11333
David S. Miller9360ffd2012-03-29 04:41:26 -040011334 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11335 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11336 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11337 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011338
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011339 if (uapsd_queues >= 0) {
11340 struct nlattr *nla_wmm =
11341 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11342 if (!nla_wmm)
11343 goto nla_put_failure;
11344
11345 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11346 uapsd_queues))
11347 goto nla_put_failure;
11348
11349 nla_nest_end(msg, nla_wmm);
11350 }
11351
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011352 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011353
Johannes Berg68eb5502013-11-19 15:19:38 +010011354 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011355 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011356 return;
11357
11358 nla_put_failure:
11359 genlmsg_cancel(msg, hdr);
11360 nlmsg_free(msg);
11361}
11362
11363void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011364 struct net_device *netdev, const u8 *buf,
11365 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011366{
11367 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011368 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011369}
11370
11371void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11372 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011373 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011374{
Johannes Berge6d6e342009-07-01 21:26:47 +020011375 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011376 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011377}
11378
Jouni Malinen53b46b82009-03-27 20:53:56 +020011379void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011380 struct net_device *netdev, const u8 *buf,
11381 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011382{
11383 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011384 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011385}
11386
Jouni Malinen53b46b82009-03-27 20:53:56 +020011387void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11388 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011389 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011390{
11391 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011392 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011393}
11394
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011395void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11396 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011397{
Johannes Berg947add32013-02-22 22:05:20 +010011398 struct wireless_dev *wdev = dev->ieee80211_ptr;
11399 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011400 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011401 const struct ieee80211_mgmt *mgmt = (void *)buf;
11402 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011403
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011404 if (WARN_ON(len < 2))
11405 return;
11406
11407 if (ieee80211_is_deauth(mgmt->frame_control))
11408 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11409 else
11410 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11411
11412 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011413 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011414}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011415EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011416
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011417static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11418 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011419 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011420{
11421 struct sk_buff *msg;
11422 void *hdr;
11423
Johannes Berge6d6e342009-07-01 21:26:47 +020011424 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011425 if (!msg)
11426 return;
11427
11428 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11429 if (!hdr) {
11430 nlmsg_free(msg);
11431 return;
11432 }
11433
David S. Miller9360ffd2012-03-29 04:41:26 -040011434 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11435 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11436 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11437 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11438 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011439
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011440 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011441
Johannes Berg68eb5502013-11-19 15:19:38 +010011442 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011443 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011444 return;
11445
11446 nla_put_failure:
11447 genlmsg_cancel(msg, hdr);
11448 nlmsg_free(msg);
11449}
11450
11451void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011452 struct net_device *netdev, const u8 *addr,
11453 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011454{
11455 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011456 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011457}
11458
11459void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011460 struct net_device *netdev, const u8 *addr,
11461 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011462{
Johannes Berge6d6e342009-07-01 21:26:47 +020011463 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11464 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011465}
11466
Samuel Ortizb23aa672009-07-01 21:26:54 +020011467void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11468 struct net_device *netdev, const u8 *bssid,
11469 const u8 *req_ie, size_t req_ie_len,
11470 const u8 *resp_ie, size_t resp_ie_len,
11471 u16 status, gfp_t gfp)
11472{
11473 struct sk_buff *msg;
11474 void *hdr;
11475
Thomas Graf58050fc2012-06-28 03:57:45 +000011476 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011477 if (!msg)
11478 return;
11479
11480 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11481 if (!hdr) {
11482 nlmsg_free(msg);
11483 return;
11484 }
11485
David S. Miller9360ffd2012-03-29 04:41:26 -040011486 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11487 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11488 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11489 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11490 (req_ie &&
11491 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11492 (resp_ie &&
11493 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11494 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011495
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011496 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011497
Johannes Berg68eb5502013-11-19 15:19:38 +010011498 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011499 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011500 return;
11501
11502 nla_put_failure:
11503 genlmsg_cancel(msg, hdr);
11504 nlmsg_free(msg);
11505
11506}
11507
11508void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11509 struct net_device *netdev, const u8 *bssid,
11510 const u8 *req_ie, size_t req_ie_len,
11511 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11512{
11513 struct sk_buff *msg;
11514 void *hdr;
11515
Thomas Graf58050fc2012-06-28 03:57:45 +000011516 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011517 if (!msg)
11518 return;
11519
11520 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11521 if (!hdr) {
11522 nlmsg_free(msg);
11523 return;
11524 }
11525
David S. Miller9360ffd2012-03-29 04:41:26 -040011526 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11527 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11528 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11529 (req_ie &&
11530 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11531 (resp_ie &&
11532 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11533 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011534
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011535 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011536
Johannes Berg68eb5502013-11-19 15:19:38 +010011537 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011538 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011539 return;
11540
11541 nla_put_failure:
11542 genlmsg_cancel(msg, hdr);
11543 nlmsg_free(msg);
11544
11545}
11546
11547void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11548 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011549 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011550{
11551 struct sk_buff *msg;
11552 void *hdr;
11553
Thomas Graf58050fc2012-06-28 03:57:45 +000011554 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011555 if (!msg)
11556 return;
11557
11558 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11559 if (!hdr) {
11560 nlmsg_free(msg);
11561 return;
11562 }
11563
David S. Miller9360ffd2012-03-29 04:41:26 -040011564 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11565 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11566 (from_ap && reason &&
11567 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11568 (from_ap &&
11569 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11570 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11571 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011572
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011573 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011574
Johannes Berg68eb5502013-11-19 15:19:38 +010011575 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011576 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011577 return;
11578
11579 nla_put_failure:
11580 genlmsg_cancel(msg, hdr);
11581 nlmsg_free(msg);
11582
11583}
11584
Johannes Berg04a773a2009-04-19 21:24:32 +020011585void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11586 struct net_device *netdev, const u8 *bssid,
11587 gfp_t gfp)
11588{
11589 struct sk_buff *msg;
11590 void *hdr;
11591
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011592 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011593 if (!msg)
11594 return;
11595
11596 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11597 if (!hdr) {
11598 nlmsg_free(msg);
11599 return;
11600 }
11601
David S. Miller9360ffd2012-03-29 04:41:26 -040011602 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11603 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11604 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11605 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011606
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011607 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011608
Johannes Berg68eb5502013-11-19 15:19:38 +010011609 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011610 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011611 return;
11612
11613 nla_put_failure:
11614 genlmsg_cancel(msg, hdr);
11615 nlmsg_free(msg);
11616}
11617
Johannes Berg947add32013-02-22 22:05:20 +010011618void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11619 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011620{
Johannes Berg947add32013-02-22 22:05:20 +010011621 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011622 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011623 struct sk_buff *msg;
11624 void *hdr;
11625
Johannes Berg947add32013-02-22 22:05:20 +010011626 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11627 return;
11628
11629 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11630
Javier Cardonac93b5e72011-04-07 15:08:34 -070011631 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11632 if (!msg)
11633 return;
11634
11635 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11636 if (!hdr) {
11637 nlmsg_free(msg);
11638 return;
11639 }
11640
David S. Miller9360ffd2012-03-29 04:41:26 -040011641 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011642 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11643 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011644 (ie_len && ie &&
11645 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11646 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011647
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011648 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011649
Johannes Berg68eb5502013-11-19 15:19:38 +010011650 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011651 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011652 return;
11653
11654 nla_put_failure:
11655 genlmsg_cancel(msg, hdr);
11656 nlmsg_free(msg);
11657}
Johannes Berg947add32013-02-22 22:05:20 +010011658EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011659
Jouni Malinena3b8b052009-03-27 21:59:49 +020011660void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11661 struct net_device *netdev, const u8 *addr,
11662 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011663 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011664{
11665 struct sk_buff *msg;
11666 void *hdr;
11667
Johannes Berge6d6e342009-07-01 21:26:47 +020011668 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011669 if (!msg)
11670 return;
11671
11672 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11673 if (!hdr) {
11674 nlmsg_free(msg);
11675 return;
11676 }
11677
David S. Miller9360ffd2012-03-29 04:41:26 -040011678 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11679 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11680 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11681 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11682 (key_id != -1 &&
11683 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11684 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11685 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011686
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011687 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011688
Johannes Berg68eb5502013-11-19 15:19:38 +010011689 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011690 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011691 return;
11692
11693 nla_put_failure:
11694 genlmsg_cancel(msg, hdr);
11695 nlmsg_free(msg);
11696}
11697
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011698void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11699 struct ieee80211_channel *channel_before,
11700 struct ieee80211_channel *channel_after)
11701{
11702 struct sk_buff *msg;
11703 void *hdr;
11704 struct nlattr *nl_freq;
11705
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011706 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011707 if (!msg)
11708 return;
11709
11710 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11711 if (!hdr) {
11712 nlmsg_free(msg);
11713 return;
11714 }
11715
11716 /*
11717 * Since we are applying the beacon hint to a wiphy we know its
11718 * wiphy_idx is valid
11719 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011720 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11721 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011722
11723 /* Before */
11724 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11725 if (!nl_freq)
11726 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011727 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011728 goto nla_put_failure;
11729 nla_nest_end(msg, nl_freq);
11730
11731 /* After */
11732 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11733 if (!nl_freq)
11734 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011735 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011736 goto nla_put_failure;
11737 nla_nest_end(msg, nl_freq);
11738
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011739 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011740
Johannes Berg463d0182009-07-14 00:33:35 +020011741 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011742 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011743 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011744 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011745
11746 return;
11747
11748nla_put_failure:
11749 genlmsg_cancel(msg, hdr);
11750 nlmsg_free(msg);
11751}
11752
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011753static void nl80211_send_remain_on_chan_event(
11754 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011755 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011756 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011757 unsigned int duration, gfp_t gfp)
11758{
11759 struct sk_buff *msg;
11760 void *hdr;
11761
11762 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11763 if (!msg)
11764 return;
11765
11766 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11767 if (!hdr) {
11768 nlmsg_free(msg);
11769 return;
11770 }
11771
David S. Miller9360ffd2012-03-29 04:41:26 -040011772 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011773 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11774 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011775 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011776 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011777 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11778 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011779 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11780 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011781
David S. Miller9360ffd2012-03-29 04:41:26 -040011782 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11783 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11784 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011785
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011786 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011787
Johannes Berg68eb5502013-11-19 15:19:38 +010011788 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011789 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011790 return;
11791
11792 nla_put_failure:
11793 genlmsg_cancel(msg, hdr);
11794 nlmsg_free(msg);
11795}
11796
Johannes Berg947add32013-02-22 22:05:20 +010011797void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11798 struct ieee80211_channel *chan,
11799 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011800{
Johannes Berg947add32013-02-22 22:05:20 +010011801 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011802 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011803
11804 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011805 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011806 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011807 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011808}
Johannes Berg947add32013-02-22 22:05:20 +010011809EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011810
Johannes Berg947add32013-02-22 22:05:20 +010011811void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11812 struct ieee80211_channel *chan,
11813 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011814{
Johannes Berg947add32013-02-22 22:05:20 +010011815 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011816 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011817
11818 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011819 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011820 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011821}
Johannes Berg947add32013-02-22 22:05:20 +010011822EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011823
Johannes Berg947add32013-02-22 22:05:20 +010011824void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11825 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011826{
Johannes Berg947add32013-02-22 22:05:20 +010011827 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011828 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011829 struct sk_buff *msg;
11830
Johannes Berg947add32013-02-22 22:05:20 +010011831 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11832
Thomas Graf58050fc2012-06-28 03:57:45 +000011833 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011834 if (!msg)
11835 return;
11836
Johannes Bergcf5ead82014-11-14 17:14:00 +010011837 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040011838 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011839 nlmsg_free(msg);
11840 return;
11841 }
11842
Johannes Berg68eb5502013-11-19 15:19:38 +010011843 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011844 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011845}
Johannes Berg947add32013-02-22 22:05:20 +010011846EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011847
Johannes Bergcf5ead82014-11-14 17:14:00 +010011848void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
11849 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011850{
Johannes Berg947add32013-02-22 22:05:20 +010011851 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011852 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011853 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010011854 struct station_info empty_sinfo = {};
11855
11856 if (!sinfo)
11857 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020011858
Johannes Berg947add32013-02-22 22:05:20 +010011859 trace_cfg80211_del_sta(dev, mac_addr);
11860
Thomas Graf58050fc2012-06-28 03:57:45 +000011861 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011862 if (!msg)
11863 return;
11864
Johannes Bergcf5ead82014-11-14 17:14:00 +010011865 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010011866 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020011867 nlmsg_free(msg);
11868 return;
11869 }
11870
Johannes Berg68eb5502013-11-19 15:19:38 +010011871 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011872 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011873}
Johannes Bergcf5ead82014-11-14 17:14:00 +010011874EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020011875
Johannes Berg947add32013-02-22 22:05:20 +010011876void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11877 enum nl80211_connect_failed_reason reason,
11878 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011879{
Johannes Berg947add32013-02-22 22:05:20 +010011880 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011881 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011882 struct sk_buff *msg;
11883 void *hdr;
11884
11885 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11886 if (!msg)
11887 return;
11888
11889 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11890 if (!hdr) {
11891 nlmsg_free(msg);
11892 return;
11893 }
11894
11895 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11896 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11897 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11898 goto nla_put_failure;
11899
11900 genlmsg_end(msg, hdr);
11901
Johannes Berg68eb5502013-11-19 15:19:38 +010011902 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011903 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011904 return;
11905
11906 nla_put_failure:
11907 genlmsg_cancel(msg, hdr);
11908 nlmsg_free(msg);
11909}
Johannes Berg947add32013-02-22 22:05:20 +010011910EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011911
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011912static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11913 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011914{
11915 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011916 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011917 struct sk_buff *msg;
11918 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011919 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011920
Eric W. Biederman15e47302012-09-07 20:12:54 +000011921 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011922 return false;
11923
11924 msg = nlmsg_new(100, gfp);
11925 if (!msg)
11926 return true;
11927
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011928 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011929 if (!hdr) {
11930 nlmsg_free(msg);
11931 return true;
11932 }
11933
David S. Miller9360ffd2012-03-29 04:41:26 -040011934 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11935 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11936 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11937 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011938
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011939 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011940 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011941 return true;
11942
11943 nla_put_failure:
11944 genlmsg_cancel(msg, hdr);
11945 nlmsg_free(msg);
11946 return true;
11947}
11948
Johannes Berg947add32013-02-22 22:05:20 +010011949bool cfg80211_rx_spurious_frame(struct net_device *dev,
11950 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011951{
Johannes Berg947add32013-02-22 22:05:20 +010011952 struct wireless_dev *wdev = dev->ieee80211_ptr;
11953 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011954
Johannes Berg947add32013-02-22 22:05:20 +010011955 trace_cfg80211_rx_spurious_frame(dev, addr);
11956
11957 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11958 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11959 trace_cfg80211_return_bool(false);
11960 return false;
11961 }
11962 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11963 addr, gfp);
11964 trace_cfg80211_return_bool(ret);
11965 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011966}
Johannes Berg947add32013-02-22 22:05:20 +010011967EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11968
11969bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11970 const u8 *addr, gfp_t gfp)
11971{
11972 struct wireless_dev *wdev = dev->ieee80211_ptr;
11973 bool ret;
11974
11975 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11976
11977 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11978 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11979 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11980 trace_cfg80211_return_bool(false);
11981 return false;
11982 }
11983 ret = __nl80211_unexpected_frame(dev,
11984 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11985 addr, gfp);
11986 trace_cfg80211_return_bool(ret);
11987 return ret;
11988}
11989EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011990
Johannes Berg2e161f72010-08-12 15:38:38 +020011991int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011992 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011993 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011994 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011995{
Johannes Berg71bbc992012-06-15 15:30:18 +020011996 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011997 struct sk_buff *msg;
11998 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011999
12000 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12001 if (!msg)
12002 return -ENOMEM;
12003
Johannes Berg2e161f72010-08-12 15:38:38 +020012004 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012005 if (!hdr) {
12006 nlmsg_free(msg);
12007 return -ENOMEM;
12008 }
12009
David S. Miller9360ffd2012-03-29 04:41:26 -040012010 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012011 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12012 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012013 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012014 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12015 (sig_dbm &&
12016 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012017 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12018 (flags &&
12019 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012020 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012021
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012022 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012023
Eric W. Biederman15e47302012-09-07 20:12:54 +000012024 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012025
12026 nla_put_failure:
12027 genlmsg_cancel(msg, hdr);
12028 nlmsg_free(msg);
12029 return -ENOBUFS;
12030}
12031
Johannes Berg947add32013-02-22 22:05:20 +010012032void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12033 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012034{
Johannes Berg947add32013-02-22 22:05:20 +010012035 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012036 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012037 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012038 struct sk_buff *msg;
12039 void *hdr;
12040
Johannes Berg947add32013-02-22 22:05:20 +010012041 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12042
Jouni Malinen026331c2010-02-15 12:53:10 +020012043 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12044 if (!msg)
12045 return;
12046
Johannes Berg2e161f72010-08-12 15:38:38 +020012047 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012048 if (!hdr) {
12049 nlmsg_free(msg);
12050 return;
12051 }
12052
David S. Miller9360ffd2012-03-29 04:41:26 -040012053 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012054 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12055 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012056 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012057 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12058 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12059 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12060 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012061
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012062 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012063
Johannes Berg68eb5502013-11-19 15:19:38 +010012064 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012065 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012066 return;
12067
12068 nla_put_failure:
12069 genlmsg_cancel(msg, hdr);
12070 nlmsg_free(msg);
12071}
Johannes Berg947add32013-02-22 22:05:20 +010012072EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012073
Johannes Berg5b97f492014-11-26 12:37:43 +010012074static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12075 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012076{
Johannes Berg947add32013-02-22 22:05:20 +010012077 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012078 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12079 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12080 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012081
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012082 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012083 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012084
Johannes Berg5b97f492014-11-26 12:37:43 +010012085 cb = (void **)msg->cb;
12086
12087 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12088 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012089 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012090 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012091 }
12092
David S. Miller9360ffd2012-03-29 04:41:26 -040012093 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012094 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012095 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012096
Johannes Berg5b97f492014-11-26 12:37:43 +010012097 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012098 goto nla_put_failure;
12099
Johannes Berg5b97f492014-11-26 12:37:43 +010012100 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12101 if (!cb[1])
12102 goto nla_put_failure;
12103
12104 cb[2] = rdev;
12105
12106 return msg;
12107 nla_put_failure:
12108 nlmsg_free(msg);
12109 return NULL;
12110}
12111
12112static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12113{
12114 void **cb = (void **)msg->cb;
12115 struct cfg80211_registered_device *rdev = cb[2];
12116
12117 nla_nest_end(msg, cb[1]);
12118 genlmsg_end(msg, cb[0]);
12119
12120 memset(msg->cb, 0, sizeof(msg->cb));
12121
12122 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12123 NL80211_MCGRP_MLME, gfp);
12124}
12125
12126void cfg80211_cqm_rssi_notify(struct net_device *dev,
12127 enum nl80211_cqm_rssi_threshold_event rssi_event,
12128 gfp_t gfp)
12129{
12130 struct sk_buff *msg;
12131
12132 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12133
Johannes Berg98f03342014-11-26 12:42:02 +010012134 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12135 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12136 return;
12137
Johannes Berg5b97f492014-11-26 12:37:43 +010012138 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12139 if (!msg)
12140 return;
12141
David S. Miller9360ffd2012-03-29 04:41:26 -040012142 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12143 rssi_event))
12144 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012145
Johannes Berg5b97f492014-11-26 12:37:43 +010012146 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012147
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012148 return;
12149
12150 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012151 nlmsg_free(msg);
12152}
Johannes Berg947add32013-02-22 22:05:20 +010012153EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012154
Johannes Berg5b97f492014-11-26 12:37:43 +010012155void cfg80211_cqm_txe_notify(struct net_device *dev,
12156 const u8 *peer, u32 num_packets,
12157 u32 rate, u32 intvl, gfp_t gfp)
12158{
12159 struct sk_buff *msg;
12160
12161 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12162 if (!msg)
12163 return;
12164
12165 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12166 goto nla_put_failure;
12167
12168 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12169 goto nla_put_failure;
12170
12171 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12172 goto nla_put_failure;
12173
12174 cfg80211_send_cqm(msg, gfp);
12175 return;
12176
12177 nla_put_failure:
12178 nlmsg_free(msg);
12179}
12180EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12181
12182void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12183 const u8 *peer, u32 num_packets, gfp_t gfp)
12184{
12185 struct sk_buff *msg;
12186
12187 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12188
12189 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12190 if (!msg)
12191 return;
12192
12193 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12194 goto nla_put_failure;
12195
12196 cfg80211_send_cqm(msg, gfp);
12197 return;
12198
12199 nla_put_failure:
12200 nlmsg_free(msg);
12201}
12202EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12203
Johannes Berg98f03342014-11-26 12:42:02 +010012204void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12205{
12206 struct sk_buff *msg;
12207
12208 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12209 if (!msg)
12210 return;
12211
12212 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12213 goto nla_put_failure;
12214
12215 cfg80211_send_cqm(msg, gfp);
12216 return;
12217
12218 nla_put_failure:
12219 nlmsg_free(msg);
12220}
12221EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12222
Johannes Berg947add32013-02-22 22:05:20 +010012223static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12224 struct net_device *netdev, const u8 *bssid,
12225 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012226{
12227 struct sk_buff *msg;
12228 struct nlattr *rekey_attr;
12229 void *hdr;
12230
Thomas Graf58050fc2012-06-28 03:57:45 +000012231 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012232 if (!msg)
12233 return;
12234
12235 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12236 if (!hdr) {
12237 nlmsg_free(msg);
12238 return;
12239 }
12240
David S. Miller9360ffd2012-03-29 04:41:26 -040012241 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12242 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12243 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12244 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012245
12246 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12247 if (!rekey_attr)
12248 goto nla_put_failure;
12249
David S. Miller9360ffd2012-03-29 04:41:26 -040012250 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12251 NL80211_REPLAY_CTR_LEN, replay_ctr))
12252 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012253
12254 nla_nest_end(msg, rekey_attr);
12255
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012256 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012257
Johannes Berg68eb5502013-11-19 15:19:38 +010012258 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012259 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012260 return;
12261
12262 nla_put_failure:
12263 genlmsg_cancel(msg, hdr);
12264 nlmsg_free(msg);
12265}
12266
Johannes Berg947add32013-02-22 22:05:20 +010012267void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12268 const u8 *replay_ctr, gfp_t gfp)
12269{
12270 struct wireless_dev *wdev = dev->ieee80211_ptr;
12271 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012272 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012273
12274 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12275 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12276}
12277EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12278
12279static void
12280nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12281 struct net_device *netdev, int index,
12282 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012283{
12284 struct sk_buff *msg;
12285 struct nlattr *attr;
12286 void *hdr;
12287
Thomas Graf58050fc2012-06-28 03:57:45 +000012288 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012289 if (!msg)
12290 return;
12291
12292 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12293 if (!hdr) {
12294 nlmsg_free(msg);
12295 return;
12296 }
12297
David S. Miller9360ffd2012-03-29 04:41:26 -040012298 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12299 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12300 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012301
12302 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12303 if (!attr)
12304 goto nla_put_failure;
12305
David S. Miller9360ffd2012-03-29 04:41:26 -040012306 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12307 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12308 (preauth &&
12309 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12310 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012311
12312 nla_nest_end(msg, attr);
12313
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012314 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012315
Johannes Berg68eb5502013-11-19 15:19:38 +010012316 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012317 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012318 return;
12319
12320 nla_put_failure:
12321 genlmsg_cancel(msg, hdr);
12322 nlmsg_free(msg);
12323}
12324
Johannes Berg947add32013-02-22 22:05:20 +010012325void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12326 const u8 *bssid, bool preauth, gfp_t gfp)
12327{
12328 struct wireless_dev *wdev = dev->ieee80211_ptr;
12329 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012330 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012331
12332 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12333 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12334}
12335EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12336
12337static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12338 struct net_device *netdev,
12339 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012340 gfp_t gfp,
12341 enum nl80211_commands notif,
12342 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012343{
12344 struct sk_buff *msg;
12345 void *hdr;
12346
Thomas Graf58050fc2012-06-28 03:57:45 +000012347 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012348 if (!msg)
12349 return;
12350
Luciano Coelhof8d75522014-11-07 14:31:35 +020012351 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012352 if (!hdr) {
12353 nlmsg_free(msg);
12354 return;
12355 }
12356
Johannes Berg683b6d32012-11-08 21:25:48 +010012357 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12358 goto nla_put_failure;
12359
12360 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012361 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012362
Luciano Coelhof8d75522014-11-07 14:31:35 +020012363 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12364 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12365 goto nla_put_failure;
12366
Thomas Pedersen53145262012-04-06 13:35:47 -070012367 genlmsg_end(msg, hdr);
12368
Johannes Berg68eb5502013-11-19 15:19:38 +010012369 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012370 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012371 return;
12372
12373 nla_put_failure:
12374 genlmsg_cancel(msg, hdr);
12375 nlmsg_free(msg);
12376}
12377
Johannes Berg947add32013-02-22 22:05:20 +010012378void cfg80211_ch_switch_notify(struct net_device *dev,
12379 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012380{
Johannes Berg947add32013-02-22 22:05:20 +010012381 struct wireless_dev *wdev = dev->ieee80211_ptr;
12382 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012383 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012384
Simon Wunderliche487eae2013-11-21 18:19:51 +010012385 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012386
Simon Wunderliche487eae2013-11-21 18:19:51 +010012387 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012388
Michal Kazior9e0e2962014-01-29 14:22:27 +010012389 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012390 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012391 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12392 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012393}
12394EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12395
Luciano Coelhof8d75522014-11-07 14:31:35 +020012396void cfg80211_ch_switch_started_notify(struct net_device *dev,
12397 struct cfg80211_chan_def *chandef,
12398 u8 count)
12399{
12400 struct wireless_dev *wdev = dev->ieee80211_ptr;
12401 struct wiphy *wiphy = wdev->wiphy;
12402 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12403
12404 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12405
12406 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12407 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12408}
12409EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12410
Thomas Pedersen84f10702012-07-12 16:17:33 -070012411void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012412nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012413 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012414 enum nl80211_radar_event event,
12415 struct net_device *netdev, gfp_t gfp)
12416{
12417 struct sk_buff *msg;
12418 void *hdr;
12419
12420 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12421 if (!msg)
12422 return;
12423
12424 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12425 if (!hdr) {
12426 nlmsg_free(msg);
12427 return;
12428 }
12429
12430 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12431 goto nla_put_failure;
12432
12433 /* NOP and radar events don't need a netdev parameter */
12434 if (netdev) {
12435 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12436
12437 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12438 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12439 goto nla_put_failure;
12440 }
12441
12442 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12443 goto nla_put_failure;
12444
12445 if (nl80211_send_chandef(msg, chandef))
12446 goto nla_put_failure;
12447
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012448 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012449
Johannes Berg68eb5502013-11-19 15:19:38 +010012450 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012451 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012452 return;
12453
12454 nla_put_failure:
12455 genlmsg_cancel(msg, hdr);
12456 nlmsg_free(msg);
12457}
12458
Johannes Berg7f6cf312011-11-04 11:18:15 +010012459void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12460 u64 cookie, bool acked, gfp_t gfp)
12461{
12462 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012463 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012464 struct sk_buff *msg;
12465 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012466
Beni Lev4ee3e062012-08-27 12:49:39 +030012467 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12468
Thomas Graf58050fc2012-06-28 03:57:45 +000012469 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012470
Johannes Berg7f6cf312011-11-04 11:18:15 +010012471 if (!msg)
12472 return;
12473
12474 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12475 if (!hdr) {
12476 nlmsg_free(msg);
12477 return;
12478 }
12479
David S. Miller9360ffd2012-03-29 04:41:26 -040012480 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12481 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12482 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12483 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12484 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12485 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012486
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012487 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012488
Johannes Berg68eb5502013-11-19 15:19:38 +010012489 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012490 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012491 return;
12492
12493 nla_put_failure:
12494 genlmsg_cancel(msg, hdr);
12495 nlmsg_free(msg);
12496}
12497EXPORT_SYMBOL(cfg80211_probe_status);
12498
Johannes Berg5e760232011-11-04 11:18:17 +010012499void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12500 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012501 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012502{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012503 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012504 struct sk_buff *msg;
12505 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012506 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012507
Beni Lev4ee3e062012-08-27 12:49:39 +030012508 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12509
Ben Greear37c73b52012-10-26 14:49:25 -070012510 spin_lock_bh(&rdev->beacon_registrations_lock);
12511 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12512 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12513 if (!msg) {
12514 spin_unlock_bh(&rdev->beacon_registrations_lock);
12515 return;
12516 }
Johannes Berg5e760232011-11-04 11:18:17 +010012517
Ben Greear37c73b52012-10-26 14:49:25 -070012518 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12519 if (!hdr)
12520 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012521
Ben Greear37c73b52012-10-26 14:49:25 -070012522 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12523 (freq &&
12524 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12525 (sig_dbm &&
12526 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12527 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12528 goto nla_put_failure;
12529
12530 genlmsg_end(msg, hdr);
12531
12532 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012533 }
Ben Greear37c73b52012-10-26 14:49:25 -070012534 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012535 return;
12536
12537 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012538 spin_unlock_bh(&rdev->beacon_registrations_lock);
12539 if (hdr)
12540 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012541 nlmsg_free(msg);
12542}
12543EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12544
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012545#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012546static int cfg80211_net_detect_results(struct sk_buff *msg,
12547 struct cfg80211_wowlan_wakeup *wakeup)
12548{
12549 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12550 struct nlattr *nl_results, *nl_match, *nl_freqs;
12551 int i, j;
12552
12553 nl_results = nla_nest_start(
12554 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12555 if (!nl_results)
12556 return -EMSGSIZE;
12557
12558 for (i = 0; i < nd->n_matches; i++) {
12559 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12560
12561 nl_match = nla_nest_start(msg, i);
12562 if (!nl_match)
12563 break;
12564
12565 /* The SSID attribute is optional in nl80211, but for
12566 * simplicity reasons it's always present in the
12567 * cfg80211 structure. If a driver can't pass the
12568 * SSID, that needs to be changed. A zero length SSID
12569 * is still a valid SSID (wildcard), so it cannot be
12570 * used for this purpose.
12571 */
12572 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12573 match->ssid.ssid)) {
12574 nla_nest_cancel(msg, nl_match);
12575 goto out;
12576 }
12577
12578 if (match->n_channels) {
12579 nl_freqs = nla_nest_start(
12580 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12581 if (!nl_freqs) {
12582 nla_nest_cancel(msg, nl_match);
12583 goto out;
12584 }
12585
12586 for (j = 0; j < match->n_channels; j++) {
12587 if (nla_put_u32(msg,
12588 NL80211_ATTR_WIPHY_FREQ,
12589 match->channels[j])) {
12590 nla_nest_cancel(msg, nl_freqs);
12591 nla_nest_cancel(msg, nl_match);
12592 goto out;
12593 }
12594 }
12595
12596 nla_nest_end(msg, nl_freqs);
12597 }
12598
12599 nla_nest_end(msg, nl_match);
12600 }
12601
12602out:
12603 nla_nest_end(msg, nl_results);
12604 return 0;
12605}
12606
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012607void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12608 struct cfg80211_wowlan_wakeup *wakeup,
12609 gfp_t gfp)
12610{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012611 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012612 struct sk_buff *msg;
12613 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012614 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012615
12616 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12617
12618 if (wakeup)
12619 size += wakeup->packet_present_len;
12620
12621 msg = nlmsg_new(size, gfp);
12622 if (!msg)
12623 return;
12624
12625 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12626 if (!hdr)
12627 goto free_msg;
12628
12629 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12630 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12631 goto free_msg;
12632
12633 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12634 wdev->netdev->ifindex))
12635 goto free_msg;
12636
12637 if (wakeup) {
12638 struct nlattr *reasons;
12639
12640 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012641 if (!reasons)
12642 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012643
12644 if (wakeup->disconnect &&
12645 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12646 goto free_msg;
12647 if (wakeup->magic_pkt &&
12648 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12649 goto free_msg;
12650 if (wakeup->gtk_rekey_failure &&
12651 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12652 goto free_msg;
12653 if (wakeup->eap_identity_req &&
12654 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12655 goto free_msg;
12656 if (wakeup->four_way_handshake &&
12657 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12658 goto free_msg;
12659 if (wakeup->rfkill_release &&
12660 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12661 goto free_msg;
12662
12663 if (wakeup->pattern_idx >= 0 &&
12664 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12665 wakeup->pattern_idx))
12666 goto free_msg;
12667
Johannes Bergae917c92013-10-25 11:05:22 +020012668 if (wakeup->tcp_match &&
12669 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12670 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012671
Johannes Bergae917c92013-10-25 11:05:22 +020012672 if (wakeup->tcp_connlost &&
12673 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12674 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012675
Johannes Bergae917c92013-10-25 11:05:22 +020012676 if (wakeup->tcp_nomoretokens &&
12677 nla_put_flag(msg,
12678 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12679 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012680
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012681 if (wakeup->packet) {
12682 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12683 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12684
12685 if (!wakeup->packet_80211) {
12686 pkt_attr =
12687 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12688 len_attr =
12689 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12690 }
12691
12692 if (wakeup->packet_len &&
12693 nla_put_u32(msg, len_attr, wakeup->packet_len))
12694 goto free_msg;
12695
12696 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12697 wakeup->packet))
12698 goto free_msg;
12699 }
12700
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012701 if (wakeup->net_detect &&
12702 cfg80211_net_detect_results(msg, wakeup))
12703 goto free_msg;
12704
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012705 nla_nest_end(msg, reasons);
12706 }
12707
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012708 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012709
Johannes Berg68eb5502013-11-19 15:19:38 +010012710 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012711 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012712 return;
12713
12714 free_msg:
12715 nlmsg_free(msg);
12716}
12717EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12718#endif
12719
Jouni Malinen3475b092012-11-16 22:49:57 +020012720void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12721 enum nl80211_tdls_operation oper,
12722 u16 reason_code, gfp_t gfp)
12723{
12724 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012725 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012726 struct sk_buff *msg;
12727 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012728
12729 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12730 reason_code);
12731
12732 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12733 if (!msg)
12734 return;
12735
12736 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12737 if (!hdr) {
12738 nlmsg_free(msg);
12739 return;
12740 }
12741
12742 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12743 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12744 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12745 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12746 (reason_code > 0 &&
12747 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12748 goto nla_put_failure;
12749
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012750 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012751
Johannes Berg68eb5502013-11-19 15:19:38 +010012752 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012753 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012754 return;
12755
12756 nla_put_failure:
12757 genlmsg_cancel(msg, hdr);
12758 nlmsg_free(msg);
12759}
12760EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12761
Jouni Malinen026331c2010-02-15 12:53:10 +020012762static int nl80211_netlink_notify(struct notifier_block * nb,
12763 unsigned long state,
12764 void *_notify)
12765{
12766 struct netlink_notify *notify = _notify;
12767 struct cfg80211_registered_device *rdev;
12768 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012769 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012770
12771 if (state != NETLINK_URELEASE)
12772 return NOTIFY_DONE;
12773
12774 rcu_read_lock();
12775
Johannes Berg5e760232011-11-04 11:18:17 +010012776 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012777 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012778 bool schedule_scan_stop = false;
12779 struct cfg80211_sched_scan_request *sched_scan_req =
12780 rcu_dereference(rdev->sched_scan_req);
12781
12782 if (sched_scan_req && notify->portid &&
12783 sched_scan_req->owner_nlportid == notify->portid)
12784 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010012785
12786 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012787 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012788
Johannes Berg78f22b62014-03-24 17:57:27 +010012789 if (wdev->owner_nlportid == notify->portid)
12790 schedule_destroy_work = true;
12791 }
12792
Ben Greear37c73b52012-10-26 14:49:25 -070012793 spin_lock_bh(&rdev->beacon_registrations_lock);
12794 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12795 list) {
12796 if (reg->nlportid == notify->portid) {
12797 list_del(&reg->list);
12798 kfree(reg);
12799 break;
12800 }
12801 }
12802 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012803
12804 if (schedule_destroy_work) {
12805 struct cfg80211_iface_destroy *destroy;
12806
12807 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12808 if (destroy) {
12809 destroy->nlportid = notify->portid;
12810 spin_lock(&rdev->destroy_list_lock);
12811 list_add(&destroy->list, &rdev->destroy_list);
12812 spin_unlock(&rdev->destroy_list_lock);
12813 schedule_work(&rdev->destroy_work);
12814 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012815 } else if (schedule_scan_stop) {
12816 sched_scan_req->owner_nlportid = 0;
12817
12818 if (rdev->ops->sched_scan_stop &&
12819 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
12820 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010012821 }
Johannes Berg5e760232011-11-04 11:18:17 +010012822 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012823
12824 rcu_read_unlock();
12825
Ilan peer05050752015-03-04 00:32:06 -050012826 /*
12827 * It is possible that the user space process that is controlling the
12828 * indoor setting disappeared, so notify the regulatory core.
12829 */
12830 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012831 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012832}
12833
12834static struct notifier_block nl80211_netlink_notifier = {
12835 .notifier_call = nl80211_netlink_notify,
12836};
12837
Jouni Malinen355199e2013-02-27 17:14:27 +020012838void cfg80211_ft_event(struct net_device *netdev,
12839 struct cfg80211_ft_event_params *ft_event)
12840{
12841 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012842 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012843 struct sk_buff *msg;
12844 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012845
12846 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12847
12848 if (!ft_event->target_ap)
12849 return;
12850
12851 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12852 if (!msg)
12853 return;
12854
12855 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012856 if (!hdr)
12857 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012858
Johannes Bergae917c92013-10-25 11:05:22 +020012859 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12860 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12861 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12862 goto out;
12863
12864 if (ft_event->ies &&
12865 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12866 goto out;
12867 if (ft_event->ric_ies &&
12868 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12869 ft_event->ric_ies))
12870 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012871
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012872 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012873
Johannes Berg68eb5502013-11-19 15:19:38 +010012874 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012875 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012876 return;
12877 out:
12878 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012879}
12880EXPORT_SYMBOL(cfg80211_ft_event);
12881
Arend van Spriel5de17982013-04-18 15:49:00 +020012882void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12883{
12884 struct cfg80211_registered_device *rdev;
12885 struct sk_buff *msg;
12886 void *hdr;
12887 u32 nlportid;
12888
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012889 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012890 if (!rdev->crit_proto_nlportid)
12891 return;
12892
12893 nlportid = rdev->crit_proto_nlportid;
12894 rdev->crit_proto_nlportid = 0;
12895
12896 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12897 if (!msg)
12898 return;
12899
12900 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12901 if (!hdr)
12902 goto nla_put_failure;
12903
12904 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12905 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12906 goto nla_put_failure;
12907
12908 genlmsg_end(msg, hdr);
12909
12910 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12911 return;
12912
12913 nla_put_failure:
12914 if (hdr)
12915 genlmsg_cancel(msg, hdr);
12916 nlmsg_free(msg);
12917
12918}
12919EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12920
Johannes Berg348baf02014-01-24 14:06:29 +010012921void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12922{
12923 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012924 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012925 struct sk_buff *msg;
12926 void *hdr;
12927
12928 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12929 if (!msg)
12930 return;
12931
12932 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12933 if (!hdr)
12934 goto out;
12935
12936 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12937 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12938 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12939 goto out;
12940
12941 genlmsg_end(msg, hdr);
12942
12943 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12944 NL80211_MCGRP_MLME, GFP_KERNEL);
12945 return;
12946 out:
12947 nlmsg_free(msg);
12948}
12949
Johannes Berg55682962007-09-20 13:09:35 -040012950/* initialisation/exit functions */
12951
12952int nl80211_init(void)
12953{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012954 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012955
Johannes Berg2a94fe42013-11-19 15:19:39 +010012956 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12957 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012958 if (err)
12959 return err;
12960
Jouni Malinen026331c2010-02-15 12:53:10 +020012961 err = netlink_register_notifier(&nl80211_netlink_notifier);
12962 if (err)
12963 goto err_out;
12964
Johannes Berg55682962007-09-20 13:09:35 -040012965 return 0;
12966 err_out:
12967 genl_unregister_family(&nl80211_fam);
12968 return err;
12969}
12970
12971void nl80211_exit(void)
12972{
Jouni Malinen026331c2010-02-15 12:53:10 +020012973 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012974 genl_unregister_family(&nl80211_fam);
12975}