blob: 9c4d0102d34de5271589c3fc8f6daa03e6c9555d [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[] = {
62 [NL80211_MCGRP_CONFIG] = { .name = "config", },
63 [NL80211_MCGRP_SCAN] = { .name = "scan", },
64 [NL80211_MCGRP_REGULATORY] = { .name = "regulatory", },
65 [NL80211_MCGRP_MLME] = { .name = "mlme", },
Johannes Berg567ffc32013-12-18 14:43:31 +010066 [NL80211_MCGRP_VENDOR] = { .name = "vendor", },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
68 [NL80211_MCGRP_TESTMODE] = { .name = "testmode", }
69#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 },
Johannes Berg55682962007-09-20 13:09:35 -0400399};
400
Johannes Berge31b8212010-10-05 19:39:30 +0200401/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000402static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200403 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200404 [NL80211_KEY_IDX] = { .type = NLA_U8 },
405 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200406 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200407 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
408 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200409 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100410 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
411};
412
413/* policy for the key default flags */
414static const struct nla_policy
415nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
416 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
417 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200418};
419
Johannes Bergff1b6e62011-05-04 15:37:28 +0200420/* policy for WoWLAN attributes */
421static const struct nla_policy
422nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
423 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
424 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
425 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
426 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200427 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100431 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300432 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100433};
434
435static const struct nla_policy
436nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
437 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
438 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
439 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
440 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
441 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
442 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
443 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
444 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
445 },
446 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
447 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
448 },
449 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
450 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
451 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200452};
453
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700454/* policy for coalesce rule attributes */
455static const struct nla_policy
456nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
457 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
458 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
459 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
460};
461
Johannes Berge5497d72011-07-05 16:35:40 +0200462/* policy for GTK rekey offload attributes */
463static const struct nla_policy
464nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
465 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
466 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
467 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
468};
469
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300470static const struct nla_policy
471nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200472 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300473 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700474 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300475};
476
Johannes Berg97990a02013-04-19 01:02:55 +0200477static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
478 struct netlink_callback *cb,
479 struct cfg80211_registered_device **rdev,
480 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100481{
Johannes Berg67748892010-10-04 21:14:06 +0200482 int err;
483
Johannes Berg67748892010-10-04 21:14:06 +0200484 rtnl_lock();
485
Johannes Berg97990a02013-04-19 01:02:55 +0200486 if (!cb->args[0]) {
487 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
488 nl80211_fam.attrbuf, nl80211_fam.maxattr,
489 nl80211_policy);
490 if (err)
491 goto out_unlock;
492
493 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
494 nl80211_fam.attrbuf);
495 if (IS_ERR(*wdev)) {
496 err = PTR_ERR(*wdev);
497 goto out_unlock;
498 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800499 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200500 /* 0 is the first index - add 1 to parse only once */
501 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200502 cb->args[1] = (*wdev)->identifier;
503 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200504 /* subtract the 1 again here */
505 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200506 struct wireless_dev *tmp;
507
508 if (!wiphy) {
509 err = -ENODEV;
510 goto out_unlock;
511 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800512 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200513 *wdev = NULL;
514
Johannes Berg97990a02013-04-19 01:02:55 +0200515 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
516 if (tmp->identifier == cb->args[1]) {
517 *wdev = tmp;
518 break;
519 }
520 }
Johannes Berg97990a02013-04-19 01:02:55 +0200521
522 if (!*wdev) {
523 err = -ENODEV;
524 goto out_unlock;
525 }
Johannes Berg67748892010-10-04 21:14:06 +0200526 }
527
Johannes Berg67748892010-10-04 21:14:06 +0200528 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200529 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200530 rtnl_unlock();
531 return err;
532}
533
Johannes Berg97990a02013-04-19 01:02:55 +0200534static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200535{
Johannes Berg67748892010-10-04 21:14:06 +0200536 rtnl_unlock();
537}
538
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100539/* IE validation */
540static bool is_valid_ie_attr(const struct nlattr *attr)
541{
542 const u8 *pos;
543 int len;
544
545 if (!attr)
546 return true;
547
548 pos = nla_data(attr);
549 len = nla_len(attr);
550
551 while (len) {
552 u8 elemlen;
553
554 if (len < 2)
555 return false;
556 len -= 2;
557
558 elemlen = pos[1];
559 if (elemlen > len)
560 return false;
561
562 len -= elemlen;
563 pos += 2 + elemlen;
564 }
565
566 return true;
567}
568
Johannes Berg55682962007-09-20 13:09:35 -0400569/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000570static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400571 int flags, u8 cmd)
572{
573 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000574 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400575}
576
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400577static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100578 struct ieee80211_channel *chan,
579 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400580{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200581 /* Some channels must be completely excluded from the
582 * list to protect old user-space tools from breaking
583 */
584 if (!large && chan->flags &
585 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
586 return 0;
587
David S. Miller9360ffd2012-03-29 04:41:26 -0400588 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
589 chan->center_freq))
590 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400591
David S. Miller9360ffd2012-03-29 04:41:26 -0400592 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
593 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
594 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200595 if (chan->flags & IEEE80211_CHAN_NO_IR) {
596 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
597 goto nla_put_failure;
598 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
599 goto nla_put_failure;
600 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100601 if (chan->flags & IEEE80211_CHAN_RADAR) {
602 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
603 goto nla_put_failure;
604 if (large) {
605 u32 time;
606
607 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
608
609 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
610 chan->dfs_state))
611 goto nla_put_failure;
612 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
613 time))
614 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100615 if (nla_put_u32(msg,
616 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
617 chan->dfs_cac_ms))
618 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100619 }
620 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400621
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100622 if (large) {
623 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
624 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
625 goto nla_put_failure;
626 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
627 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
628 goto nla_put_failure;
629 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
630 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
631 goto nla_put_failure;
632 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
633 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
634 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200635 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
636 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
637 goto nla_put_failure;
638 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
639 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
640 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200641 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
642 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
643 goto nla_put_failure;
644 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
645 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
646 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100647 }
648
David S. Miller9360ffd2012-03-29 04:41:26 -0400649 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
650 DBM_TO_MBM(chan->max_power)))
651 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400652
653 return 0;
654
655 nla_put_failure:
656 return -ENOBUFS;
657}
658
Johannes Berg55682962007-09-20 13:09:35 -0400659/* netlink command implementations */
660
Johannes Bergb9454e82009-07-08 13:29:08 +0200661struct key_parse {
662 struct key_params p;
663 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200664 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200665 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100666 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200667};
668
669static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
670{
671 struct nlattr *tb[NL80211_KEY_MAX + 1];
672 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
673 nl80211_key_policy);
674 if (err)
675 return err;
676
677 k->def = !!tb[NL80211_KEY_DEFAULT];
678 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
679
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100680 if (k->def) {
681 k->def_uni = true;
682 k->def_multi = true;
683 }
684 if (k->defmgmt)
685 k->def_multi = true;
686
Johannes Bergb9454e82009-07-08 13:29:08 +0200687 if (tb[NL80211_KEY_IDX])
688 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
689
690 if (tb[NL80211_KEY_DATA]) {
691 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
692 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
693 }
694
695 if (tb[NL80211_KEY_SEQ]) {
696 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
697 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
698 }
699
700 if (tb[NL80211_KEY_CIPHER])
701 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
702
Johannes Berge31b8212010-10-05 19:39:30 +0200703 if (tb[NL80211_KEY_TYPE]) {
704 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
705 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
706 return -EINVAL;
707 }
708
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100709 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
710 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100711 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
712 tb[NL80211_KEY_DEFAULT_TYPES],
713 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100714 if (err)
715 return err;
716
717 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
718 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
719 }
720
Johannes Bergb9454e82009-07-08 13:29:08 +0200721 return 0;
722}
723
724static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
725{
726 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
727 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
728 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
729 }
730
731 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
732 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
733 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
734 }
735
736 if (info->attrs[NL80211_ATTR_KEY_IDX])
737 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
738
739 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
740 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
741
742 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
743 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
744
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100745 if (k->def) {
746 k->def_uni = true;
747 k->def_multi = true;
748 }
749 if (k->defmgmt)
750 k->def_multi = true;
751
Johannes Berge31b8212010-10-05 19:39:30 +0200752 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
753 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
754 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
755 return -EINVAL;
756 }
757
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100758 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
759 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
760 int err = nla_parse_nested(
761 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
762 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
763 nl80211_key_default_policy);
764 if (err)
765 return err;
766
767 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
768 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
769 }
770
Johannes Bergb9454e82009-07-08 13:29:08 +0200771 return 0;
772}
773
774static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
775{
776 int err;
777
778 memset(k, 0, sizeof(*k));
779 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200780 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200781
782 if (info->attrs[NL80211_ATTR_KEY])
783 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
784 else
785 err = nl80211_parse_key_old(info, k);
786
787 if (err)
788 return err;
789
790 if (k->def && k->defmgmt)
791 return -EINVAL;
792
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100793 if (k->defmgmt) {
794 if (k->def_uni || !k->def_multi)
795 return -EINVAL;
796 }
797
Johannes Bergb9454e82009-07-08 13:29:08 +0200798 if (k->idx != -1) {
799 if (k->defmgmt) {
800 if (k->idx < 4 || k->idx > 5)
801 return -EINVAL;
802 } else if (k->def) {
803 if (k->idx < 0 || k->idx > 3)
804 return -EINVAL;
805 } else {
806 if (k->idx < 0 || k->idx > 5)
807 return -EINVAL;
808 }
809 }
810
811 return 0;
812}
813
Johannes Bergfffd0932009-07-08 14:22:54 +0200814static struct cfg80211_cached_keys *
815nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530816 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200817{
818 struct key_parse parse;
819 struct nlattr *key;
820 struct cfg80211_cached_keys *result;
821 int rem, err, def = 0;
822
823 result = kzalloc(sizeof(*result), GFP_KERNEL);
824 if (!result)
825 return ERR_PTR(-ENOMEM);
826
827 result->def = -1;
828 result->defmgmt = -1;
829
830 nla_for_each_nested(key, keys, rem) {
831 memset(&parse, 0, sizeof(parse));
832 parse.idx = -1;
833
834 err = nl80211_parse_key_new(key, &parse);
835 if (err)
836 goto error;
837 err = -EINVAL;
838 if (!parse.p.key)
839 goto error;
840 if (parse.idx < 0 || parse.idx > 4)
841 goto error;
842 if (parse.def) {
843 if (def)
844 goto error;
845 def = 1;
846 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100847 if (!parse.def_uni || !parse.def_multi)
848 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200849 } else if (parse.defmgmt)
850 goto error;
851 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200852 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200853 if (err)
854 goto error;
855 result->params[parse.idx].cipher = parse.p.cipher;
856 result->params[parse.idx].key_len = parse.p.key_len;
857 result->params[parse.idx].key = result->data[parse.idx];
858 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530859
860 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
861 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
862 if (no_ht)
863 *no_ht = true;
864 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200865 }
866
867 return result;
868 error:
869 kfree(result);
870 return ERR_PTR(err);
871}
872
873static int nl80211_key_allowed(struct wireless_dev *wdev)
874{
875 ASSERT_WDEV_LOCK(wdev);
876
Johannes Bergfffd0932009-07-08 14:22:54 +0200877 switch (wdev->iftype) {
878 case NL80211_IFTYPE_AP:
879 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200880 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700881 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200882 break;
883 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200884 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200885 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200886 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200887 return -ENOLINK;
888 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100889 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100890 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100891 case NL80211_IFTYPE_MONITOR:
892 case NL80211_IFTYPE_P2P_DEVICE:
893 case NL80211_IFTYPE_WDS:
894 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200895 return -EINVAL;
896 }
897
898 return 0;
899}
900
Jouni Malinen664834d2014-01-15 00:01:44 +0200901static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
902 struct nlattr *tb)
903{
904 struct ieee80211_channel *chan;
905
906 if (tb == NULL)
907 return NULL;
908 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
909 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
910 return NULL;
911 return chan;
912}
913
Johannes Berg7527a782011-05-13 10:58:57 +0200914static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
915{
916 struct nlattr *nl_modes = nla_nest_start(msg, attr);
917 int i;
918
919 if (!nl_modes)
920 goto nla_put_failure;
921
922 i = 0;
923 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400924 if ((ifmodes & 1) && nla_put_flag(msg, i))
925 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200926 ifmodes >>= 1;
927 i++;
928 }
929
930 nla_nest_end(msg, nl_modes);
931 return 0;
932
933nla_put_failure:
934 return -ENOBUFS;
935}
936
937static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100938 struct sk_buff *msg,
939 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200940{
941 struct nlattr *nl_combis;
942 int i, j;
943
944 nl_combis = nla_nest_start(msg,
945 NL80211_ATTR_INTERFACE_COMBINATIONS);
946 if (!nl_combis)
947 goto nla_put_failure;
948
949 for (i = 0; i < wiphy->n_iface_combinations; i++) {
950 const struct ieee80211_iface_combination *c;
951 struct nlattr *nl_combi, *nl_limits;
952
953 c = &wiphy->iface_combinations[i];
954
955 nl_combi = nla_nest_start(msg, i + 1);
956 if (!nl_combi)
957 goto nla_put_failure;
958
959 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
960 if (!nl_limits)
961 goto nla_put_failure;
962
963 for (j = 0; j < c->n_limits; j++) {
964 struct nlattr *nl_limit;
965
966 nl_limit = nla_nest_start(msg, j + 1);
967 if (!nl_limit)
968 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400969 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
970 c->limits[j].max))
971 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200972 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
973 c->limits[j].types))
974 goto nla_put_failure;
975 nla_nest_end(msg, nl_limit);
976 }
977
978 nla_nest_end(msg, nl_limits);
979
David S. Miller9360ffd2012-03-29 04:41:26 -0400980 if (c->beacon_int_infra_match &&
981 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
982 goto nla_put_failure;
983 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
984 c->num_different_channels) ||
985 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
986 c->max_interfaces))
987 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100988 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200989 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
990 c->radar_detect_widths) ||
991 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
992 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100993 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200994
995 nla_nest_end(msg, nl_combi);
996 }
997
998 nla_nest_end(msg, nl_combis);
999
1000 return 0;
1001nla_put_failure:
1002 return -ENOBUFS;
1003}
1004
Johannes Berg3713b4e2013-02-14 16:19:38 +01001005#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001006static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1007 struct sk_buff *msg)
1008{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001009 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001010 struct nlattr *nl_tcp;
1011
1012 if (!tcp)
1013 return 0;
1014
1015 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1016 if (!nl_tcp)
1017 return -ENOBUFS;
1018
1019 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1020 tcp->data_payload_max))
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 (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1028 return -ENOBUFS;
1029
1030 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1031 sizeof(*tcp->tok), tcp->tok))
1032 return -ENOBUFS;
1033
1034 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1035 tcp->data_interval_max))
1036 return -ENOBUFS;
1037
1038 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1039 tcp->wake_payload_max))
1040 return -ENOBUFS;
1041
1042 nla_nest_end(msg, nl_tcp);
1043 return 0;
1044}
1045
Johannes Berg3713b4e2013-02-14 16:19:38 +01001046static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001047 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001048 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001049{
1050 struct nlattr *nl_wowlan;
1051
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001052 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053 return 0;
1054
1055 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1056 if (!nl_wowlan)
1057 return -ENOBUFS;
1058
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001059 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001060 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001061 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001062 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001066 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001067 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001068 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001069 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001070 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001071 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001073 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001074 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1075 return -ENOBUFS;
1076
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001078 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001079 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1080 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1081 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1082 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001083 };
1084
1085 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1086 sizeof(pat), &pat))
1087 return -ENOBUFS;
1088 }
1089
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001090 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001091 return -ENOBUFS;
1092
Luciano Coelho8cd4d452014-09-17 11:55:28 +03001093 /* TODO: send wowlan net detect */
1094
Johannes Berg3713b4e2013-02-14 16:19:38 +01001095 nla_nest_end(msg, nl_wowlan);
1096
1097 return 0;
1098}
1099#endif
1100
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001101static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001102 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001103{
1104 struct nl80211_coalesce_rule_support rule;
1105
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001106 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001107 return 0;
1108
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001109 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1110 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1111 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1112 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1113 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1114 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001115
1116 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1117 return -ENOBUFS;
1118
1119 return 0;
1120}
1121
Johannes Berg3713b4e2013-02-14 16:19:38 +01001122static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1123 struct ieee80211_supported_band *sband)
1124{
1125 struct nlattr *nl_rates, *nl_rate;
1126 struct ieee80211_rate *rate;
1127 int i;
1128
1129 /* add HT info */
1130 if (sband->ht_cap.ht_supported &&
1131 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1132 sizeof(sband->ht_cap.mcs),
1133 &sband->ht_cap.mcs) ||
1134 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1135 sband->ht_cap.cap) ||
1136 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1137 sband->ht_cap.ampdu_factor) ||
1138 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1139 sband->ht_cap.ampdu_density)))
1140 return -ENOBUFS;
1141
1142 /* add VHT info */
1143 if (sband->vht_cap.vht_supported &&
1144 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1145 sizeof(sband->vht_cap.vht_mcs),
1146 &sband->vht_cap.vht_mcs) ||
1147 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1148 sband->vht_cap.cap)))
1149 return -ENOBUFS;
1150
1151 /* add bitrates */
1152 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1153 if (!nl_rates)
1154 return -ENOBUFS;
1155
1156 for (i = 0; i < sband->n_bitrates; i++) {
1157 nl_rate = nla_nest_start(msg, i);
1158 if (!nl_rate)
1159 return -ENOBUFS;
1160
1161 rate = &sband->bitrates[i];
1162 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1163 rate->bitrate))
1164 return -ENOBUFS;
1165 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1166 nla_put_flag(msg,
1167 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1168 return -ENOBUFS;
1169
1170 nla_nest_end(msg, nl_rate);
1171 }
1172
1173 nla_nest_end(msg, nl_rates);
1174
1175 return 0;
1176}
1177
1178static int
1179nl80211_send_mgmt_stypes(struct sk_buff *msg,
1180 const struct ieee80211_txrx_stypes *mgmt_stypes)
1181{
1182 u16 stypes;
1183 struct nlattr *nl_ftypes, *nl_ifs;
1184 enum nl80211_iftype ift;
1185 int i;
1186
1187 if (!mgmt_stypes)
1188 return 0;
1189
1190 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1191 if (!nl_ifs)
1192 return -ENOBUFS;
1193
1194 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1195 nl_ftypes = nla_nest_start(msg, ift);
1196 if (!nl_ftypes)
1197 return -ENOBUFS;
1198 i = 0;
1199 stypes = mgmt_stypes[ift].tx;
1200 while (stypes) {
1201 if ((stypes & 1) &&
1202 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1203 (i << 4) | IEEE80211_FTYPE_MGMT))
1204 return -ENOBUFS;
1205 stypes >>= 1;
1206 i++;
1207 }
1208 nla_nest_end(msg, nl_ftypes);
1209 }
1210
1211 nla_nest_end(msg, nl_ifs);
1212
1213 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1214 if (!nl_ifs)
1215 return -ENOBUFS;
1216
1217 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1218 nl_ftypes = nla_nest_start(msg, ift);
1219 if (!nl_ftypes)
1220 return -ENOBUFS;
1221 i = 0;
1222 stypes = mgmt_stypes[ift].rx;
1223 while (stypes) {
1224 if ((stypes & 1) &&
1225 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1226 (i << 4) | IEEE80211_FTYPE_MGMT))
1227 return -ENOBUFS;
1228 stypes >>= 1;
1229 i++;
1230 }
1231 nla_nest_end(msg, nl_ftypes);
1232 }
1233 nla_nest_end(msg, nl_ifs);
1234
1235 return 0;
1236}
1237
Johannes Berg86e8cf92013-06-19 10:57:22 +02001238struct nl80211_dump_wiphy_state {
1239 s64 filter_wiphy;
1240 long start;
1241 long split_start, band_start, chan_start;
1242 bool split;
1243};
1244
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001245static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001246 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001247 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001248 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001249{
1250 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001251 struct nlattr *nl_bands, *nl_band;
1252 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001253 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001254 enum ieee80211_band band;
1255 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001256 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001257 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001258 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001259 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001260
Johannes Berg3bb20552014-05-26 13:52:25 +02001261 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001262 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001263 return -ENOBUFS;
1264
Johannes Berg86e8cf92013-06-19 10:57:22 +02001265 if (WARN_ON(!state))
1266 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001267
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001268 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001269 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001270 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001271 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001273 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001274
Johannes Berg3bb20552014-05-26 13:52:25 +02001275 if (cmd != NL80211_CMD_NEW_WIPHY)
1276 goto finish;
1277
Johannes Berg86e8cf92013-06-19 10:57:22 +02001278 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 case 0:
1280 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001281 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001282 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001283 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001284 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001285 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001287 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001289 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001290 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001291 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001292 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001293 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001294 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001295 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001296 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001297 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001298 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001299 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001300 goto nla_put_failure;
1301
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1304 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001305 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001306 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1307 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001308 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001309 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1310 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1313 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001314 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001315 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1316 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001319 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001320 state->split_start++;
1321 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 break;
1323 case 1:
1324 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001325 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1326 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001327 goto nla_put_failure;
1328
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001330 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001331 goto nla_put_failure;
1332
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001333 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001334 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1335 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001336
Johannes Berg3713b4e2013-02-14 16:19:38 +01001337 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001338 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001339 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001342
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001343 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001345 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001347
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001348 if ((rdev->wiphy.available_antennas_tx ||
1349 rdev->wiphy.available_antennas_rx) &&
1350 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 u32 tx_ant = 0, rx_ant = 0;
1352 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001353 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001354 if (!res) {
1355 if (nla_put_u32(msg,
1356 NL80211_ATTR_WIPHY_ANTENNA_TX,
1357 tx_ant) ||
1358 nla_put_u32(msg,
1359 NL80211_ATTR_WIPHY_ANTENNA_RX,
1360 rx_ant))
1361 goto nla_put_failure;
1362 }
Johannes Bergee688b002008-01-24 19:38:39 +01001363 }
1364
Johannes Berg86e8cf92013-06-19 10:57:22 +02001365 state->split_start++;
1366 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001367 break;
1368 case 2:
1369 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001370 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001371 goto nla_put_failure;
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 3:
1376 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1377 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001378 goto nla_put_failure;
1379
Johannes Berg86e8cf92013-06-19 10:57:22 +02001380 for (band = state->band_start;
1381 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001382 struct ieee80211_supported_band *sband;
1383
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001384 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001385
1386 if (!sband)
1387 continue;
1388
1389 nl_band = nla_nest_start(msg, band);
1390 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001391 goto nla_put_failure;
1392
Johannes Berg86e8cf92013-06-19 10:57:22 +02001393 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394 case 0:
1395 if (nl80211_send_band_rateinfo(msg, sband))
1396 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001397 state->chan_start++;
1398 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001399 break;
1400 default:
1401 /* add frequencies */
1402 nl_freqs = nla_nest_start(
1403 msg, NL80211_BAND_ATTR_FREQS);
1404 if (!nl_freqs)
1405 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001406
Johannes Berg86e8cf92013-06-19 10:57:22 +02001407 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001408 i < sband->n_channels;
1409 i++) {
1410 nl_freq = nla_nest_start(msg, i);
1411 if (!nl_freq)
1412 goto nla_put_failure;
1413
1414 chan = &sband->channels[i];
1415
Johannes Berg86e8cf92013-06-19 10:57:22 +02001416 if (nl80211_msg_put_channel(
1417 msg, chan,
1418 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001419 goto nla_put_failure;
1420
1421 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001422 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001423 break;
1424 }
1425 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001426 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001427 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001428 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001429 nla_nest_end(msg, nl_freqs);
1430 }
1431
1432 nla_nest_end(msg, nl_band);
1433
Johannes Berg86e8cf92013-06-19 10:57:22 +02001434 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001435 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001436 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001437 band--;
1438 break;
1439 }
Johannes Bergee688b002008-01-24 19:38:39 +01001440 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001441 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001442
Johannes Berg3713b4e2013-02-14 16:19:38 +01001443 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001444 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001445 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001446 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001447
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001449 if (state->band_start == 0 && state->chan_start == 0)
1450 state->split_start++;
1451 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 break;
1453 case 4:
1454 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1455 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001456 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457
1458 i = 0;
1459#define CMD(op, n) \
1460 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001461 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001462 i++; \
1463 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1464 goto nla_put_failure; \
1465 } \
1466 } while (0)
1467
1468 CMD(add_virtual_intf, NEW_INTERFACE);
1469 CMD(change_virtual_intf, SET_INTERFACE);
1470 CMD(add_key, NEW_KEY);
1471 CMD(start_ap, START_AP);
1472 CMD(add_station, NEW_STATION);
1473 CMD(add_mpath, NEW_MPATH);
1474 CMD(update_mesh_config, SET_MESH_CONFIG);
1475 CMD(change_bss, SET_BSS);
1476 CMD(auth, AUTHENTICATE);
1477 CMD(assoc, ASSOCIATE);
1478 CMD(deauth, DEAUTHENTICATE);
1479 CMD(disassoc, DISASSOCIATE);
1480 CMD(join_ibss, JOIN_IBSS);
1481 CMD(join_mesh, JOIN_MESH);
1482 CMD(set_pmksa, SET_PMKSA);
1483 CMD(del_pmksa, DEL_PMKSA);
1484 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001485 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001486 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1487 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1488 CMD(mgmt_tx, FRAME);
1489 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001490 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001491 i++;
1492 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1493 goto nla_put_failure;
1494 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001495 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1496 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001497 i++;
1498 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1499 goto nla_put_failure;
1500 }
1501 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001503 CMD(tdls_mgmt, TDLS_MGMT);
1504 CMD(tdls_oper, TDLS_OPER);
1505 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001506 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001507 CMD(sched_scan_start, START_SCHED_SCAN);
1508 CMD(probe_client, PROBE_CLIENT);
1509 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001510 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001511 i++;
1512 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1513 goto nla_put_failure;
1514 }
1515 CMD(start_p2p_device, START_P2P_DEVICE);
1516 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001517#ifdef CONFIG_NL80211_TESTMODE
1518 CMD(testmode_cmd, TESTMODE);
1519#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001520 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001521 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1522 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001523 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001524 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001525 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001526 if (rdev->wiphy.features &
1527 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001528 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001529 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001530 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001531#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001532
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001533 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001534 i++;
1535 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001536 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001537 }
1538
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001539 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001540 i++;
1541 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1542 goto nla_put_failure;
1543 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001544
Johannes Berg3713b4e2013-02-14 16:19:38 +01001545 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001546 state->split_start++;
1547 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001548 break;
1549 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001550 if (rdev->ops->remain_on_channel &&
1551 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 nla_put_u32(msg,
1553 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001554 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001555 goto nla_put_failure;
1556
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001557 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001558 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1559 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001560
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1562 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001563 state->split_start++;
1564 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 break;
1566 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001567#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001568 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001569 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#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001574 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001575#endif
1576 case 7:
1577 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001578 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001579 goto nla_put_failure;
1580
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001581 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001582 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001583 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001584
Johannes Berg86e8cf92013-06-19 10:57:22 +02001585 state->split_start++;
1586 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001587 break;
1588 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001589 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001591 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 goto nla_put_failure;
1593
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001594 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001595 /*
1596 * We can only add the per-channel limit information if the
1597 * dump is split, otherwise it makes it too big. Therefore
1598 * only advertise it in that case.
1599 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001600 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001601 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1602 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001603 goto nla_put_failure;
1604
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001605 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001606 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001607 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1608 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001609 goto nla_put_failure;
1610
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001611 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1612 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 goto nla_put_failure;
1616
1617 /*
1618 * Any information below this point is only available to
1619 * applications that can deal with it being split. This
1620 * helps ensure that newly added capabilities don't break
1621 * older tools by overrunning their buffers.
1622 *
1623 * We still increment split_start so that in the split
1624 * case we'll continue with more data in the next round,
1625 * but break unconditionally so unsplit data stops here.
1626 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001627 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001628 break;
1629 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001630 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001631 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001632 rdev->wiphy.extended_capabilities_len,
1633 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001634 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001635 rdev->wiphy.extended_capabilities_len,
1636 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001637 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001638
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001640 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001641 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1642 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001643 goto nla_put_failure;
1644
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001645 state->split_start++;
1646 break;
1647 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001648 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001649 goto nla_put_failure;
1650
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001651 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001652 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1653 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1654 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001655
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001656 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001657 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001658 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001659 goto nla_put_failure;
1660
Johannes Bergad7e7182013-11-13 13:37:47 +01001661 state->split_start++;
1662 break;
1663 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001664 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001665 const struct nl80211_vendor_cmd_info *info;
1666 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001667
Johannes Berg567ffc32013-12-18 14:43:31 +01001668 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1669 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001670 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001671
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001672 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1673 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001674 if (nla_put(msg, i + 1, sizeof(*info), info))
1675 goto nla_put_failure;
1676 }
1677 nla_nest_end(msg, nested);
1678 }
1679
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001680 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001681 const struct nl80211_vendor_cmd_info *info;
1682 struct nlattr *nested;
1683
1684 nested = nla_nest_start(msg,
1685 NL80211_ATTR_VENDOR_EVENTS);
1686 if (!nested)
1687 goto nla_put_failure;
1688
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001689 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1690 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001691 if (nla_put(msg, i + 1, sizeof(*info), info))
1692 goto nla_put_failure;
1693 }
1694 nla_nest_end(msg, nested);
1695 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001696 state->split_start++;
1697 break;
1698 case 12:
1699 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1700 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1701 rdev->wiphy.max_num_csa_counters))
1702 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001703
Johannes Berg3713b4e2013-02-14 16:19:38 +01001704 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001705 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001706 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001707 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001708 finish:
Johannes Berg55682962007-09-20 13:09:35 -04001709 return genlmsg_end(msg, hdr);
1710
1711 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001712 genlmsg_cancel(msg, hdr);
1713 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001714}
1715
Johannes Berg86e8cf92013-06-19 10:57:22 +02001716static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1717 struct netlink_callback *cb,
1718 struct nl80211_dump_wiphy_state *state)
1719{
1720 struct nlattr **tb = nl80211_fam.attrbuf;
1721 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1722 tb, nl80211_fam.maxattr, nl80211_policy);
1723 /* ignore parse errors for backward compatibility */
1724 if (ret)
1725 return 0;
1726
1727 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1728 if (tb[NL80211_ATTR_WIPHY])
1729 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1730 if (tb[NL80211_ATTR_WDEV])
1731 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1732 if (tb[NL80211_ATTR_IFINDEX]) {
1733 struct net_device *netdev;
1734 struct cfg80211_registered_device *rdev;
1735 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1736
Ying Xue7f2b8562014-01-15 10:23:45 +08001737 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001738 if (!netdev)
1739 return -ENODEV;
1740 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001741 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001742 netdev->ieee80211_ptr->wiphy);
1743 state->filter_wiphy = rdev->wiphy_idx;
1744 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001745 }
1746
1747 return 0;
1748}
1749
Johannes Berg55682962007-09-20 13:09:35 -04001750static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1751{
Johannes Berg645e77d2013-03-01 14:03:49 +01001752 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001753 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001754 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001755
Johannes Berg5fe231e2013-05-08 21:45:15 +02001756 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001757 if (!state) {
1758 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001759 if (!state) {
1760 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001761 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001762 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001763 state->filter_wiphy = -1;
1764 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1765 if (ret) {
1766 kfree(state);
1767 rtnl_unlock();
1768 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001769 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001770 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001771 }
1772
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001773 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1774 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001775 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001776 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001777 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001779 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001780 continue;
1781 /* attempt to fit multiple wiphy data chunks into the skb */
1782 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001783 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1784 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001785 NETLINK_CB(cb->skb).portid,
1786 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001787 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 if (ret < 0) {
1789 /*
1790 * If sending the wiphy data didn't fit (ENOBUFS
1791 * or EMSGSIZE returned), this SKB is still
1792 * empty (so it's not too big because another
1793 * wiphy dataset is already in the skb) and
1794 * we've not tried to adjust the dump allocation
1795 * yet ... then adjust the alloc size to be
1796 * bigger, and return 1 but with the empty skb.
1797 * This results in an empty message being RX'ed
1798 * in userspace, but that is ignored.
1799 *
1800 * We can then retry with the larger buffer.
1801 */
1802 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001803 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001804 cb->min_dump_alloc < 4096) {
1805 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001806 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001807 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001808 return 1;
1809 }
1810 idx--;
1811 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001812 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001813 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001814 break;
Johannes Berg55682962007-09-20 13:09:35 -04001815 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001816 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001817
Johannes Berg86e8cf92013-06-19 10:57:22 +02001818 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001819
1820 return skb->len;
1821}
1822
Johannes Berg86e8cf92013-06-19 10:57:22 +02001823static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1824{
1825 kfree((void *)cb->args[0]);
1826 return 0;
1827}
1828
Johannes Berg55682962007-09-20 13:09:35 -04001829static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1830{
1831 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001833 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001834
Johannes Berg645e77d2013-03-01 14:03:49 +01001835 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001836 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001837 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001838
Johannes Berg3bb20552014-05-26 13:52:25 +02001839 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1840 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001841 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001842 nlmsg_free(msg);
1843 return -ENOBUFS;
1844 }
Johannes Berg55682962007-09-20 13:09:35 -04001845
Johannes Berg134e6372009-07-10 09:51:34 +00001846 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001847}
1848
Jouni Malinen31888482008-10-30 16:59:24 +02001849static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1850 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1851 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1852 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1853 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1854 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1855};
1856
1857static int parse_txq_params(struct nlattr *tb[],
1858 struct ieee80211_txq_params *txq_params)
1859{
Johannes Berga3304b02012-03-28 11:04:24 +02001860 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001861 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1862 !tb[NL80211_TXQ_ATTR_AIFS])
1863 return -EINVAL;
1864
Johannes Berga3304b02012-03-28 11:04:24 +02001865 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001866 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1867 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1868 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1869 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1870
Johannes Berga3304b02012-03-28 11:04:24 +02001871 if (txq_params->ac >= NL80211_NUM_ACS)
1872 return -EINVAL;
1873
Jouni Malinen31888482008-10-30 16:59:24 +02001874 return 0;
1875}
1876
Johannes Bergf444de02010-05-05 15:25:02 +02001877static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1878{
1879 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001880 * You can only set the channel explicitly for WDS interfaces,
1881 * all others have their channel managed via their respective
1882 * "establish a connection" command (connect, join, ...)
1883 *
1884 * For AP/GO and mesh mode, the channel can be set with the
1885 * channel userspace API, but is only stored and passed to the
1886 * low-level driver when the AP starts or the mesh is joined.
1887 * This is for backward compatibility, userspace can also give
1888 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001889 *
1890 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001891 * whatever else is going on, so they have their own special
1892 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001893 */
1894 return !wdev ||
1895 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001896 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001897 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1898 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001899}
1900
Johannes Berg683b6d32012-11-08 21:25:48 +01001901static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1902 struct genl_info *info,
1903 struct cfg80211_chan_def *chandef)
1904{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301905 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001906
1907 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1908 return -EINVAL;
1909
1910 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1911
1912 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001913 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1914 chandef->center_freq1 = control_freq;
1915 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001916
1917 /* Primary channel not allowed */
1918 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1919 return -EINVAL;
1920
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001921 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1922 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001923
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001924 chantype = nla_get_u32(
1925 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1926
1927 switch (chantype) {
1928 case NL80211_CHAN_NO_HT:
1929 case NL80211_CHAN_HT20:
1930 case NL80211_CHAN_HT40PLUS:
1931 case NL80211_CHAN_HT40MINUS:
1932 cfg80211_chandef_create(chandef, chandef->chan,
1933 chantype);
1934 break;
1935 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001936 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001937 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1939 chandef->width =
1940 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1941 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1942 chandef->center_freq1 =
1943 nla_get_u32(
1944 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1945 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1946 chandef->center_freq2 =
1947 nla_get_u32(
1948 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1949 }
1950
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001951 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001952 return -EINVAL;
1953
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001954 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1955 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001956 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001957
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001958 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1959 chandef->width == NL80211_CHAN_WIDTH_10) &&
1960 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1961 return -EINVAL;
1962
Johannes Berg683b6d32012-11-08 21:25:48 +01001963 return 0;
1964}
1965
Johannes Bergf444de02010-05-05 15:25:02 +02001966static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001967 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001968 struct genl_info *info)
1969{
Johannes Berg683b6d32012-11-08 21:25:48 +01001970 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001971 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001972 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001973 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001974
Jouni Malinene16821b2014-04-28 11:22:08 +03001975 if (dev)
1976 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001977 if (!nl80211_can_set_dev_channel(wdev))
1978 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001979 if (wdev)
1980 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001981
Johannes Berg683b6d32012-11-08 21:25:48 +01001982 result = nl80211_parse_chandef(rdev, info, &chandef);
1983 if (result)
1984 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02001985
Johannes Berge8c9bd52012-06-06 08:18:22 +02001986 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001987 case NL80211_IFTYPE_AP:
1988 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02001989 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02001990 result = -EINVAL;
1991 break;
1992 }
Jouni Malinene16821b2014-04-28 11:22:08 +03001993 if (wdev->beacon_interval) {
1994 if (!dev || !rdev->ops->set_ap_chanwidth ||
1995 !(rdev->wiphy.features &
1996 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
1997 result = -EBUSY;
1998 break;
1999 }
2000
2001 /* Only allow dynamic channel width changes */
2002 if (chandef.chan != wdev->preset_chandef.chan) {
2003 result = -EBUSY;
2004 break;
2005 }
2006 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2007 if (result)
2008 break;
2009 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002010 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002011 result = 0;
2012 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002013 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002014 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002015 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002016 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002017 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002018 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002019 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002020 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002021 }
Johannes Bergf444de02010-05-05 15:25:02 +02002022
2023 return result;
2024}
2025
2026static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2027{
Johannes Berg4c476992010-10-04 21:36:35 +02002028 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2029 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002030
Jouni Malinene16821b2014-04-28 11:22:08 +03002031 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002032}
2033
Bill Jordane8347eb2010-10-01 13:54:28 -04002034static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2035{
Johannes Berg43b19952010-10-07 13:10:30 +02002036 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2037 struct net_device *dev = info->user_ptr[1];
2038 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002039 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002040
2041 if (!info->attrs[NL80211_ATTR_MAC])
2042 return -EINVAL;
2043
Johannes Berg43b19952010-10-07 13:10:30 +02002044 if (netif_running(dev))
2045 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002046
Johannes Berg43b19952010-10-07 13:10:30 +02002047 if (!rdev->ops->set_wds_peer)
2048 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002049
Johannes Berg43b19952010-10-07 13:10:30 +02002050 if (wdev->iftype != NL80211_IFTYPE_WDS)
2051 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002052
2053 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002054 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002055}
2056
2057
Johannes Berg55682962007-09-20 13:09:35 -04002058static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2059{
2060 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002061 struct net_device *netdev = NULL;
2062 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002063 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002064 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002065 u32 changed;
2066 u8 retry_short = 0, retry_long = 0;
2067 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002068 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002069
Johannes Berg5fe231e2013-05-08 21:45:15 +02002070 ASSERT_RTNL();
2071
Johannes Bergf444de02010-05-05 15:25:02 +02002072 /*
2073 * Try to find the wiphy and netdev. Normally this
2074 * function shouldn't need the netdev, but this is
2075 * done for backward compatibility -- previously
2076 * setting the channel was done per wiphy, but now
2077 * it is per netdev. Previous userland like hostapd
2078 * also passed a netdev to set_wiphy, so that it is
2079 * possible to let that go to the right netdev!
2080 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002081
Johannes Bergf444de02010-05-05 15:25:02 +02002082 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2083 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2084
Ying Xue7f2b8562014-01-15 10:23:45 +08002085 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002086 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002087 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002088 else
Johannes Bergf444de02010-05-05 15:25:02 +02002089 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002090 }
2091
Johannes Bergf444de02010-05-05 15:25:02 +02002092 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002093 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2094 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002095 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002096 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002097 wdev = NULL;
2098 netdev = NULL;
2099 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002100 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002101 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002102
2103 /*
2104 * end workaround code, by now the rdev is available
2105 * and locked, and wdev may or may not be NULL.
2106 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002107
2108 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002109 result = cfg80211_dev_rename(
2110 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002111
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002112 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002113 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002114
Jouni Malinen31888482008-10-30 16:59:24 +02002115 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2116 struct ieee80211_txq_params txq_params;
2117 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2118
Ying Xue7f2b8562014-01-15 10:23:45 +08002119 if (!rdev->ops->set_txq_params)
2120 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002121
Ying Xue7f2b8562014-01-15 10:23:45 +08002122 if (!netdev)
2123 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002124
Johannes Berg133a3ff2011-11-03 14:50:13 +01002125 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002126 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2127 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002128
Ying Xue7f2b8562014-01-15 10:23:45 +08002129 if (!netif_running(netdev))
2130 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002131
Jouni Malinen31888482008-10-30 16:59:24 +02002132 nla_for_each_nested(nl_txq_params,
2133 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2134 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002135 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2136 nla_data(nl_txq_params),
2137 nla_len(nl_txq_params),
2138 txq_params_policy);
2139 if (result)
2140 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002141 result = parse_txq_params(tb, &txq_params);
2142 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002143 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002144
Hila Gonene35e4d22012-06-27 17:19:42 +03002145 result = rdev_set_txq_params(rdev, netdev,
2146 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002147 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002148 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002149 }
2150 }
2151
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002152 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002153 result = __nl80211_set_channel(
2154 rdev,
2155 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2156 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002157 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002158 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002159 }
2160
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002161 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002162 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002163 enum nl80211_tx_power_setting type;
2164 int idx, mbm = 0;
2165
Johannes Bergc8442112012-10-24 10:17:18 +02002166 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2167 txp_wdev = NULL;
2168
Ying Xue7f2b8562014-01-15 10:23:45 +08002169 if (!rdev->ops->set_tx_power)
2170 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002171
2172 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2173 type = nla_get_u32(info->attrs[idx]);
2174
2175 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002176 (type != NL80211_TX_POWER_AUTOMATIC))
2177 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002178
2179 if (type != NL80211_TX_POWER_AUTOMATIC) {
2180 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2181 mbm = nla_get_u32(info->attrs[idx]);
2182 }
2183
Johannes Bergc8442112012-10-24 10:17:18 +02002184 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002185 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002186 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002187 }
2188
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002189 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2190 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2191 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002192 if ((!rdev->wiphy.available_antennas_tx &&
2193 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 !rdev->ops->set_antenna)
2195 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002196
2197 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2198 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2199
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002200 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002201 * available antenna masks, except for the "all" mask */
2202 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002203 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2204 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002205
Bruno Randolf7f531e02010-12-16 11:30:22 +09002206 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2207 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002208
Hila Gonene35e4d22012-06-27 17:19:42 +03002209 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002210 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002211 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002212 }
2213
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002214 changed = 0;
2215
2216 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2217 retry_short = nla_get_u8(
2218 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002219 if (retry_short == 0)
2220 return -EINVAL;
2221
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002222 changed |= WIPHY_PARAM_RETRY_SHORT;
2223 }
2224
2225 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2226 retry_long = nla_get_u8(
2227 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002228 if (retry_long == 0)
2229 return -EINVAL;
2230
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002231 changed |= WIPHY_PARAM_RETRY_LONG;
2232 }
2233
2234 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2235 frag_threshold = nla_get_u32(
2236 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002237 if (frag_threshold < 256)
2238 return -EINVAL;
2239
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002240 if (frag_threshold != (u32) -1) {
2241 /*
2242 * Fragments (apart from the last one) are required to
2243 * have even length. Make the fragmentation code
2244 * simpler by stripping LSB should someone try to use
2245 * odd threshold value.
2246 */
2247 frag_threshold &= ~0x1;
2248 }
2249 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2250 }
2251
2252 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2253 rts_threshold = nla_get_u32(
2254 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2255 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2256 }
2257
Lukáš Turek81077e82009-12-21 22:50:47 +01002258 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002259 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2260 return -EINVAL;
2261
Lukáš Turek81077e82009-12-21 22:50:47 +01002262 coverage_class = nla_get_u8(
2263 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2264 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2265 }
2266
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002267 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2268 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2269 return -EOPNOTSUPP;
2270
2271 changed |= WIPHY_PARAM_DYN_ACK;
2272 }
2273
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002274 if (changed) {
2275 u8 old_retry_short, old_retry_long;
2276 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002277 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002278
Ying Xue7f2b8562014-01-15 10:23:45 +08002279 if (!rdev->ops->set_wiphy_params)
2280 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002281
2282 old_retry_short = rdev->wiphy.retry_short;
2283 old_retry_long = rdev->wiphy.retry_long;
2284 old_frag_threshold = rdev->wiphy.frag_threshold;
2285 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002286 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002287
2288 if (changed & WIPHY_PARAM_RETRY_SHORT)
2289 rdev->wiphy.retry_short = retry_short;
2290 if (changed & WIPHY_PARAM_RETRY_LONG)
2291 rdev->wiphy.retry_long = retry_long;
2292 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2293 rdev->wiphy.frag_threshold = frag_threshold;
2294 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2295 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002296 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2297 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002298
Hila Gonene35e4d22012-06-27 17:19:42 +03002299 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002300 if (result) {
2301 rdev->wiphy.retry_short = old_retry_short;
2302 rdev->wiphy.retry_long = old_retry_long;
2303 rdev->wiphy.frag_threshold = old_frag_threshold;
2304 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002305 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002306 }
2307 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002308 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002309}
2310
Johannes Berg71bbc992012-06-15 15:30:18 +02002311static inline u64 wdev_id(struct wireless_dev *wdev)
2312{
2313 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002314 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002315}
Johannes Berg55682962007-09-20 13:09:35 -04002316
Johannes Berg683b6d32012-11-08 21:25:48 +01002317static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002318 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002319{
Johannes Berg9f5e8f62012-11-22 16:59:45 +01002320 WARN_ON(!cfg80211_chandef_valid(chandef));
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002321
Johannes Berg683b6d32012-11-08 21:25:48 +01002322 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2323 chandef->chan->center_freq))
2324 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002325 switch (chandef->width) {
2326 case NL80211_CHAN_WIDTH_20_NOHT:
2327 case NL80211_CHAN_WIDTH_20:
2328 case NL80211_CHAN_WIDTH_40:
2329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2330 cfg80211_get_chandef_type(chandef)))
2331 return -ENOBUFS;
2332 break;
2333 default:
2334 break;
2335 }
2336 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2337 return -ENOBUFS;
2338 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2339 return -ENOBUFS;
2340 if (chandef->center_freq2 &&
2341 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002342 return -ENOBUFS;
2343 return 0;
2344}
2345
Eric W. Biederman15e47302012-09-07 20:12:54 +00002346static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002347 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002348 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002349{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002350 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002351 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002352 void *hdr;
2353
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002354 if (removal)
2355 cmd = NL80211_CMD_DEL_INTERFACE;
2356
2357 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002358 if (!hdr)
2359 return -1;
2360
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002361 if (dev &&
2362 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002363 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002364 goto nla_put_failure;
2365
2366 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2367 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002368 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002369 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002370 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2371 rdev->devlist_generation ^
2372 (cfg80211_rdev_list_generation << 2)))
2373 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002374
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002375 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002376 int ret;
2377 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002378
Johannes Berg683b6d32012-11-08 21:25:48 +01002379 ret = rdev_get_channel(rdev, wdev, &chandef);
2380 if (ret == 0) {
2381 if (nl80211_send_chandef(msg, &chandef))
2382 goto nla_put_failure;
2383 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002384 }
2385
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002386 if (wdev->ssid_len) {
2387 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2388 goto nla_put_failure;
2389 }
2390
Johannes Berg55682962007-09-20 13:09:35 -04002391 return genlmsg_end(msg, hdr);
2392
2393 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002394 genlmsg_cancel(msg, hdr);
2395 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002396}
2397
2398static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2399{
2400 int wp_idx = 0;
2401 int if_idx = 0;
2402 int wp_start = cb->args[0];
2403 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002404 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002405 struct wireless_dev *wdev;
2406
Johannes Berg5fe231e2013-05-08 21:45:15 +02002407 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002408 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2409 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002410 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002411 if (wp_idx < wp_start) {
2412 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002413 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002414 }
Johannes Berg55682962007-09-20 13:09:35 -04002415 if_idx = 0;
2416
Johannes Berg89a54e42012-06-15 14:33:17 +02002417 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002418 if (if_idx < if_start) {
2419 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002420 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002421 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002422 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002423 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002424 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002425 goto out;
2426 }
2427 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002428 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002429
2430 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002431 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002432 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002433 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002434
2435 cb->args[0] = wp_idx;
2436 cb->args[1] = if_idx;
2437
2438 return skb->len;
2439}
2440
2441static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2442{
2443 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002445 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002446
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002447 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002448 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002449 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002450
Eric W. Biederman15e47302012-09-07 20:12:54 +00002451 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002452 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002453 nlmsg_free(msg);
2454 return -ENOBUFS;
2455 }
Johannes Berg55682962007-09-20 13:09:35 -04002456
Johannes Berg134e6372009-07-10 09:51:34 +00002457 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002458}
2459
Michael Wu66f7ac52008-01-31 19:48:22 +01002460static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2461 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2462 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2463 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2464 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2465 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002466 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002467};
2468
2469static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2470{
2471 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2472 int flag;
2473
2474 *mntrflags = 0;
2475
2476 if (!nla)
2477 return -EINVAL;
2478
2479 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2480 nla, mntr_flags_policy))
2481 return -EINVAL;
2482
2483 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2484 if (flags[flag])
2485 *mntrflags |= (1<<flag);
2486
2487 return 0;
2488}
2489
Johannes Berg9bc383d2009-11-19 11:55:19 +01002490static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002491 struct net_device *netdev, u8 use_4addr,
2492 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002493{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002494 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002495 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002496 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002497 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002498 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002499
2500 switch (iftype) {
2501 case NL80211_IFTYPE_AP_VLAN:
2502 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2503 return 0;
2504 break;
2505 case NL80211_IFTYPE_STATION:
2506 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2507 return 0;
2508 break;
2509 default:
2510 break;
2511 }
2512
2513 return -EOPNOTSUPP;
2514}
2515
Johannes Berg55682962007-09-20 13:09:35 -04002516static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2517{
Johannes Berg4c476992010-10-04 21:36:35 +02002518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002519 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002520 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002521 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002522 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002523 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002524 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002525
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002526 memset(&params, 0, sizeof(params));
2527
Johannes Berg04a773a2009-04-19 21:24:32 +02002528 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002529
Johannes Berg723b0382008-09-16 20:22:09 +02002530 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002531 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002532 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002533 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002534 if (ntype > NL80211_IFTYPE_MAX)
2535 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002536 }
2537
Johannes Berg92ffe052008-09-16 20:39:36 +02002538 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002539 struct wireless_dev *wdev = dev->ieee80211_ptr;
2540
Johannes Berg4c476992010-10-04 21:36:35 +02002541 if (ntype != NL80211_IFTYPE_MESH_POINT)
2542 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002543 if (netif_running(dev))
2544 return -EBUSY;
2545
2546 wdev_lock(wdev);
2547 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2548 IEEE80211_MAX_MESH_ID_LEN);
2549 wdev->mesh_id_up_len =
2550 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2551 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2552 wdev->mesh_id_up_len);
2553 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002554 }
2555
Felix Fietkau8b787642009-11-10 18:53:10 +01002556 if (info->attrs[NL80211_ATTR_4ADDR]) {
2557 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2558 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002559 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002560 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002561 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002562 } else {
2563 params.use_4addr = -1;
2564 }
2565
Johannes Berg92ffe052008-09-16 20:39:36 +02002566 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002567 if (ntype != NL80211_IFTYPE_MONITOR)
2568 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002569 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2570 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002571 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002572 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002573
2574 flags = &_flags;
2575 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002576 }
Johannes Berg3b858752009-03-12 09:55:09 +01002577
Luciano Coelho18003292013-08-29 13:26:57 +03002578 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002579 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2580 return -EOPNOTSUPP;
2581
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002582 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002583 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002584 else
2585 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002586
Johannes Berg9bc383d2009-11-19 11:55:19 +01002587 if (!err && params.use_4addr != -1)
2588 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2589
Johannes Berg55682962007-09-20 13:09:35 -04002590 return err;
2591}
2592
2593static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2594{
Johannes Berg4c476992010-10-04 21:36:35 +02002595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002596 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002597 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002598 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002599 int err;
2600 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002601 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002602
Johannes Berg78f22b62014-03-24 17:57:27 +01002603 /* to avoid failing a new interface creation due to pending removal */
2604 cfg80211_destroy_ifaces(rdev);
2605
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002606 memset(&params, 0, sizeof(params));
2607
Johannes Berg55682962007-09-20 13:09:35 -04002608 if (!info->attrs[NL80211_ATTR_IFNAME])
2609 return -EINVAL;
2610
2611 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2612 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2613 if (type > NL80211_IFTYPE_MAX)
2614 return -EINVAL;
2615 }
2616
Johannes Berg79c97e92009-07-07 03:56:12 +02002617 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002618 !(rdev->wiphy.interface_modes & (1 << type)))
2619 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002620
Ben Greeare8f479b2014-10-22 12:23:05 -07002621 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2622 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2623 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002624 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2625 ETH_ALEN);
2626 if (!is_valid_ether_addr(params.macaddr))
2627 return -EADDRNOTAVAIL;
2628 }
2629
Johannes Berg9bc383d2009-11-19 11:55:19 +01002630 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002631 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002632 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002633 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002634 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002635 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002636
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002637 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2638 if (!msg)
2639 return -ENOMEM;
2640
Michael Wu66f7ac52008-01-31 19:48:22 +01002641 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2642 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2643 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002644
Luciano Coelho18003292013-08-29 13:26:57 +03002645 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002646 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2647 return -EOPNOTSUPP;
2648
Hila Gonene35e4d22012-06-27 17:19:42 +03002649 wdev = rdev_add_virtual_intf(rdev,
2650 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2651 type, err ? NULL : &flags, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002652 if (WARN_ON(!wdev)) {
2653 nlmsg_free(msg);
2654 return -EPROTO;
2655 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002656 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002657 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002658 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002659
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002660 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002661 wdev->owner_nlportid = info->snd_portid;
2662
Johannes Berg98104fde2012-06-16 00:19:54 +02002663 switch (type) {
2664 case NL80211_IFTYPE_MESH_POINT:
2665 if (!info->attrs[NL80211_ATTR_MESH_ID])
2666 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002667 wdev_lock(wdev);
2668 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2669 IEEE80211_MAX_MESH_ID_LEN);
2670 wdev->mesh_id_up_len =
2671 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2672 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2673 wdev->mesh_id_up_len);
2674 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002675 break;
2676 case NL80211_IFTYPE_P2P_DEVICE:
2677 /*
2678 * P2P Device doesn't have a netdev, so doesn't go
2679 * through the netdev notifier and must be added here
2680 */
2681 mutex_init(&wdev->mtx);
2682 INIT_LIST_HEAD(&wdev->event_list);
2683 spin_lock_init(&wdev->event_lock);
2684 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2685 spin_lock_init(&wdev->mgmt_registrations_lock);
2686
Johannes Berg98104fde2012-06-16 00:19:54 +02002687 wdev->identifier = ++rdev->wdev_id;
2688 list_add_rcu(&wdev->list, &rdev->wdev_list);
2689 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002690 break;
2691 default:
2692 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002693 }
2694
Eric W. Biederman15e47302012-09-07 20:12:54 +00002695 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002696 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002697 nlmsg_free(msg);
2698 return -ENOBUFS;
2699 }
2700
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002701 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2702 if (event) {
2703 if (nl80211_send_iface(event, 0, 0, 0,
2704 rdev, wdev, false) < 0) {
2705 nlmsg_free(event);
2706 goto out;
2707 }
2708
2709 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2710 event, 0, NL80211_MCGRP_CONFIG,
2711 GFP_KERNEL);
2712 }
2713
2714out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002715 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002716}
2717
2718static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2719{
Johannes Berg4c476992010-10-04 21:36:35 +02002720 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002721 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002722 struct sk_buff *msg;
2723 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002724
Johannes Berg4c476992010-10-04 21:36:35 +02002725 if (!rdev->ops->del_virtual_intf)
2726 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002727
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002728 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2729 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2730 nlmsg_free(msg);
2731 msg = NULL;
2732 }
2733
Johannes Berg84efbb82012-06-16 00:00:26 +02002734 /*
2735 * If we remove a wireless device without a netdev then clear
2736 * user_ptr[1] so that nl80211_post_doit won't dereference it
2737 * to check if it needs to do dev_put(). Otherwise it crashes
2738 * since the wdev has been freed, unlike with a netdev where
2739 * we need the dev_put() for the netdev to really be freed.
2740 */
2741 if (!wdev->netdev)
2742 info->user_ptr[1] = NULL;
2743
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002744 status = rdev_del_virtual_intf(rdev, wdev);
2745 if (status >= 0 && msg)
2746 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2747 msg, 0, NL80211_MCGRP_CONFIG,
2748 GFP_KERNEL);
2749 else
2750 nlmsg_free(msg);
2751
2752 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002753}
2754
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002755static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2756{
2757 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2758 struct net_device *dev = info->user_ptr[1];
2759 u16 noack_map;
2760
2761 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2762 return -EINVAL;
2763
2764 if (!rdev->ops->set_noack_map)
2765 return -EOPNOTSUPP;
2766
2767 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2768
Hila Gonene35e4d22012-06-27 17:19:42 +03002769 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002770}
2771
Johannes Berg41ade002007-12-19 02:03:29 +01002772struct get_key_cookie {
2773 struct sk_buff *msg;
2774 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002775 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002776};
2777
2778static void get_key_callback(void *c, struct key_params *params)
2779{
Johannes Bergb9454e82009-07-08 13:29:08 +02002780 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002781 struct get_key_cookie *cookie = c;
2782
David S. Miller9360ffd2012-03-29 04:41:26 -04002783 if ((params->key &&
2784 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2785 params->key_len, params->key)) ||
2786 (params->seq &&
2787 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2788 params->seq_len, params->seq)) ||
2789 (params->cipher &&
2790 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2791 params->cipher)))
2792 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002793
Johannes Bergb9454e82009-07-08 13:29:08 +02002794 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2795 if (!key)
2796 goto nla_put_failure;
2797
David S. Miller9360ffd2012-03-29 04:41:26 -04002798 if ((params->key &&
2799 nla_put(cookie->msg, NL80211_KEY_DATA,
2800 params->key_len, params->key)) ||
2801 (params->seq &&
2802 nla_put(cookie->msg, NL80211_KEY_SEQ,
2803 params->seq_len, params->seq)) ||
2804 (params->cipher &&
2805 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2806 params->cipher)))
2807 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002808
David S. Miller9360ffd2012-03-29 04:41:26 -04002809 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2810 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002811
2812 nla_nest_end(cookie->msg, key);
2813
Johannes Berg41ade002007-12-19 02:03:29 +01002814 return;
2815 nla_put_failure:
2816 cookie->error = 1;
2817}
2818
2819static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2820{
Johannes Berg4c476992010-10-04 21:36:35 +02002821 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002822 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002823 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002824 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002825 const u8 *mac_addr = NULL;
2826 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002827 struct get_key_cookie cookie = {
2828 .error = 0,
2829 };
2830 void *hdr;
2831 struct sk_buff *msg;
2832
2833 if (info->attrs[NL80211_ATTR_KEY_IDX])
2834 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2835
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002836 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002837 return -EINVAL;
2838
2839 if (info->attrs[NL80211_ATTR_MAC])
2840 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2841
Johannes Berge31b8212010-10-05 19:39:30 +02002842 pairwise = !!mac_addr;
2843 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2844 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2845 if (kt >= NUM_NL80211_KEYTYPES)
2846 return -EINVAL;
2847 if (kt != NL80211_KEYTYPE_GROUP &&
2848 kt != NL80211_KEYTYPE_PAIRWISE)
2849 return -EINVAL;
2850 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2851 }
2852
Johannes Berg4c476992010-10-04 21:36:35 +02002853 if (!rdev->ops->get_key)
2854 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002855
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002856 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002857 if (!msg)
2858 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002859
Eric W. Biederman15e47302012-09-07 20:12:54 +00002860 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002861 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002862 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002863 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002864
2865 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002866 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002867
David S. Miller9360ffd2012-03-29 04:41:26 -04002868 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2869 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2870 goto nla_put_failure;
2871 if (mac_addr &&
2872 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2873 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002874
Johannes Berge31b8212010-10-05 19:39:30 +02002875 if (pairwise && mac_addr &&
2876 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2877 return -ENOENT;
2878
Hila Gonene35e4d22012-06-27 17:19:42 +03002879 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2880 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002881
2882 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002883 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002884
2885 if (cookie.error)
2886 goto nla_put_failure;
2887
2888 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002889 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002890
2891 nla_put_failure:
2892 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002893 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002894 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002895 return err;
2896}
2897
2898static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2899{
Johannes Berg4c476992010-10-04 21:36:35 +02002900 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002901 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002902 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002903 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002904
Johannes Bergb9454e82009-07-08 13:29:08 +02002905 err = nl80211_parse_key(info, &key);
2906 if (err)
2907 return err;
2908
2909 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002910 return -EINVAL;
2911
Johannes Bergb9454e82009-07-08 13:29:08 +02002912 /* only support setting default key */
2913 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002914 return -EINVAL;
2915
Johannes Bergfffd0932009-07-08 14:22:54 +02002916 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002917
2918 if (key.def) {
2919 if (!rdev->ops->set_default_key) {
2920 err = -EOPNOTSUPP;
2921 goto out;
2922 }
2923
2924 err = nl80211_key_allowed(dev->ieee80211_ptr);
2925 if (err)
2926 goto out;
2927
Hila Gonene35e4d22012-06-27 17:19:42 +03002928 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002929 key.def_uni, key.def_multi);
2930
2931 if (err)
2932 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002933
Johannes Berg3d23e342009-09-29 23:27:28 +02002934#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002935 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002936#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002937 } else {
2938 if (key.def_uni || !key.def_multi) {
2939 err = -EINVAL;
2940 goto out;
2941 }
2942
2943 if (!rdev->ops->set_default_mgmt_key) {
2944 err = -EOPNOTSUPP;
2945 goto out;
2946 }
2947
2948 err = nl80211_key_allowed(dev->ieee80211_ptr);
2949 if (err)
2950 goto out;
2951
Hila Gonene35e4d22012-06-27 17:19:42 +03002952 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002953 if (err)
2954 goto out;
2955
2956#ifdef CONFIG_CFG80211_WEXT
2957 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2958#endif
2959 }
2960
2961 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002962 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002963
Johannes Berg41ade002007-12-19 02:03:29 +01002964 return err;
2965}
2966
2967static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2968{
Johannes Berg4c476992010-10-04 21:36:35 +02002969 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002970 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002971 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002972 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002973 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002974
Johannes Bergb9454e82009-07-08 13:29:08 +02002975 err = nl80211_parse_key(info, &key);
2976 if (err)
2977 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002978
Johannes Bergb9454e82009-07-08 13:29:08 +02002979 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01002980 return -EINVAL;
2981
Johannes Berg41ade002007-12-19 02:03:29 +01002982 if (info->attrs[NL80211_ATTR_MAC])
2983 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2984
Johannes Berge31b8212010-10-05 19:39:30 +02002985 if (key.type == -1) {
2986 if (mac_addr)
2987 key.type = NL80211_KEYTYPE_PAIRWISE;
2988 else
2989 key.type = NL80211_KEYTYPE_GROUP;
2990 }
2991
2992 /* for now */
2993 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
2994 key.type != NL80211_KEYTYPE_GROUP)
2995 return -EINVAL;
2996
Johannes Berg4c476992010-10-04 21:36:35 +02002997 if (!rdev->ops->add_key)
2998 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002999
Johannes Berge31b8212010-10-05 19:39:30 +02003000 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3001 key.type == NL80211_KEYTYPE_PAIRWISE,
3002 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003003 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003004
3005 wdev_lock(dev->ieee80211_ptr);
3006 err = nl80211_key_allowed(dev->ieee80211_ptr);
3007 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003008 err = rdev_add_key(rdev, dev, key.idx,
3009 key.type == NL80211_KEYTYPE_PAIRWISE,
3010 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003011 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003012
Johannes Berg41ade002007-12-19 02:03:29 +01003013 return err;
3014}
3015
3016static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3017{
Johannes Berg4c476992010-10-04 21:36:35 +02003018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003019 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003020 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003021 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003022 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003023
Johannes Bergb9454e82009-07-08 13:29:08 +02003024 err = nl80211_parse_key(info, &key);
3025 if (err)
3026 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003027
3028 if (info->attrs[NL80211_ATTR_MAC])
3029 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3030
Johannes Berge31b8212010-10-05 19:39:30 +02003031 if (key.type == -1) {
3032 if (mac_addr)
3033 key.type = NL80211_KEYTYPE_PAIRWISE;
3034 else
3035 key.type = NL80211_KEYTYPE_GROUP;
3036 }
3037
3038 /* for now */
3039 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3040 key.type != NL80211_KEYTYPE_GROUP)
3041 return -EINVAL;
3042
Johannes Berg4c476992010-10-04 21:36:35 +02003043 if (!rdev->ops->del_key)
3044 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003045
Johannes Bergfffd0932009-07-08 14:22:54 +02003046 wdev_lock(dev->ieee80211_ptr);
3047 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003048
3049 if (key.type == NL80211_KEYTYPE_PAIRWISE && mac_addr &&
3050 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3051 err = -ENOENT;
3052
Johannes Bergfffd0932009-07-08 14:22:54 +02003053 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003054 err = rdev_del_key(rdev, dev, key.idx,
3055 key.type == NL80211_KEYTYPE_PAIRWISE,
3056 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003057
Johannes Berg3d23e342009-09-29 23:27:28 +02003058#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003059 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003060 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003061 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003062 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003063 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3064 }
3065#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003066 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003067
Johannes Berg41ade002007-12-19 02:03:29 +01003068 return err;
3069}
3070
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303071/* This function returns an error or the number of nested attributes */
3072static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3073{
3074 struct nlattr *attr;
3075 int n_entries = 0, tmp;
3076
3077 nla_for_each_nested(attr, nl_attr, tmp) {
3078 if (nla_len(attr) != ETH_ALEN)
3079 return -EINVAL;
3080
3081 n_entries++;
3082 }
3083
3084 return n_entries;
3085}
3086
3087/*
3088 * This function parses ACL information and allocates memory for ACL data.
3089 * On successful return, the calling function is responsible to free the
3090 * ACL buffer returned by this function.
3091 */
3092static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3093 struct genl_info *info)
3094{
3095 enum nl80211_acl_policy acl_policy;
3096 struct nlattr *attr;
3097 struct cfg80211_acl_data *acl;
3098 int i = 0, n_entries, tmp;
3099
3100 if (!wiphy->max_acl_mac_addrs)
3101 return ERR_PTR(-EOPNOTSUPP);
3102
3103 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3104 return ERR_PTR(-EINVAL);
3105
3106 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3107 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3108 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3109 return ERR_PTR(-EINVAL);
3110
3111 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3112 return ERR_PTR(-EINVAL);
3113
3114 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3115 if (n_entries < 0)
3116 return ERR_PTR(n_entries);
3117
3118 if (n_entries > wiphy->max_acl_mac_addrs)
3119 return ERR_PTR(-ENOTSUPP);
3120
3121 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3122 GFP_KERNEL);
3123 if (!acl)
3124 return ERR_PTR(-ENOMEM);
3125
3126 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3127 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3128 i++;
3129 }
3130
3131 acl->n_acl_entries = n_entries;
3132 acl->acl_policy = acl_policy;
3133
3134 return acl;
3135}
3136
3137static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3138{
3139 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3140 struct net_device *dev = info->user_ptr[1];
3141 struct cfg80211_acl_data *acl;
3142 int err;
3143
3144 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3145 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3146 return -EOPNOTSUPP;
3147
3148 if (!dev->ieee80211_ptr->beacon_interval)
3149 return -EINVAL;
3150
3151 acl = parse_acl_data(&rdev->wiphy, info);
3152 if (IS_ERR(acl))
3153 return PTR_ERR(acl);
3154
3155 err = rdev_set_mac_acl(rdev, dev, acl);
3156
3157 kfree(acl);
3158
3159 return err;
3160}
3161
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003162static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003163 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003164{
Johannes Berg88600202012-02-13 15:17:18 +01003165 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003166
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003167 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3168 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3169 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3170 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003171 return -EINVAL;
3172
Johannes Berg88600202012-02-13 15:17:18 +01003173 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003174
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003175 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3176 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3177 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003178 if (!bcn->head_len)
3179 return -EINVAL;
3180 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003181 }
3182
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003183 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3184 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3185 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003186 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003187 }
3188
Johannes Berg4c476992010-10-04 21:36:35 +02003189 if (!haveinfo)
3190 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003191
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003192 if (attrs[NL80211_ATTR_IE]) {
3193 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3194 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003195 }
3196
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003197 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003198 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003199 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003200 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003201 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003202 }
3203
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003204 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003205 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003206 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003207 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003208 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003209 }
3210
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003211 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3212 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3213 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003214 }
3215
Johannes Berg88600202012-02-13 15:17:18 +01003216 return 0;
3217}
3218
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003219static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3220 struct cfg80211_ap_settings *params)
3221{
3222 struct wireless_dev *wdev;
3223 bool ret = false;
3224
Johannes Berg89a54e42012-06-15 14:33:17 +02003225 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003226 if (wdev->iftype != NL80211_IFTYPE_AP &&
3227 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3228 continue;
3229
Johannes Berg683b6d32012-11-08 21:25:48 +01003230 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003231 continue;
3232
Johannes Berg683b6d32012-11-08 21:25:48 +01003233 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003234 ret = true;
3235 break;
3236 }
3237
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003238 return ret;
3239}
3240
Jouni Malinene39e5b52012-09-30 19:29:39 +03003241static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3242 enum nl80211_auth_type auth_type,
3243 enum nl80211_commands cmd)
3244{
3245 if (auth_type > NL80211_AUTHTYPE_MAX)
3246 return false;
3247
3248 switch (cmd) {
3249 case NL80211_CMD_AUTHENTICATE:
3250 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3251 auth_type == NL80211_AUTHTYPE_SAE)
3252 return false;
3253 return true;
3254 case NL80211_CMD_CONNECT:
3255 case NL80211_CMD_START_AP:
3256 /* SAE not supported yet */
3257 if (auth_type == NL80211_AUTHTYPE_SAE)
3258 return false;
3259 return true;
3260 default:
3261 return false;
3262 }
3263}
3264
Johannes Berg88600202012-02-13 15:17:18 +01003265static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3266{
3267 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3268 struct net_device *dev = info->user_ptr[1];
3269 struct wireless_dev *wdev = dev->ieee80211_ptr;
3270 struct cfg80211_ap_settings params;
3271 int err;
3272
3273 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3274 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3275 return -EOPNOTSUPP;
3276
3277 if (!rdev->ops->start_ap)
3278 return -EOPNOTSUPP;
3279
3280 if (wdev->beacon_interval)
3281 return -EALREADY;
3282
3283 memset(&params, 0, sizeof(params));
3284
3285 /* these are required for START_AP */
3286 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3287 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3288 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3289 return -EINVAL;
3290
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003291 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003292 if (err)
3293 return err;
3294
3295 params.beacon_interval =
3296 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3297 params.dtim_period =
3298 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3299
3300 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3301 if (err)
3302 return err;
3303
3304 /*
3305 * In theory, some of these attributes should be required here
3306 * but since they were not used when the command was originally
3307 * added, keep them optional for old user space programs to let
3308 * them continue to work with drivers that do not need the
3309 * additional information -- drivers must check!
3310 */
3311 if (info->attrs[NL80211_ATTR_SSID]) {
3312 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3313 params.ssid_len =
3314 nla_len(info->attrs[NL80211_ATTR_SSID]);
3315 if (params.ssid_len == 0 ||
3316 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3317 return -EINVAL;
3318 }
3319
3320 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3321 params.hidden_ssid = nla_get_u32(
3322 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3323 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3324 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3325 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3326 return -EINVAL;
3327 }
3328
3329 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3330
3331 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3332 params.auth_type = nla_get_u32(
3333 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003334 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3335 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003336 return -EINVAL;
3337 } else
3338 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3339
3340 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3341 NL80211_MAX_NR_CIPHER_SUITES);
3342 if (err)
3343 return err;
3344
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303345 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3346 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3347 return -EOPNOTSUPP;
3348 params.inactivity_timeout = nla_get_u16(
3349 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3350 }
3351
Johannes Berg53cabad2012-11-14 15:17:28 +01003352 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3353 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3354 return -EINVAL;
3355 params.p2p_ctwindow =
3356 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3357 if (params.p2p_ctwindow > 127)
3358 return -EINVAL;
3359 if (params.p2p_ctwindow != 0 &&
3360 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3361 return -EINVAL;
3362 }
3363
3364 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3365 u8 tmp;
3366
3367 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3368 return -EINVAL;
3369 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3370 if (tmp > 1)
3371 return -EINVAL;
3372 params.p2p_opp_ps = tmp;
3373 if (params.p2p_opp_ps != 0 &&
3374 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3375 return -EINVAL;
3376 }
3377
Johannes Bergaa430da2012-05-16 23:50:18 +02003378 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003379 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3380 if (err)
3381 return err;
3382 } else if (wdev->preset_chandef.chan) {
3383 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003384 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003385 return -EINVAL;
3386
Ilan Peer174e0cd2014-02-23 09:13:01 +02003387 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3388 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003389 return -EINVAL;
3390
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303391 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3392 params.acl = parse_acl_data(&rdev->wiphy, info);
3393 if (IS_ERR(params.acl))
3394 return PTR_ERR(params.acl);
3395 }
3396
Eliad Peller18998c32014-09-10 14:07:34 +03003397 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3398 params.smps_mode =
3399 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3400 switch (params.smps_mode) {
3401 case NL80211_SMPS_OFF:
3402 break;
3403 case NL80211_SMPS_STATIC:
3404 if (!(rdev->wiphy.features &
3405 NL80211_FEATURE_STATIC_SMPS))
3406 return -EINVAL;
3407 break;
3408 case NL80211_SMPS_DYNAMIC:
3409 if (!(rdev->wiphy.features &
3410 NL80211_FEATURE_DYNAMIC_SMPS))
3411 return -EINVAL;
3412 break;
3413 default:
3414 return -EINVAL;
3415 }
3416 } else {
3417 params.smps_mode = NL80211_SMPS_OFF;
3418 }
3419
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003420 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003421 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003422 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003423 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003424 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003425 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003426 wdev->ssid_len = params.ssid_len;
3427 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003428 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003429 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303430
3431 kfree(params.acl);
3432
Johannes Berg56d18932011-05-09 18:41:15 +02003433 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003434}
3435
Johannes Berg88600202012-02-13 15:17:18 +01003436static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3437{
3438 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3439 struct net_device *dev = info->user_ptr[1];
3440 struct wireless_dev *wdev = dev->ieee80211_ptr;
3441 struct cfg80211_beacon_data params;
3442 int err;
3443
3444 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3445 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3446 return -EOPNOTSUPP;
3447
3448 if (!rdev->ops->change_beacon)
3449 return -EOPNOTSUPP;
3450
3451 if (!wdev->beacon_interval)
3452 return -EINVAL;
3453
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003454 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003455 if (err)
3456 return err;
3457
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003458 wdev_lock(wdev);
3459 err = rdev_change_beacon(rdev, dev, &params);
3460 wdev_unlock(wdev);
3461
3462 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003463}
3464
3465static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003466{
Johannes Berg4c476992010-10-04 21:36:35 +02003467 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3468 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003469
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003470 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003471}
3472
Johannes Berg5727ef12007-12-19 02:03:34 +01003473static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3474 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3475 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3476 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003477 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003478 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003479 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003480};
3481
Johannes Bergeccb8e82009-05-11 21:57:56 +03003482static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003483 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003484 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003485{
3486 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003487 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003488 int flag;
3489
Johannes Bergeccb8e82009-05-11 21:57:56 +03003490 /*
3491 * Try parsing the new attribute first so userspace
3492 * can specify both for older kernels.
3493 */
3494 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3495 if (nla) {
3496 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003497
Johannes Bergeccb8e82009-05-11 21:57:56 +03003498 sta_flags = nla_data(nla);
3499 params->sta_flags_mask = sta_flags->mask;
3500 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003501 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003502 if ((params->sta_flags_mask |
3503 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3504 return -EINVAL;
3505 return 0;
3506 }
3507
3508 /* if present, parse the old attribute */
3509
3510 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003511 if (!nla)
3512 return 0;
3513
3514 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3515 nla, sta_flags_policy))
3516 return -EINVAL;
3517
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003518 /*
3519 * Only allow certain flags for interface types so that
3520 * other attributes are silently ignored. Remember that
3521 * this is backward compatibility code with old userspace
3522 * and shouldn't be hit in other cases anyway.
3523 */
3524 switch (iftype) {
3525 case NL80211_IFTYPE_AP:
3526 case NL80211_IFTYPE_AP_VLAN:
3527 case NL80211_IFTYPE_P2P_GO:
3528 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3529 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3530 BIT(NL80211_STA_FLAG_WME) |
3531 BIT(NL80211_STA_FLAG_MFP);
3532 break;
3533 case NL80211_IFTYPE_P2P_CLIENT:
3534 case NL80211_IFTYPE_STATION:
3535 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3536 BIT(NL80211_STA_FLAG_TDLS_PEER);
3537 break;
3538 case NL80211_IFTYPE_MESH_POINT:
3539 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3540 BIT(NL80211_STA_FLAG_MFP) |
3541 BIT(NL80211_STA_FLAG_AUTHORIZED);
3542 default:
3543 return -EINVAL;
3544 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003545
Johannes Berg3383b5a2012-05-10 20:14:43 +02003546 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3547 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003548 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003549
Johannes Berg3383b5a2012-05-10 20:14:43 +02003550 /* no longer support new API additions in old API */
3551 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3552 return -EINVAL;
3553 }
3554 }
3555
Johannes Berg5727ef12007-12-19 02:03:34 +01003556 return 0;
3557}
3558
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003559static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3560 int attr)
3561{
3562 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003563 u32 bitrate;
3564 u16 bitrate_compat;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003565
3566 rate = nla_nest_start(msg, attr);
3567 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003568 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003569
3570 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3571 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003572 /* report 16-bit bitrate only if we can */
3573 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003574 if (bitrate > 0 &&
3575 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3576 return false;
3577 if (bitrate_compat > 0 &&
3578 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3579 return false;
3580
3581 if (info->flags & RATE_INFO_FLAGS_MCS) {
3582 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3583 return false;
3584 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3585 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3586 return false;
3587 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3588 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3589 return false;
3590 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3591 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3592 return false;
3593 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3594 return false;
3595 if (info->flags & RATE_INFO_FLAGS_40_MHZ_WIDTH &&
3596 nla_put_flag(msg, NL80211_RATE_INFO_40_MHZ_WIDTH))
3597 return false;
3598 if (info->flags & RATE_INFO_FLAGS_80_MHZ_WIDTH &&
3599 nla_put_flag(msg, NL80211_RATE_INFO_80_MHZ_WIDTH))
3600 return false;
3601 if (info->flags & RATE_INFO_FLAGS_80P80_MHZ_WIDTH &&
3602 nla_put_flag(msg, NL80211_RATE_INFO_80P80_MHZ_WIDTH))
3603 return false;
3604 if (info->flags & RATE_INFO_FLAGS_160_MHZ_WIDTH &&
3605 nla_put_flag(msg, NL80211_RATE_INFO_160_MHZ_WIDTH))
3606 return false;
3607 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3608 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3609 return false;
3610 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003611
3612 nla_nest_end(msg, rate);
3613 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003614}
3615
Felix Fietkau119363c2013-04-22 16:29:30 +02003616static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3617 int id)
3618{
3619 void *attr;
3620 int i = 0;
3621
3622 if (!mask)
3623 return true;
3624
3625 attr = nla_nest_start(msg, id);
3626 if (!attr)
3627 return false;
3628
3629 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3630 if (!(mask & BIT(i)))
3631 continue;
3632
3633 if (nla_put_u8(msg, i, signal[i]))
3634 return false;
3635 }
3636
3637 nla_nest_end(msg, attr);
3638
3639 return true;
3640}
3641
Eric W. Biederman15e47302012-09-07 20:12:54 +00003642static int nl80211_send_station(struct sk_buff *msg, u32 portid, u32 seq,
John W. Linville66266b32012-03-15 13:25:41 -04003643 int flags,
3644 struct cfg80211_registered_device *rdev,
3645 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003646 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003647{
3648 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003649 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003650
Eric W. Biederman15e47302012-09-07 20:12:54 +00003651 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_STATION);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003652 if (!hdr)
3653 return -1;
3654
David S. Miller9360ffd2012-03-29 04:41:26 -04003655 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3656 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3657 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3658 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003659
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003660 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3661 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003662 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003663 if ((sinfo->filled & STATION_INFO_CONNECTED_TIME) &&
3664 nla_put_u32(msg, NL80211_STA_INFO_CONNECTED_TIME,
3665 sinfo->connected_time))
3666 goto nla_put_failure;
3667 if ((sinfo->filled & STATION_INFO_INACTIVE_TIME) &&
3668 nla_put_u32(msg, NL80211_STA_INFO_INACTIVE_TIME,
3669 sinfo->inactive_time))
3670 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003671 if ((sinfo->filled & (STATION_INFO_RX_BYTES |
3672 STATION_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003673 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003674 (u32)sinfo->rx_bytes))
3675 goto nla_put_failure;
3676 if ((sinfo->filled & (STATION_INFO_TX_BYTES |
Felix Fietkau4325d722013-05-23 15:05:59 +02003677 STATION_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003678 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3679 (u32)sinfo->tx_bytes))
3680 goto nla_put_failure;
3681 if ((sinfo->filled & STATION_INFO_RX_BYTES64) &&
3682 nla_put_u64(msg, NL80211_STA_INFO_RX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003683 sinfo->rx_bytes))
3684 goto nla_put_failure;
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003685 if ((sinfo->filled & STATION_INFO_TX_BYTES64) &&
3686 nla_put_u64(msg, NL80211_STA_INFO_TX_BYTES64,
David S. Miller9360ffd2012-03-29 04:41:26 -04003687 sinfo->tx_bytes))
3688 goto nla_put_failure;
3689 if ((sinfo->filled & STATION_INFO_LLID) &&
3690 nla_put_u16(msg, NL80211_STA_INFO_LLID, sinfo->llid))
3691 goto nla_put_failure;
3692 if ((sinfo->filled & STATION_INFO_PLID) &&
3693 nla_put_u16(msg, NL80211_STA_INFO_PLID, sinfo->plid))
3694 goto nla_put_failure;
3695 if ((sinfo->filled & STATION_INFO_PLINK_STATE) &&
3696 nla_put_u8(msg, NL80211_STA_INFO_PLINK_STATE,
3697 sinfo->plink_state))
3698 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003699 switch (rdev->wiphy.signal_type) {
3700 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04003701 if ((sinfo->filled & STATION_INFO_SIGNAL) &&
3702 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL,
3703 sinfo->signal))
3704 goto nla_put_failure;
3705 if ((sinfo->filled & STATION_INFO_SIGNAL_AVG) &&
3706 nla_put_u8(msg, NL80211_STA_INFO_SIGNAL_AVG,
3707 sinfo->signal_avg))
3708 goto nla_put_failure;
John W. Linville66266b32012-03-15 13:25:41 -04003709 break;
3710 default:
3711 break;
3712 }
Felix Fietkau119363c2013-04-22 16:29:30 +02003713 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL) {
3714 if (!nl80211_put_signal(msg, sinfo->chains,
3715 sinfo->chain_signal,
3716 NL80211_STA_INFO_CHAIN_SIGNAL))
3717 goto nla_put_failure;
3718 }
3719 if (sinfo->filled & STATION_INFO_CHAIN_SIGNAL_AVG) {
3720 if (!nl80211_put_signal(msg, sinfo->chains,
3721 sinfo->chain_signal_avg,
3722 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3723 goto nla_put_failure;
3724 }
Henning Rogge420e7fa2008-12-11 22:04:19 +01003725 if (sinfo->filled & STATION_INFO_TX_BITRATE) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003726 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3727 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003728 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003729 }
3730 if (sinfo->filled & STATION_INFO_RX_BITRATE) {
3731 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3732 NL80211_STA_INFO_RX_BITRATE))
3733 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003734 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003735 if ((sinfo->filled & STATION_INFO_RX_PACKETS) &&
3736 nla_put_u32(msg, NL80211_STA_INFO_RX_PACKETS,
3737 sinfo->rx_packets))
3738 goto nla_put_failure;
3739 if ((sinfo->filled & STATION_INFO_TX_PACKETS) &&
3740 nla_put_u32(msg, NL80211_STA_INFO_TX_PACKETS,
3741 sinfo->tx_packets))
3742 goto nla_put_failure;
3743 if ((sinfo->filled & STATION_INFO_TX_RETRIES) &&
3744 nla_put_u32(msg, NL80211_STA_INFO_TX_RETRIES,
3745 sinfo->tx_retries))
3746 goto nla_put_failure;
3747 if ((sinfo->filled & STATION_INFO_TX_FAILED) &&
3748 nla_put_u32(msg, NL80211_STA_INFO_TX_FAILED,
3749 sinfo->tx_failed))
3750 goto nla_put_failure;
Antonio Quartulli867d8492014-05-19 21:53:19 +02003751 if ((sinfo->filled & STATION_INFO_EXPECTED_THROUGHPUT) &&
3752 nla_put_u32(msg, NL80211_STA_INFO_EXPECTED_THROUGHPUT,
3753 sinfo->expected_throughput))
3754 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04003755 if ((sinfo->filled & STATION_INFO_BEACON_LOSS_COUNT) &&
3756 nla_put_u32(msg, NL80211_STA_INFO_BEACON_LOSS,
3757 sinfo->beacon_loss_count))
3758 goto nla_put_failure;
Marco Porsch3b1c5a52013-01-07 16:04:52 +01003759 if ((sinfo->filled & STATION_INFO_LOCAL_PM) &&
3760 nla_put_u32(msg, NL80211_STA_INFO_LOCAL_PM,
3761 sinfo->local_pm))
3762 goto nla_put_failure;
3763 if ((sinfo->filled & STATION_INFO_PEER_PM) &&
3764 nla_put_u32(msg, NL80211_STA_INFO_PEER_PM,
3765 sinfo->peer_pm))
3766 goto nla_put_failure;
3767 if ((sinfo->filled & STATION_INFO_NONPEER_PM) &&
3768 nla_put_u32(msg, NL80211_STA_INFO_NONPEER_PM,
3769 sinfo->nonpeer_pm))
3770 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003771 if (sinfo->filled & STATION_INFO_BSS_PARAM) {
3772 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3773 if (!bss_param)
3774 goto nla_put_failure;
3775
David S. Miller9360ffd2012-03-29 04:41:26 -04003776 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3777 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3778 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3779 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3780 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3781 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3782 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3783 sinfo->bss_param.dtim_period) ||
3784 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3785 sinfo->bss_param.beacon_interval))
3786 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003787
3788 nla_nest_end(msg, bss_param);
3789 }
David S. Miller9360ffd2012-03-29 04:41:26 -04003790 if ((sinfo->filled & STATION_INFO_STA_FLAGS) &&
3791 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3792 sizeof(struct nl80211_sta_flag_update),
3793 &sinfo->sta_flags))
3794 goto nla_put_failure;
John W. Linville7eab0f62012-04-12 14:25:14 -04003795 if ((sinfo->filled & STATION_INFO_T_OFFSET) &&
3796 nla_put_u64(msg, NL80211_STA_INFO_T_OFFSET,
3797 sinfo->t_offset))
3798 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003799 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003800
David S. Miller9360ffd2012-03-29 04:41:26 -04003801 if ((sinfo->filled & STATION_INFO_ASSOC_REQ_IES) &&
3802 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3803 sinfo->assoc_req_ies))
3804 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003805
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003806 return genlmsg_end(msg, hdr);
3807
3808 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003809 genlmsg_cancel(msg, hdr);
3810 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003811}
3812
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003813static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003814 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003815{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003816 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003817 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003818 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003819 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003820 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003821 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003822
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003823 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003824 if (err)
3825 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003826
Johannes Berg97990a02013-04-19 01:02:55 +02003827 if (!wdev->netdev) {
3828 err = -EINVAL;
3829 goto out_err;
3830 }
3831
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003832 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003833 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003834 goto out_err;
3835 }
3836
Johannes Bergbba95fe2008-07-29 13:22:51 +02003837 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003838 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003839 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003840 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003841 if (err == -ENOENT)
3842 break;
3843 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003844 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003845
3846 if (nl80211_send_station(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003847 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003848 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003849 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003850 &sinfo) < 0)
3851 goto out;
3852
3853 sta_idx++;
3854 }
3855
3856
3857 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003858 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003859 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003860 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003861 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003862
3863 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003864}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003865
Johannes Berg5727ef12007-12-19 02:03:34 +01003866static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3867{
Johannes Berg4c476992010-10-04 21:36:35 +02003868 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3869 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003870 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003871 struct sk_buff *msg;
3872 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003873 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003874
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003875 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003876
3877 if (!info->attrs[NL80211_ATTR_MAC])
3878 return -EINVAL;
3879
3880 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3881
Johannes Berg4c476992010-10-04 21:36:35 +02003882 if (!rdev->ops->get_station)
3883 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003884
Hila Gonene35e4d22012-06-27 17:19:42 +03003885 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003886 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003887 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003888
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003889 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003890 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003891 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003892
Eric W. Biederman15e47302012-09-07 20:12:54 +00003893 if (nl80211_send_station(msg, info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003894 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003895 nlmsg_free(msg);
3896 return -ENOBUFS;
3897 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003898
Johannes Berg4c476992010-10-04 21:36:35 +02003899 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003900}
3901
Johannes Berg77ee7c82013-02-15 00:48:33 +01003902int cfg80211_check_station_change(struct wiphy *wiphy,
3903 struct station_parameters *params,
3904 enum cfg80211_station_type statype)
3905{
3906 if (params->listen_interval != -1)
3907 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003908 if (params->aid &&
3909 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003910 return -EINVAL;
3911
3912 /* When you run into this, adjust the code below for the new flag */
3913 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3914
3915 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003916 case CFG80211_STA_MESH_PEER_KERNEL:
3917 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003918 /*
3919 * No ignoring the TDLS flag here -- the userspace mesh
3920 * code doesn't have the bug of including TDLS in the
3921 * mask everywhere.
3922 */
3923 if (params->sta_flags_mask &
3924 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3925 BIT(NL80211_STA_FLAG_MFP) |
3926 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3927 return -EINVAL;
3928 break;
3929 case CFG80211_STA_TDLS_PEER_SETUP:
3930 case CFG80211_STA_TDLS_PEER_ACTIVE:
3931 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3932 return -EINVAL;
3933 /* ignore since it can't change */
3934 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3935 break;
3936 default:
3937 /* disallow mesh-specific things */
3938 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3939 return -EINVAL;
3940 if (params->local_pm)
3941 return -EINVAL;
3942 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3943 return -EINVAL;
3944 }
3945
3946 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3947 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3948 /* TDLS can't be set, ... */
3949 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3950 return -EINVAL;
3951 /*
3952 * ... but don't bother the driver with it. This works around
3953 * a hostapd/wpa_supplicant issue -- it always includes the
3954 * TLDS_PEER flag in the mask even for AP mode.
3955 */
3956 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3957 }
3958
3959 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
3960 /* reject other things that can't change */
3961 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
3962 return -EINVAL;
3963 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
3964 return -EINVAL;
3965 if (params->supported_rates)
3966 return -EINVAL;
3967 if (params->ext_capab || params->ht_capa || params->vht_capa)
3968 return -EINVAL;
3969 }
3970
3971 if (statype != CFG80211_STA_AP_CLIENT) {
3972 if (params->vlan)
3973 return -EINVAL;
3974 }
3975
3976 switch (statype) {
3977 case CFG80211_STA_AP_MLME_CLIENT:
3978 /* Use this only for authorizing/unauthorizing a station */
3979 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
3980 return -EOPNOTSUPP;
3981 break;
3982 case CFG80211_STA_AP_CLIENT:
3983 /* accept only the listed bits */
3984 if (params->sta_flags_mask &
3985 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
3986 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3987 BIT(NL80211_STA_FLAG_ASSOCIATED) |
3988 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3989 BIT(NL80211_STA_FLAG_WME) |
3990 BIT(NL80211_STA_FLAG_MFP)))
3991 return -EINVAL;
3992
3993 /* but authenticated/associated only if driver handles it */
3994 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
3995 params->sta_flags_mask &
3996 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3997 BIT(NL80211_STA_FLAG_ASSOCIATED)))
3998 return -EINVAL;
3999 break;
4000 case CFG80211_STA_IBSS:
4001 case CFG80211_STA_AP_STA:
4002 /* reject any changes other than AUTHORIZED */
4003 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4004 return -EINVAL;
4005 break;
4006 case CFG80211_STA_TDLS_PEER_SETUP:
4007 /* reject any changes other than AUTHORIZED or WME */
4008 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4009 BIT(NL80211_STA_FLAG_WME)))
4010 return -EINVAL;
4011 /* force (at least) rates when authorizing */
4012 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4013 !params->supported_rates)
4014 return -EINVAL;
4015 break;
4016 case CFG80211_STA_TDLS_PEER_ACTIVE:
4017 /* reject any changes */
4018 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004019 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004020 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4021 return -EINVAL;
4022 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004023 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004024 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4025 return -EINVAL;
4026 break;
4027 }
4028
4029 return 0;
4030}
4031EXPORT_SYMBOL(cfg80211_check_station_change);
4032
Johannes Berg5727ef12007-12-19 02:03:34 +01004033/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004034 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004035 */
Johannes Berg80b99892011-11-18 16:23:01 +01004036static struct net_device *get_vlan(struct genl_info *info,
4037 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004038{
Johannes Berg463d0182009-07-14 00:33:35 +02004039 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004040 struct net_device *v;
4041 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004042
Johannes Berg80b99892011-11-18 16:23:01 +01004043 if (!vlanattr)
4044 return NULL;
4045
4046 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4047 if (!v)
4048 return ERR_PTR(-ENODEV);
4049
4050 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4051 ret = -EINVAL;
4052 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004053 }
Johannes Berg80b99892011-11-18 16:23:01 +01004054
Johannes Berg77ee7c82013-02-15 00:48:33 +01004055 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4056 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4057 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4058 ret = -EINVAL;
4059 goto error;
4060 }
4061
Johannes Berg80b99892011-11-18 16:23:01 +01004062 if (!netif_running(v)) {
4063 ret = -ENETDOWN;
4064 goto error;
4065 }
4066
4067 return v;
4068 error:
4069 dev_put(v);
4070 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004071}
4072
Johannes Berg94e860f2014-01-20 23:58:15 +01004073static const struct nla_policy
4074nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004075 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4076 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4077};
4078
Johannes Bergff276692013-02-15 00:09:01 +01004079static int nl80211_parse_sta_wme(struct genl_info *info,
4080 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004081{
Jouni Malinendf881292013-02-14 21:10:54 +02004082 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4083 struct nlattr *nla;
4084 int err;
4085
Jouni Malinendf881292013-02-14 21:10:54 +02004086 /* parse WME attributes if present */
4087 if (!info->attrs[NL80211_ATTR_STA_WME])
4088 return 0;
4089
4090 nla = info->attrs[NL80211_ATTR_STA_WME];
4091 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4092 nl80211_sta_wme_policy);
4093 if (err)
4094 return err;
4095
4096 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4097 params->uapsd_queues = nla_get_u8(
4098 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4099 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4100 return -EINVAL;
4101
4102 if (tb[NL80211_STA_WME_MAX_SP])
4103 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4104
4105 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4106 return -EINVAL;
4107
4108 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4109
4110 return 0;
4111}
4112
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304113static int nl80211_parse_sta_channel_info(struct genl_info *info,
4114 struct station_parameters *params)
4115{
4116 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4117 params->supported_channels =
4118 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4119 params->supported_channels_len =
4120 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4121 /*
4122 * Need to include at least one (first channel, number of
4123 * channels) tuple for each subband, and must have proper
4124 * tuples for the rest of the data as well.
4125 */
4126 if (params->supported_channels_len < 2)
4127 return -EINVAL;
4128 if (params->supported_channels_len % 2)
4129 return -EINVAL;
4130 }
4131
4132 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4133 params->supported_oper_classes =
4134 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4135 params->supported_oper_classes_len =
4136 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4137 /*
4138 * The value of the Length field of the Supported Operating
4139 * Classes element is between 2 and 253.
4140 */
4141 if (params->supported_oper_classes_len < 2 ||
4142 params->supported_oper_classes_len > 253)
4143 return -EINVAL;
4144 }
4145 return 0;
4146}
4147
Johannes Bergff276692013-02-15 00:09:01 +01004148static int nl80211_set_station_tdls(struct genl_info *info,
4149 struct station_parameters *params)
4150{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304151 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004152 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004153 if (info->attrs[NL80211_ATTR_PEER_AID])
4154 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004155 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4156 params->ht_capa =
4157 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4158 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4159 params->vht_capa =
4160 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4161
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304162 err = nl80211_parse_sta_channel_info(info, params);
4163 if (err)
4164 return err;
4165
Johannes Bergff276692013-02-15 00:09:01 +01004166 return nl80211_parse_sta_wme(info, params);
4167}
4168
Johannes Berg5727ef12007-12-19 02:03:34 +01004169static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4170{
Johannes Berg4c476992010-10-04 21:36:35 +02004171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004172 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004173 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004174 u8 *mac_addr;
4175 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004176
4177 memset(&params, 0, sizeof(params));
4178
4179 params.listen_interval = -1;
4180
Johannes Berg77ee7c82013-02-15 00:48:33 +01004181 if (!rdev->ops->change_station)
4182 return -EOPNOTSUPP;
4183
Johannes Berg5727ef12007-12-19 02:03:34 +01004184 if (info->attrs[NL80211_ATTR_STA_AID])
4185 return -EINVAL;
4186
4187 if (!info->attrs[NL80211_ATTR_MAC])
4188 return -EINVAL;
4189
4190 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4191
4192 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4193 params.supported_rates =
4194 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4195 params.supported_rates_len =
4196 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4197 }
4198
Jouni Malinen9d62a982013-02-14 21:10:13 +02004199 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4200 params.capability =
4201 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4202 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4203 }
4204
4205 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4206 params.ext_capab =
4207 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4208 params.ext_capab_len =
4209 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4210 }
4211
Jouni Malinendf881292013-02-14 21:10:54 +02004212 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004213 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004214
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004215 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004216 return -EINVAL;
4217
Johannes Bergf8bacc22013-02-14 23:27:01 +01004218 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004219 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004220 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4221 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4222 return -EINVAL;
4223 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004224
Johannes Bergf8bacc22013-02-14 23:27:01 +01004225 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004226 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004227 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4228 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4229 return -EINVAL;
4230 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4231 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004232
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004233 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4234 enum nl80211_mesh_power_mode pm = nla_get_u32(
4235 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4236
4237 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4238 pm > NL80211_MESH_POWER_MAX)
4239 return -EINVAL;
4240
4241 params.local_pm = pm;
4242 }
4243
Johannes Berg77ee7c82013-02-15 00:48:33 +01004244 /* Include parameters for TDLS peer (will check later) */
4245 err = nl80211_set_station_tdls(info, &params);
4246 if (err)
4247 return err;
4248
4249 params.vlan = get_vlan(info, rdev);
4250 if (IS_ERR(params.vlan))
4251 return PTR_ERR(params.vlan);
4252
Johannes Berga97f4422009-06-18 17:23:43 +02004253 switch (dev->ieee80211_ptr->iftype) {
4254 case NL80211_IFTYPE_AP:
4255 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004256 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004257 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004258 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004259 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004260 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004261 break;
4262 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004263 err = -EOPNOTSUPP;
4264 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004265 }
4266
Johannes Berg77ee7c82013-02-15 00:48:33 +01004267 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004268 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004269
Johannes Berg77ee7c82013-02-15 00:48:33 +01004270 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004271 if (params.vlan)
4272 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004273
Johannes Berg5727ef12007-12-19 02:03:34 +01004274 return err;
4275}
4276
4277static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4278{
Johannes Berg4c476992010-10-04 21:36:35 +02004279 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004280 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004281 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004282 struct station_parameters params;
4283 u8 *mac_addr = NULL;
4284
4285 memset(&params, 0, sizeof(params));
4286
Johannes Berg984c3112013-02-14 23:43:25 +01004287 if (!rdev->ops->add_station)
4288 return -EOPNOTSUPP;
4289
Johannes Berg5727ef12007-12-19 02:03:34 +01004290 if (!info->attrs[NL80211_ATTR_MAC])
4291 return -EINVAL;
4292
Johannes Berg5727ef12007-12-19 02:03:34 +01004293 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4294 return -EINVAL;
4295
4296 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4297 return -EINVAL;
4298
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004299 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4300 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004301 return -EINVAL;
4302
Johannes Berg5727ef12007-12-19 02:03:34 +01004303 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4304 params.supported_rates =
4305 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4306 params.supported_rates_len =
4307 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4308 params.listen_interval =
4309 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004310
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004311 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004312 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004313 else
4314 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004315 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4316 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004317
Jouni Malinen9d62a982013-02-14 21:10:13 +02004318 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4319 params.capability =
4320 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4321 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4322 }
4323
4324 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4325 params.ext_capab =
4326 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4327 params.ext_capab_len =
4328 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4329 }
4330
Jouni Malinen36aedc92008-08-25 11:58:58 +03004331 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4332 params.ht_capa =
4333 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004334
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004335 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4336 params.vht_capa =
4337 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4338
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004339 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4340 params.opmode_notif_used = true;
4341 params.opmode_notif =
4342 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4343 }
4344
Johannes Bergf8bacc22013-02-14 23:27:01 +01004345 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004346 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004347 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4348 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4349 return -EINVAL;
4350 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004351
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304352 err = nl80211_parse_sta_channel_info(info, &params);
4353 if (err)
4354 return err;
4355
Johannes Bergff276692013-02-15 00:09:01 +01004356 err = nl80211_parse_sta_wme(info, &params);
4357 if (err)
4358 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004359
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004360 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004361 return -EINVAL;
4362
Johannes Berg77ee7c82013-02-15 00:48:33 +01004363 /* When you run into this, adjust the code below for the new flag */
4364 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4365
Johannes Bergbdd90d52011-12-14 12:20:27 +01004366 switch (dev->ieee80211_ptr->iftype) {
4367 case NL80211_IFTYPE_AP:
4368 case NL80211_IFTYPE_AP_VLAN:
4369 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004370 /* ignore WME attributes if iface/sta is not capable */
4371 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4372 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4373 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004374
Johannes Bergbdd90d52011-12-14 12:20:27 +01004375 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004376 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4377 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004378 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004379 /* but don't bother the driver with it */
4380 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004381
Johannes Bergd582cff2012-10-26 17:53:44 +02004382 /* allow authenticated/associated only if driver handles it */
4383 if (!(rdev->wiphy.features &
4384 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4385 params.sta_flags_mask &
4386 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4387 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4388 return -EINVAL;
4389
Johannes Bergbdd90d52011-12-14 12:20:27 +01004390 /* must be last in here for error handling */
4391 params.vlan = get_vlan(info, rdev);
4392 if (IS_ERR(params.vlan))
4393 return PTR_ERR(params.vlan);
4394 break;
4395 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004396 /* ignore uAPSD data */
4397 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4398
Johannes Bergd582cff2012-10-26 17:53:44 +02004399 /* associated is disallowed */
4400 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4401 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004402 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004403 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4404 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004405 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004406 break;
4407 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004408 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004409 /* ignore uAPSD data */
4410 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4411
Johannes Berg77ee7c82013-02-15 00:48:33 +01004412 /* these are disallowed */
4413 if (params.sta_flags_mask &
4414 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4415 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004416 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004417 /* Only TDLS peers can be added */
4418 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4419 return -EINVAL;
4420 /* Can only add if TDLS ... */
4421 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4422 return -EOPNOTSUPP;
4423 /* ... with external setup is supported */
4424 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4425 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004426 /*
4427 * Older wpa_supplicant versions always mark the TDLS peer
4428 * as authorized, but it shouldn't yet be.
4429 */
4430 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004431 break;
4432 default:
4433 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004434 }
4435
Johannes Bergbdd90d52011-12-14 12:20:27 +01004436 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004437
Hila Gonene35e4d22012-06-27 17:19:42 +03004438 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004439
Johannes Berg5727ef12007-12-19 02:03:34 +01004440 if (params.vlan)
4441 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004442 return err;
4443}
4444
4445static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4446{
Johannes Berg4c476992010-10-04 21:36:35 +02004447 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4448 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004449 struct station_del_parameters params;
4450
4451 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004452
4453 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004454 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004455
Johannes Berge80cf852009-05-11 14:43:13 +02004456 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004457 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004458 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004459 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4460 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004461
Johannes Berg4c476992010-10-04 21:36:35 +02004462 if (!rdev->ops->del_station)
4463 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004464
Jouni Malinen98856862014-10-20 13:20:45 +03004465 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4466 params.subtype =
4467 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4468 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4469 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4470 return -EINVAL;
4471 } else {
4472 /* Default to Deauthentication frame */
4473 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4474 }
4475
4476 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4477 params.reason_code =
4478 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4479 if (params.reason_code == 0)
4480 return -EINVAL; /* 0 is reserved */
4481 } else {
4482 /* Default to reason code 2 */
4483 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4484 }
4485
Jouni Malinen89c771e2014-10-10 20:52:40 +03004486 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004487}
4488
Eric W. Biederman15e47302012-09-07 20:12:54 +00004489static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004490 int flags, struct net_device *dev,
4491 u8 *dst, u8 *next_hop,
4492 struct mpath_info *pinfo)
4493{
4494 void *hdr;
4495 struct nlattr *pinfoattr;
4496
Henning Rogge1ef4c852014-11-04 16:14:58 +01004497 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004498 if (!hdr)
4499 return -1;
4500
David S. Miller9360ffd2012-03-29 04:41:26 -04004501 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4502 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4503 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4504 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4505 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004506
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004507 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4508 if (!pinfoattr)
4509 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004510 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4511 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4512 pinfo->frame_qlen))
4513 goto nla_put_failure;
4514 if (((pinfo->filled & MPATH_INFO_SN) &&
4515 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4516 ((pinfo->filled & MPATH_INFO_METRIC) &&
4517 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4518 pinfo->metric)) ||
4519 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4520 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4521 pinfo->exptime)) ||
4522 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4523 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4524 pinfo->flags)) ||
4525 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4526 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4527 pinfo->discovery_timeout)) ||
4528 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4529 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4530 pinfo->discovery_retries)))
4531 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004532
4533 nla_nest_end(msg, pinfoattr);
4534
4535 return genlmsg_end(msg, hdr);
4536
4537 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004538 genlmsg_cancel(msg, hdr);
4539 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004540}
4541
4542static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004543 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004544{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004545 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004546 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004547 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004548 u8 dst[ETH_ALEN];
4549 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004550 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004551 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004552
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004553 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004554 if (err)
4555 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004556
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004557 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004558 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004559 goto out_err;
4560 }
4561
Johannes Berg97990a02013-04-19 01:02:55 +02004562 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004563 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004564 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004565 }
4566
Johannes Bergbba95fe2008-07-29 13:22:51 +02004567 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004568 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004569 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004570 if (err == -ENOENT)
4571 break;
4572 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004573 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004574
Eric W. Biederman15e47302012-09-07 20:12:54 +00004575 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004576 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004577 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004578 &pinfo) < 0)
4579 goto out;
4580
4581 path_idx++;
4582 }
4583
4584
4585 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004586 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004587 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004588 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004589 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004590 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004591}
4592
4593static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4594{
Johannes Berg4c476992010-10-04 21:36:35 +02004595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004596 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004597 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004598 struct mpath_info pinfo;
4599 struct sk_buff *msg;
4600 u8 *dst = NULL;
4601 u8 next_hop[ETH_ALEN];
4602
4603 memset(&pinfo, 0, sizeof(pinfo));
4604
4605 if (!info->attrs[NL80211_ATTR_MAC])
4606 return -EINVAL;
4607
4608 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4609
Johannes Berg4c476992010-10-04 21:36:35 +02004610 if (!rdev->ops->get_mpath)
4611 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004612
Johannes Berg4c476992010-10-04 21:36:35 +02004613 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4614 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004615
Hila Gonene35e4d22012-06-27 17:19:42 +03004616 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004617 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004618 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004619
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004620 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004621 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004622 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004623
Eric W. Biederman15e47302012-09-07 20:12:54 +00004624 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004625 dev, dst, next_hop, &pinfo) < 0) {
4626 nlmsg_free(msg);
4627 return -ENOBUFS;
4628 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004629
Johannes Berg4c476992010-10-04 21:36:35 +02004630 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004631}
4632
4633static int nl80211_set_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];
4636 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004637 u8 *dst = NULL;
4638 u8 *next_hop = NULL;
4639
4640 if (!info->attrs[NL80211_ATTR_MAC])
4641 return -EINVAL;
4642
4643 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4644 return -EINVAL;
4645
4646 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4647 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4648
Johannes Berg4c476992010-10-04 21:36:35 +02004649 if (!rdev->ops->change_mpath)
4650 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004651
Johannes Berg4c476992010-10-04 21:36:35 +02004652 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4653 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004654
Hila Gonene35e4d22012-06-27 17:19:42 +03004655 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004656}
Johannes Berg4c476992010-10-04 21:36:35 +02004657
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004658static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4659{
Johannes Berg4c476992010-10-04 21:36:35 +02004660 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4661 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004662 u8 *dst = NULL;
4663 u8 *next_hop = NULL;
4664
4665 if (!info->attrs[NL80211_ATTR_MAC])
4666 return -EINVAL;
4667
4668 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4669 return -EINVAL;
4670
4671 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4672 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4673
Johannes Berg4c476992010-10-04 21:36:35 +02004674 if (!rdev->ops->add_mpath)
4675 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004676
Johannes Berg4c476992010-10-04 21:36:35 +02004677 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4678 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004679
Hila Gonene35e4d22012-06-27 17:19:42 +03004680 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004681}
4682
4683static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4684{
Johannes Berg4c476992010-10-04 21:36:35 +02004685 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4686 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004687 u8 *dst = NULL;
4688
4689 if (info->attrs[NL80211_ATTR_MAC])
4690 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4691
Johannes Berg4c476992010-10-04 21:36:35 +02004692 if (!rdev->ops->del_mpath)
4693 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004694
Hila Gonene35e4d22012-06-27 17:19:42 +03004695 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004696}
4697
Henning Rogge66be7d22014-09-12 08:58:49 +02004698static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4699{
4700 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4701 int err;
4702 struct net_device *dev = info->user_ptr[1];
4703 struct mpath_info pinfo;
4704 struct sk_buff *msg;
4705 u8 *dst = NULL;
4706 u8 mpp[ETH_ALEN];
4707
4708 memset(&pinfo, 0, sizeof(pinfo));
4709
4710 if (!info->attrs[NL80211_ATTR_MAC])
4711 return -EINVAL;
4712
4713 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4714
4715 if (!rdev->ops->get_mpp)
4716 return -EOPNOTSUPP;
4717
4718 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4719 return -EOPNOTSUPP;
4720
4721 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4722 if (err)
4723 return err;
4724
4725 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4726 if (!msg)
4727 return -ENOMEM;
4728
4729 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4730 dev, dst, mpp, &pinfo) < 0) {
4731 nlmsg_free(msg);
4732 return -ENOBUFS;
4733 }
4734
4735 return genlmsg_reply(msg, info);
4736}
4737
4738static int nl80211_dump_mpp(struct sk_buff *skb,
4739 struct netlink_callback *cb)
4740{
4741 struct mpath_info pinfo;
4742 struct cfg80211_registered_device *rdev;
4743 struct wireless_dev *wdev;
4744 u8 dst[ETH_ALEN];
4745 u8 mpp[ETH_ALEN];
4746 int path_idx = cb->args[2];
4747 int err;
4748
4749 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4750 if (err)
4751 return err;
4752
4753 if (!rdev->ops->dump_mpp) {
4754 err = -EOPNOTSUPP;
4755 goto out_err;
4756 }
4757
4758 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4759 err = -EOPNOTSUPP;
4760 goto out_err;
4761 }
4762
4763 while (1) {
4764 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4765 mpp, &pinfo);
4766 if (err == -ENOENT)
4767 break;
4768 if (err)
4769 goto out_err;
4770
4771 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4772 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4773 wdev->netdev, dst, mpp,
4774 &pinfo) < 0)
4775 goto out;
4776
4777 path_idx++;
4778 }
4779
4780 out:
4781 cb->args[2] = path_idx;
4782 err = skb->len;
4783 out_err:
4784 nl80211_finish_wdev_dump(rdev);
4785 return err;
4786}
4787
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004788static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4789{
Johannes Berg4c476992010-10-04 21:36:35 +02004790 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4791 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004792 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004793 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004794 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004795
4796 memset(&params, 0, sizeof(params));
4797 /* default to not changing parameters */
4798 params.use_cts_prot = -1;
4799 params.use_short_preamble = -1;
4800 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004801 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004802 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004803 params.p2p_ctwindow = -1;
4804 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004805
4806 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4807 params.use_cts_prot =
4808 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4809 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4810 params.use_short_preamble =
4811 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4812 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4813 params.use_short_slot_time =
4814 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004815 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4816 params.basic_rates =
4817 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4818 params.basic_rates_len =
4819 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4820 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004821 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4822 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004823 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4824 params.ht_opmode =
4825 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004826
Johannes Berg53cabad2012-11-14 15:17:28 +01004827 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4828 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4829 return -EINVAL;
4830 params.p2p_ctwindow =
4831 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4832 if (params.p2p_ctwindow < 0)
4833 return -EINVAL;
4834 if (params.p2p_ctwindow != 0 &&
4835 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4836 return -EINVAL;
4837 }
4838
4839 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4840 u8 tmp;
4841
4842 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4843 return -EINVAL;
4844 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4845 if (tmp > 1)
4846 return -EINVAL;
4847 params.p2p_opp_ps = tmp;
4848 if (params.p2p_opp_ps &&
4849 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4850 return -EINVAL;
4851 }
4852
Johannes Berg4c476992010-10-04 21:36:35 +02004853 if (!rdev->ops->change_bss)
4854 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004855
Johannes Berg074ac8d2010-09-16 14:58:22 +02004856 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004857 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4858 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004859
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004860 wdev_lock(wdev);
4861 err = rdev_change_bss(rdev, dev, &params);
4862 wdev_unlock(wdev);
4863
4864 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004865}
4866
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004867static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004868 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4869 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4870 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4871 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4872 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4873 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004874 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004875};
4876
4877static int parse_reg_rule(struct nlattr *tb[],
4878 struct ieee80211_reg_rule *reg_rule)
4879{
4880 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4881 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4882
4883 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4884 return -EINVAL;
4885 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4886 return -EINVAL;
4887 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4888 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004889 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4890 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004891 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4892 return -EINVAL;
4893
4894 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4895
4896 freq_range->start_freq_khz =
4897 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4898 freq_range->end_freq_khz =
4899 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004900 freq_range->max_bandwidth_khz =
4901 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004902
4903 power_rule->max_eirp =
4904 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4905
4906 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4907 power_rule->max_antenna_gain =
4908 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4909
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004910 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4911 reg_rule->dfs_cac_ms =
4912 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4913
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004914 return 0;
4915}
4916
4917static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4918{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004919 char *data = NULL;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004920 enum nl80211_user_reg_hint_type user_reg_hint_type;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004921
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004922 /*
4923 * You should only get this when cfg80211 hasn't yet initialized
4924 * completely when built-in to the kernel right between the time
4925 * window between nl80211_init() and regulatory_init(), if that is
4926 * even possible.
4927 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004928 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004929 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004930
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004931 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4932 user_reg_hint_type =
4933 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4934 else
4935 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4936
4937 switch (user_reg_hint_type) {
4938 case NL80211_USER_REG_HINT_USER:
4939 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004940 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4941 return -EINVAL;
4942
4943 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4944 return regulatory_hint_user(data, user_reg_hint_type);
4945 case NL80211_USER_REG_HINT_INDOOR:
4946 return regulatory_hint_indoor_user();
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004947 default:
4948 return -EINVAL;
4949 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004950}
4951
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004952static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01004953 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004954{
Johannes Berg4c476992010-10-04 21:36:35 +02004955 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004956 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01004957 struct wireless_dev *wdev = dev->ieee80211_ptr;
4958 struct mesh_config cur_params;
4959 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004960 void *hdr;
4961 struct nlattr *pinfoattr;
4962 struct sk_buff *msg;
4963
Johannes Berg29cbe682010-12-03 09:20:44 +01004964 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
4965 return -EOPNOTSUPP;
4966
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004967 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02004968 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02004969
Johannes Berg29cbe682010-12-03 09:20:44 +01004970 wdev_lock(wdev);
4971 /* If not connected, get default parameters */
4972 if (!wdev->mesh_id_len)
4973 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
4974 else
Hila Gonene35e4d22012-06-27 17:19:42 +03004975 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01004976 wdev_unlock(wdev);
4977
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004978 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004979 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004980
4981 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004982 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02004983 if (!msg)
4984 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00004985 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004986 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004987 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01004988 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004989 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07004990 if (!pinfoattr)
4991 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004992 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4993 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
4994 cur_params.dot11MeshRetryTimeout) ||
4995 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
4996 cur_params.dot11MeshConfirmTimeout) ||
4997 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
4998 cur_params.dot11MeshHoldingTimeout) ||
4999 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5000 cur_params.dot11MeshMaxPeerLinks) ||
5001 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5002 cur_params.dot11MeshMaxRetries) ||
5003 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5004 cur_params.dot11MeshTTL) ||
5005 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5006 cur_params.element_ttl) ||
5007 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5008 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005009 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5010 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005011 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5012 cur_params.dot11MeshHWMPmaxPREQretries) ||
5013 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5014 cur_params.path_refresh_time) ||
5015 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5016 cur_params.min_discovery_timeout) ||
5017 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5018 cur_params.dot11MeshHWMPactivePathTimeout) ||
5019 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5020 cur_params.dot11MeshHWMPpreqMinInterval) ||
5021 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5022 cur_params.dot11MeshHWMPperrMinInterval) ||
5023 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5024 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5025 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5026 cur_params.dot11MeshHWMPRootMode) ||
5027 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5028 cur_params.dot11MeshHWMPRannInterval) ||
5029 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5030 cur_params.dot11MeshGateAnnouncementProtocol) ||
5031 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5032 cur_params.dot11MeshForwarding) ||
5033 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005034 cur_params.rssi_threshold) ||
5035 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005036 cur_params.ht_opmode) ||
5037 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5038 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5039 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005040 cur_params.dot11MeshHWMProotInterval) ||
5041 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005042 cur_params.dot11MeshHWMPconfirmationInterval) ||
5043 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5044 cur_params.power_mode) ||
5045 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005046 cur_params.dot11MeshAwakeWindowDuration) ||
5047 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5048 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005049 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005050 nla_nest_end(msg, pinfoattr);
5051 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005052 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005053
Johannes Berg3b858752009-03-12 09:55:09 +01005054 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005055 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005056 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005057 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005058 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005059}
5060
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005061static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005062 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5063 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5064 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5065 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5066 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5067 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005068 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005069 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005070 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005071 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5072 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5073 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5074 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5075 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005076 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005077 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005078 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005079 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005080 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005081 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005082 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5083 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005084 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5085 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005086 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005087 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5088 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005089 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005090};
5091
Javier Cardonac80d5452010-12-16 17:37:49 -08005092static const struct nla_policy
5093 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005094 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005095 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5096 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005097 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005098 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005099 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005100 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005101 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005102 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005103};
5104
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005105static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005106 struct mesh_config *cfg,
5107 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005108{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005109 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005110 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005111
Marco Porschea54fba2013-01-07 16:04:48 +01005112#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5113do { \
5114 if (tb[attr]) { \
5115 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5116 return -EINVAL; \
5117 cfg->param = fn(tb[attr]); \
5118 mask |= (1 << (attr - 1)); \
5119 } \
5120} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005121
5122
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005123 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005124 return -EINVAL;
5125 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005126 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005127 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005128 return -EINVAL;
5129
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005130 /* This makes sure that there aren't more than 32 mesh config
5131 * parameters (otherwise our bitfield scheme would not work.) */
5132 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5133
5134 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005135 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005136 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5137 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005138 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005139 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5140 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005141 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005142 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5143 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005144 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005145 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5146 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005147 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005148 mask, NL80211_MESHCONF_MAX_RETRIES,
5149 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005150 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005151 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005152 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005153 mask, NL80211_MESHCONF_ELEMENT_TTL,
5154 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005155 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005156 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5157 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005158 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5159 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005160 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5161 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005162 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005163 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5164 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005165 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005166 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5167 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005168 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005169 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5170 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005171 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5172 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005173 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5174 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005175 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005176 1, 65535, mask,
5177 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005178 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005179 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005180 1, 65535, mask,
5181 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005182 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005183 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005184 dot11MeshHWMPnetDiameterTraversalTime,
5185 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005186 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5187 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005188 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5189 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5190 nla_get_u8);
5191 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5192 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005193 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005194 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005195 dot11MeshGateAnnouncementProtocol, 0, 1,
5196 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005197 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005198 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005199 mask, NL80211_MESHCONF_FORWARDING,
5200 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005201 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005202 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005203 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005204 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005205 mask, NL80211_MESHCONF_HT_OPMODE,
5206 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005207 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005208 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005209 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5210 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005211 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005212 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5213 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005214 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005215 dot11MeshHWMPconfirmationInterval,
5216 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005217 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5218 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005219 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5220 NL80211_MESH_POWER_ACTIVE,
5221 NL80211_MESH_POWER_MAX,
5222 mask, NL80211_MESHCONF_POWER_MODE,
5223 nla_get_u32);
5224 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5225 0, 65535, mask,
5226 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005227 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 1, 0xffffffff,
5228 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5229 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005230 if (mask_out)
5231 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005232
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005233 return 0;
5234
5235#undef FILL_IN_MESH_PARAM_IF_SET
5236}
5237
Javier Cardonac80d5452010-12-16 17:37:49 -08005238static int nl80211_parse_mesh_setup(struct genl_info *info,
5239 struct mesh_setup *setup)
5240{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005241 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005242 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5243
5244 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5245 return -EINVAL;
5246 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5247 info->attrs[NL80211_ATTR_MESH_SETUP],
5248 nl80211_mesh_setup_params_policy))
5249 return -EINVAL;
5250
Javier Cardonad299a1f2012-03-31 11:31:33 -07005251 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5252 setup->sync_method =
5253 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5254 IEEE80211_SYNC_METHOD_VENDOR :
5255 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5256
Javier Cardonac80d5452010-12-16 17:37:49 -08005257 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5258 setup->path_sel_proto =
5259 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5260 IEEE80211_PATH_PROTOCOL_VENDOR :
5261 IEEE80211_PATH_PROTOCOL_HWMP;
5262
5263 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5264 setup->path_metric =
5265 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5266 IEEE80211_PATH_METRIC_VENDOR :
5267 IEEE80211_PATH_METRIC_AIRTIME;
5268
Javier Cardona581a8b02011-04-07 15:08:27 -07005269
5270 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005271 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005272 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005273 if (!is_valid_ie_attr(ieattr))
5274 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005275 setup->ie = nla_data(ieattr);
5276 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005277 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005278 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5279 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5280 return -EINVAL;
5281 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005282 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5283 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005284 if (setup->is_secure)
5285 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005286
Colleen Twitty6e16d902013-05-08 11:45:59 -07005287 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5288 if (!setup->user_mpm)
5289 return -EINVAL;
5290 setup->auth_id =
5291 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5292 }
5293
Javier Cardonac80d5452010-12-16 17:37:49 -08005294 return 0;
5295}
5296
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005297static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005298 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005299{
5300 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5301 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005302 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005303 struct mesh_config cfg;
5304 u32 mask;
5305 int err;
5306
Johannes Berg29cbe682010-12-03 09:20:44 +01005307 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5308 return -EOPNOTSUPP;
5309
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005310 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005311 return -EOPNOTSUPP;
5312
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005313 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005314 if (err)
5315 return err;
5316
Johannes Berg29cbe682010-12-03 09:20:44 +01005317 wdev_lock(wdev);
5318 if (!wdev->mesh_id_len)
5319 err = -ENOLINK;
5320
5321 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005322 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005323
5324 wdev_unlock(wdev);
5325
5326 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005327}
5328
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005329static int nl80211_get_reg(struct sk_buff *skb, struct genl_info *info)
5330{
Johannes Berg458f4f92012-12-06 15:47:38 +01005331 const struct ieee80211_regdomain *regdom;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005332 struct sk_buff *msg;
5333 void *hdr = NULL;
5334 struct nlattr *nl_reg_rules;
5335 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005336
5337 if (!cfg80211_regdomain)
Johannes Berg5fe231e2013-05-08 21:45:15 +02005338 return -EINVAL;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005339
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005340 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005341 if (!msg)
5342 return -ENOBUFS;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005343
Eric W. Biederman15e47302012-09-07 20:12:54 +00005344 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005345 NL80211_CMD_GET_REG);
5346 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005347 goto put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005348
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005349 if (reg_last_request_cell_base() &&
5350 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5351 NL80211_USER_REG_HINT_CELL_BASE))
5352 goto nla_put_failure;
5353
Johannes Berg458f4f92012-12-06 15:47:38 +01005354 rcu_read_lock();
5355 regdom = rcu_dereference(cfg80211_regdomain);
5356
5357 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5358 (regdom->dfs_region &&
5359 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
5360 goto nla_put_failure_rcu;
5361
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005362 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5363 if (!nl_reg_rules)
Johannes Berg458f4f92012-12-06 15:47:38 +01005364 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005365
Johannes Berg458f4f92012-12-06 15:47:38 +01005366 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005367 struct nlattr *nl_reg_rule;
5368 const struct ieee80211_reg_rule *reg_rule;
5369 const struct ieee80211_freq_range *freq_range;
5370 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005371 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005372
Johannes Berg458f4f92012-12-06 15:47:38 +01005373 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005374 freq_range = &reg_rule->freq_range;
5375 power_rule = &reg_rule->power_rule;
5376
5377 nl_reg_rule = nla_nest_start(msg, i);
5378 if (!nl_reg_rule)
Johannes Berg458f4f92012-12-06 15:47:38 +01005379 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005380
Janusz Dziedzic97524822014-01-30 09:52:20 +01005381 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5382 if (!max_bandwidth_khz)
5383 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5384 reg_rule);
5385
David S. Miller9360ffd2012-03-29 04:41:26 -04005386 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5387 reg_rule->flags) ||
5388 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5389 freq_range->start_freq_khz) ||
5390 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5391 freq_range->end_freq_khz) ||
5392 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005393 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005394 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5395 power_rule->max_antenna_gain) ||
5396 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005397 power_rule->max_eirp) ||
5398 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5399 reg_rule->dfs_cac_ms))
Johannes Berg458f4f92012-12-06 15:47:38 +01005400 goto nla_put_failure_rcu;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005401
5402 nla_nest_end(msg, nl_reg_rule);
5403 }
Johannes Berg458f4f92012-12-06 15:47:38 +01005404 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005405
5406 nla_nest_end(msg, nl_reg_rules);
5407
5408 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005409 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005410
Johannes Berg458f4f92012-12-06 15:47:38 +01005411nla_put_failure_rcu:
5412 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005413nla_put_failure:
5414 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005415put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005416 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005417 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005418}
5419
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005420static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5421{
5422 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5423 struct nlattr *nl_reg_rule;
5424 char *alpha2 = NULL;
5425 int rem_reg_rules = 0, r = 0;
5426 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005427 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005428 struct ieee80211_regdomain *rd = NULL;
5429
5430 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5431 return -EINVAL;
5432
5433 if (!info->attrs[NL80211_ATTR_REG_RULES])
5434 return -EINVAL;
5435
5436 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5437
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005438 if (info->attrs[NL80211_ATTR_DFS_REGION])
5439 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5440
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005441 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005442 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005443 num_rules++;
5444 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005445 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005446 }
5447
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005448 if (!reg_is_valid_request(alpha2))
5449 return -EINVAL;
5450
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005451 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005452 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005453
5454 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005455 if (!rd)
5456 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005457
5458 rd->n_reg_rules = num_rules;
5459 rd->alpha2[0] = alpha2[0];
5460 rd->alpha2[1] = alpha2[1];
5461
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005462 /*
5463 * Disable DFS master mode if the DFS region was
5464 * not supported or known on this kernel.
5465 */
5466 if (reg_supported_dfs_region(dfs_region))
5467 rd->dfs_region = dfs_region;
5468
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005469 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005470 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005471 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5472 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5473 reg_rule_policy);
5474 if (r)
5475 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005476 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5477 if (r)
5478 goto bad_reg;
5479
5480 rule_idx++;
5481
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005482 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5483 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005484 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005485 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005486 }
5487
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005488 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005489 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005490 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005491
Johannes Bergd2372b32008-10-24 20:32:20 +02005492 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005493 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005494 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005495}
5496
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005497static int validate_scan_freqs(struct nlattr *freqs)
5498{
5499 struct nlattr *attr1, *attr2;
5500 int n_channels = 0, tmp1, tmp2;
5501
5502 nla_for_each_nested(attr1, freqs, tmp1) {
5503 n_channels++;
5504 /*
5505 * Some hardware has a limited channel list for
5506 * scanning, and it is pretty much nonsensical
5507 * to scan for a channel twice, so disallow that
5508 * and don't require drivers to check that the
5509 * channel list they get isn't longer than what
5510 * they can scan, as long as they can scan all
5511 * the channels they registered at once.
5512 */
5513 nla_for_each_nested(attr2, freqs, tmp2)
5514 if (attr1 != attr2 &&
5515 nla_get_u32(attr1) == nla_get_u32(attr2))
5516 return 0;
5517 }
5518
5519 return n_channels;
5520}
5521
Johannes Bergad2b26a2014-06-12 21:39:05 +02005522static int nl80211_parse_random_mac(struct nlattr **attrs,
5523 u8 *mac_addr, u8 *mac_addr_mask)
5524{
5525 int i;
5526
5527 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
5528 memset(mac_addr, 0, ETH_ALEN);
5529 memset(mac_addr_mask, 0, ETH_ALEN);
5530 mac_addr[0] = 0x2;
5531 mac_addr_mask[0] = 0x3;
5532
5533 return 0;
5534 }
5535
5536 /* need both or none */
5537 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5538 return -EINVAL;
5539
5540 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5541 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5542
5543 /* don't allow or configure an mcast address */
5544 if (!is_multicast_ether_addr(mac_addr_mask) ||
5545 is_multicast_ether_addr(mac_addr))
5546 return -EINVAL;
5547
5548 /*
5549 * allow users to pass a MAC address that has bits set outside
5550 * of the mask, but don't bother drivers with having to deal
5551 * with such bits
5552 */
5553 for (i = 0; i < ETH_ALEN; i++)
5554 mac_addr[i] &= mac_addr_mask[i];
5555
5556 return 0;
5557}
5558
Johannes Berg2a519312009-02-10 21:25:55 +01005559static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5560{
Johannes Berg4c476992010-10-04 21:36:35 +02005561 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005562 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005563 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005564 struct nlattr *attr;
5565 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005566 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005567 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005568
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005569 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5570 return -EINVAL;
5571
Johannes Berg79c97e92009-07-07 03:56:12 +02005572 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005573
Johannes Berg4c476992010-10-04 21:36:35 +02005574 if (!rdev->ops->scan)
5575 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005576
Johannes Bergf9d15d12014-01-22 11:14:19 +02005577 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005578 err = -EBUSY;
5579 goto unlock;
5580 }
Johannes Berg2a519312009-02-10 21:25:55 +01005581
5582 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005583 n_channels = validate_scan_freqs(
5584 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005585 if (!n_channels) {
5586 err = -EINVAL;
5587 goto unlock;
5588 }
Johannes Berg2a519312009-02-10 21:25:55 +01005589 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005590 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005591 }
5592
5593 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5594 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5595 n_ssids++;
5596
Johannes Bergf9f47522013-03-19 15:04:07 +01005597 if (n_ssids > wiphy->max_scan_ssids) {
5598 err = -EINVAL;
5599 goto unlock;
5600 }
Johannes Berg2a519312009-02-10 21:25:55 +01005601
Jouni Malinen70692ad2009-02-16 19:39:13 +02005602 if (info->attrs[NL80211_ATTR_IE])
5603 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5604 else
5605 ie_len = 0;
5606
Johannes Bergf9f47522013-03-19 15:04:07 +01005607 if (ie_len > wiphy->max_scan_ie_len) {
5608 err = -EINVAL;
5609 goto unlock;
5610 }
Johannes Berg18a83652009-03-31 12:12:05 +02005611
Johannes Berg2a519312009-02-10 21:25:55 +01005612 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005613 + sizeof(*request->ssids) * n_ssids
5614 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005615 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005616 if (!request) {
5617 err = -ENOMEM;
5618 goto unlock;
5619 }
Johannes Berg2a519312009-02-10 21:25:55 +01005620
Johannes Berg2a519312009-02-10 21:25:55 +01005621 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005622 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005623 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005624 if (ie_len) {
5625 if (request->ssids)
5626 request->ie = (void *)(request->ssids + n_ssids);
5627 else
5628 request->ie = (void *)(request->channels + n_channels);
5629 }
Johannes Berg2a519312009-02-10 21:25:55 +01005630
Johannes Berg584991d2009-11-02 13:32:03 +01005631 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005632 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5633 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005634 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005635 struct ieee80211_channel *chan;
5636
5637 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5638
5639 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005640 err = -EINVAL;
5641 goto out_free;
5642 }
Johannes Berg584991d2009-11-02 13:32:03 +01005643
5644 /* ignore disabled channels */
5645 if (chan->flags & IEEE80211_CHAN_DISABLED)
5646 continue;
5647
5648 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005649 i++;
5650 }
5651 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005652 enum ieee80211_band band;
5653
Johannes Berg2a519312009-02-10 21:25:55 +01005654 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005655 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5656 int j;
5657 if (!wiphy->bands[band])
5658 continue;
5659 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005660 struct ieee80211_channel *chan;
5661
5662 chan = &wiphy->bands[band]->channels[j];
5663
5664 if (chan->flags & IEEE80211_CHAN_DISABLED)
5665 continue;
5666
5667 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005668 i++;
5669 }
5670 }
5671 }
5672
Johannes Berg584991d2009-11-02 13:32:03 +01005673 if (!i) {
5674 err = -EINVAL;
5675 goto out_free;
5676 }
5677
5678 request->n_channels = i;
5679
Johannes Berg2a519312009-02-10 21:25:55 +01005680 i = 0;
5681 if (info->attrs[NL80211_ATTR_SCAN_SSIDS]) {
5682 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005683 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005684 err = -EINVAL;
5685 goto out_free;
5686 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005687 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005688 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005689 i++;
5690 }
5691 }
5692
Jouni Malinen70692ad2009-02-16 19:39:13 +02005693 if (info->attrs[NL80211_ATTR_IE]) {
5694 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005695 memcpy((void *)request->ie,
5696 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005697 request->ie_len);
5698 }
5699
Johannes Berg34850ab2011-07-18 18:08:35 +02005700 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005701 if (wiphy->bands[i])
5702 request->rates[i] =
5703 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005704
5705 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5706 nla_for_each_nested(attr,
5707 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5708 tmp) {
5709 enum ieee80211_band band = nla_type(attr);
5710
Dan Carpenter84404622011-07-29 11:52:18 +03005711 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005712 err = -EINVAL;
5713 goto out_free;
5714 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005715
5716 if (!wiphy->bands[band])
5717 continue;
5718
Johannes Berg34850ab2011-07-18 18:08:35 +02005719 err = ieee80211_get_ratemask(wiphy->bands[band],
5720 nla_data(attr),
5721 nla_len(attr),
5722 &request->rates[band]);
5723 if (err)
5724 goto out_free;
5725 }
5726 }
5727
Sam Leffler46856bb2012-10-11 21:03:32 -07005728 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005729 request->flags = nla_get_u32(
5730 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005731 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5732 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005733 err = -EOPNOTSUPP;
5734 goto out_free;
5735 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005736
5737 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5738 if (!(wiphy->features &
5739 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5740 err = -EOPNOTSUPP;
5741 goto out_free;
5742 }
5743
5744 if (wdev->current_bss) {
5745 err = -EOPNOTSUPP;
5746 goto out_free;
5747 }
5748
5749 err = nl80211_parse_random_mac(info->attrs,
5750 request->mac_addr,
5751 request->mac_addr_mask);
5752 if (err)
5753 goto out_free;
5754 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005755 }
Sam Lefflered4737712012-10-11 21:03:31 -07005756
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305757 request->no_cck =
5758 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5759
Johannes Bergfd014282012-06-18 19:17:03 +02005760 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005761 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005762 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005763
Johannes Berg79c97e92009-07-07 03:56:12 +02005764 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005765 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005766
Johannes Berg463d0182009-07-14 00:33:35 +02005767 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005768 nl80211_send_scan_start(rdev, wdev);
5769 if (wdev->netdev)
5770 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005771 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005772 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005773 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005774 kfree(request);
5775 }
Johannes Berg3b858752009-03-12 09:55:09 +01005776
Johannes Bergf9f47522013-03-19 15:04:07 +01005777 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005778 return err;
5779}
5780
Luciano Coelho256da022014-11-10 16:13:46 +02005781static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005782nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005783 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005784{
5785 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005786 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005787 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005788 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005789 enum ieee80211_band band;
5790 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005791 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005792 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005793
Luciano Coelho256da022014-11-10 16:13:46 +02005794 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5795 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005796
Luciano Coelho256da022014-11-10 16:13:46 +02005797 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5798 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005799
Luciano Coelho256da022014-11-10 16:13:46 +02005800 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005801 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005802 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005803
Luciano Coelho256da022014-11-10 16:13:46 +02005804 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005805 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005806 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005807 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005808 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005809 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005810 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005811 }
5812
Luciano Coelho256da022014-11-10 16:13:46 +02005813 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5814 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005815 tmp)
5816 n_ssids++;
5817
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005818 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005819 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005820
Johannes Bergea73cbc2014-01-24 10:53:53 +01005821 /*
5822 * First, count the number of 'real' matchsets. Due to an issue with
5823 * the old implementation, matchsets containing only the RSSI attribute
5824 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5825 * RSSI for all matchsets, rather than their own matchset for reporting
5826 * all APs with a strong RSSI. This is needed to be compatible with
5827 * older userspace that treated a matchset with only the RSSI as the
5828 * global RSSI for all other matchsets - if there are other matchsets.
5829 */
Luciano Coelho256da022014-11-10 16:13:46 +02005830 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005831 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005832 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01005833 tmp) {
5834 struct nlattr *rssi;
5835
5836 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5837 nla_data(attr), nla_len(attr),
5838 nl80211_match_policy);
5839 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02005840 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005841 /* add other standalone attributes here */
5842 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
5843 n_match_sets++;
5844 continue;
5845 }
5846 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5847 if (rssi)
5848 default_match_rssi = nla_get_s32(rssi);
5849 }
5850 }
5851
5852 /* However, if there's no other matchset, add the RSSI one */
5853 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
5854 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005855
5856 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02005857 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005858
Luciano Coelho256da022014-11-10 16:13:46 +02005859 if (attrs[NL80211_ATTR_IE])
5860 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005861 else
5862 ie_len = 0;
5863
Luciano Coelho5a865ba2011-07-13 14:57:29 +03005864 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02005865 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03005866
Luciano Coelho807f8a82011-05-11 17:09:35 +03005867 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005868 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005869 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005870 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03005871 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02005872 if (!request)
5873 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005874
5875 if (n_ssids)
5876 request->ssids = (void *)&request->channels[n_channels];
5877 request->n_ssids = n_ssids;
5878 if (ie_len) {
5879 if (request->ssids)
5880 request->ie = (void *)(request->ssids + n_ssids);
5881 else
5882 request->ie = (void *)(request->channels + n_channels);
5883 }
5884
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005885 if (n_match_sets) {
5886 if (request->ie)
5887 request->match_sets = (void *)(request->ie + ie_len);
5888 else if (request->ssids)
5889 request->match_sets =
5890 (void *)(request->ssids + n_ssids);
5891 else
5892 request->match_sets =
5893 (void *)(request->channels + n_channels);
5894 }
5895 request->n_match_sets = n_match_sets;
5896
Luciano Coelho807f8a82011-05-11 17:09:35 +03005897 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005898 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005899 /* user specified, bail out if channel not found */
5900 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005901 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005902 tmp) {
5903 struct ieee80211_channel *chan;
5904
5905 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5906
5907 if (!chan) {
5908 err = -EINVAL;
5909 goto out_free;
5910 }
5911
5912 /* ignore disabled channels */
5913 if (chan->flags & IEEE80211_CHAN_DISABLED)
5914 continue;
5915
5916 request->channels[i] = chan;
5917 i++;
5918 }
5919 } else {
5920 /* all channels */
5921 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5922 int j;
5923 if (!wiphy->bands[band])
5924 continue;
5925 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
5926 struct ieee80211_channel *chan;
5927
5928 chan = &wiphy->bands[band]->channels[j];
5929
5930 if (chan->flags & IEEE80211_CHAN_DISABLED)
5931 continue;
5932
5933 request->channels[i] = chan;
5934 i++;
5935 }
5936 }
5937 }
5938
5939 if (!i) {
5940 err = -EINVAL;
5941 goto out_free;
5942 }
5943
5944 request->n_channels = i;
5945
5946 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005947 if (attrs[NL80211_ATTR_SCAN_SSIDS]) {
5948 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005949 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005950 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005951 err = -EINVAL;
5952 goto out_free;
5953 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005954 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005955 memcpy(request->ssids[i].ssid, nla_data(attr),
5956 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03005957 i++;
5958 }
5959 }
5960
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005961 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02005962 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005963 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02005964 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005965 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07005966 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005967
Johannes Bergae811e22014-01-24 10:17:47 +01005968 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
5969 nla_data(attr), nla_len(attr),
5970 nl80211_match_policy);
5971 if (err)
5972 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02005973 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005974 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01005975 if (WARN_ON(i >= n_match_sets)) {
5976 /* this indicates a programming error,
5977 * the loop above should have verified
5978 * things properly
5979 */
5980 err = -EINVAL;
5981 goto out_free;
5982 }
5983
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005984 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
5985 err = -EINVAL;
5986 goto out_free;
5987 }
5988 memcpy(request->match_sets[i].ssid.ssid,
5989 nla_data(ssid), nla_len(ssid));
5990 request->match_sets[i].ssid.ssid_len =
5991 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01005992 /* special attribute - old implemenation w/a */
5993 request->match_sets[i].rssi_thold =
5994 default_match_rssi;
5995 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
5996 if (rssi)
5997 request->match_sets[i].rssi_thold =
5998 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005999 }
6000 i++;
6001 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006002
6003 /* there was no other matchset, so the RSSI one is alone */
6004 if (i == 0)
6005 request->match_sets[0].rssi_thold = default_match_rssi;
6006
6007 request->min_rssi_thold = INT_MAX;
6008 for (i = 0; i < n_match_sets; i++)
6009 request->min_rssi_thold =
6010 min(request->match_sets[i].rssi_thold,
6011 request->min_rssi_thold);
6012 } else {
6013 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006014 }
6015
Johannes Berg9900e482014-02-04 21:01:25 +01006016 if (ie_len) {
6017 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006018 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006019 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006020 request->ie_len);
6021 }
6022
Luciano Coelho256da022014-11-10 16:13:46 +02006023 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006024 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006025 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006026 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6027 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006028 err = -EOPNOTSUPP;
6029 goto out_free;
6030 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006031
6032 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6033 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6034
6035 if (!wdev) /* must be net-detect */
6036 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6037
6038 if (!(wiphy->features & flg)) {
6039 err = -EOPNOTSUPP;
6040 goto out_free;
6041 }
6042
6043 if (wdev && wdev->current_bss) {
6044 err = -EOPNOTSUPP;
6045 goto out_free;
6046 }
6047
6048 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6049 request->mac_addr_mask);
6050 if (err)
6051 goto out_free;
6052 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006053 }
Sam Lefflered4737712012-10-11 21:03:31 -07006054
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006055 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006056 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006057
Luciano Coelho256da022014-11-10 16:13:46 +02006058 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006059
6060out_free:
6061 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006062 return ERR_PTR(err);
6063}
6064
6065static int nl80211_start_sched_scan(struct sk_buff *skb,
6066 struct genl_info *info)
6067{
6068 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6069 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006070 struct wireless_dev *wdev = dev->ieee80211_ptr;
Luciano Coelho256da022014-11-10 16:13:46 +02006071 int err;
6072
6073 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6074 !rdev->ops->sched_scan_start)
6075 return -EOPNOTSUPP;
6076
6077 if (rdev->sched_scan_req)
6078 return -EINPROGRESS;
6079
Johannes Bergad2b26a2014-06-12 21:39:05 +02006080 rdev->sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02006081 info->attrs);
6082 err = PTR_ERR_OR_ZERO(rdev->sched_scan_req);
6083 if (err)
6084 goto out_err;
6085
6086 err = rdev_sched_scan_start(rdev, dev, rdev->sched_scan_req);
6087 if (err)
6088 goto out_free;
6089
6090 rdev->sched_scan_req->dev = dev;
6091 rdev->sched_scan_req->wiphy = &rdev->wiphy;
6092
6093 nl80211_send_sched_scan(rdev, dev,
6094 NL80211_CMD_START_SCHED_SCAN);
6095 return 0;
6096
6097out_free:
6098 kfree(rdev->sched_scan_req);
6099out_err:
6100 rdev->sched_scan_req = NULL;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006101 return err;
6102}
6103
6104static int nl80211_stop_sched_scan(struct sk_buff *skb,
6105 struct genl_info *info)
6106{
6107 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6108
6109 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6110 !rdev->ops->sched_scan_stop)
6111 return -EOPNOTSUPP;
6112
Johannes Berg5fe231e2013-05-08 21:45:15 +02006113 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006114}
6115
Simon Wunderlich04f39042013-02-08 18:16:19 +01006116static int nl80211_start_radar_detection(struct sk_buff *skb,
6117 struct genl_info *info)
6118{
6119 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6120 struct net_device *dev = info->user_ptr[1];
6121 struct wireless_dev *wdev = dev->ieee80211_ptr;
6122 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006123 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006124 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006125 int err;
6126
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006127 dfs_region = reg_get_dfs_region(wdev->wiphy);
6128 if (dfs_region == NL80211_DFS_UNSET)
6129 return -EINVAL;
6130
Simon Wunderlich04f39042013-02-08 18:16:19 +01006131 err = nl80211_parse_chandef(rdev, info, &chandef);
6132 if (err)
6133 return err;
6134
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006135 if (netif_carrier_ok(dev))
6136 return -EBUSY;
6137
Simon Wunderlich04f39042013-02-08 18:16:19 +01006138 if (wdev->cac_started)
6139 return -EBUSY;
6140
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006141 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006142 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006143 if (err < 0)
6144 return err;
6145
6146 if (err == 0)
6147 return -EINVAL;
6148
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006149 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006150 return -EINVAL;
6151
6152 if (!rdev->ops->start_radar_detection)
6153 return -EOPNOTSUPP;
6154
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006155 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6156 if (WARN_ON(!cac_time_ms))
6157 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6158
6159 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6160 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006161 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006162 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006163 wdev->cac_started = true;
6164 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006165 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006166 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006167 return err;
6168}
6169
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006170static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6171{
6172 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6173 struct net_device *dev = info->user_ptr[1];
6174 struct wireless_dev *wdev = dev->ieee80211_ptr;
6175 struct cfg80211_csa_settings params;
6176 /* csa_attrs is defined static to avoid waste of stack size - this
6177 * function is called under RTNL lock, so this should not be a problem.
6178 */
6179 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006180 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006181 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006182 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006183 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006184
6185 if (!rdev->ops->channel_switch ||
6186 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6187 return -EOPNOTSUPP;
6188
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006189 switch (dev->ieee80211_ptr->iftype) {
6190 case NL80211_IFTYPE_AP:
6191 case NL80211_IFTYPE_P2P_GO:
6192 need_new_beacon = true;
6193
6194 /* useless if AP is not running */
6195 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006196 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006197 break;
6198 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006199 if (!wdev->ssid_len)
6200 return -ENOTCONN;
6201 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006202 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006203 if (!wdev->mesh_id_len)
6204 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006205 break;
6206 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006207 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006208 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006209
6210 memset(&params, 0, sizeof(params));
6211
6212 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6213 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6214 return -EINVAL;
6215
6216 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006217 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006218 return -EINVAL;
6219
Luciano Coelho252e07c2014-10-08 09:48:34 +03006220 /* Even though the attribute is u32, the specification says
6221 * u8, so let's make sure we don't overflow.
6222 */
6223 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6224 if (cs_count > 255)
6225 return -EINVAL;
6226
6227 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006228
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006229 if (!need_new_beacon)
6230 goto skip_beacons;
6231
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006232 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6233 if (err)
6234 return err;
6235
6236 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6237 info->attrs[NL80211_ATTR_CSA_IES],
6238 nl80211_policy);
6239 if (err)
6240 return err;
6241
6242 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6243 if (err)
6244 return err;
6245
6246 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6247 return -EINVAL;
6248
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006249 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6250 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006251 return -EINVAL;
6252
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006253 params.n_counter_offsets_beacon = len / sizeof(u16);
6254 if (rdev->wiphy.max_num_csa_counters &&
6255 (params.n_counter_offsets_beacon >
6256 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006257 return -EINVAL;
6258
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006259 params.counter_offsets_beacon =
6260 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6261
6262 /* sanity checks - counters should fit and be the same */
6263 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6264 u16 offset = params.counter_offsets_beacon[i];
6265
6266 if (offset >= params.beacon_csa.tail_len)
6267 return -EINVAL;
6268
6269 if (params.beacon_csa.tail[offset] != params.count)
6270 return -EINVAL;
6271 }
6272
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006273 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006274 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6275 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006276 return -EINVAL;
6277
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006278 params.n_counter_offsets_presp = len / sizeof(u16);
6279 if (rdev->wiphy.max_num_csa_counters &&
6280 (params.n_counter_offsets_beacon >
6281 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006282 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006283
6284 params.counter_offsets_presp =
6285 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6286
6287 /* sanity checks - counters should fit and be the same */
6288 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6289 u16 offset = params.counter_offsets_presp[i];
6290
6291 if (offset >= params.beacon_csa.probe_resp_len)
6292 return -EINVAL;
6293
6294 if (params.beacon_csa.probe_resp[offset] !=
6295 params.count)
6296 return -EINVAL;
6297 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006298 }
6299
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006300skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006301 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6302 if (err)
6303 return err;
6304
Ilan Peer174e0cd2014-02-23 09:13:01 +02006305 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6306 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006307 return -EINVAL;
6308
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006309 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6310 &params.chandef,
6311 wdev->iftype);
6312 if (err < 0)
6313 return err;
6314
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006315 if (err > 0)
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006316 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006317
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006318 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6319 params.block_tx = true;
6320
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006321 wdev_lock(wdev);
6322 err = rdev_channel_switch(rdev, dev, &params);
6323 wdev_unlock(wdev);
6324
6325 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006326}
6327
Johannes Berg9720bb32011-06-21 09:45:33 +02006328static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6329 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006330 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006331 struct wireless_dev *wdev,
6332 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006333{
Johannes Berg48ab9052009-07-10 18:42:31 +02006334 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006335 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006336 void *hdr;
6337 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006338
6339 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006340
Eric W. Biederman15e47302012-09-07 20:12:54 +00006341 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006342 NL80211_CMD_NEW_SCAN_RESULTS);
6343 if (!hdr)
6344 return -1;
6345
Johannes Berg9720bb32011-06-21 09:45:33 +02006346 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6347
Johannes Berg97990a02013-04-19 01:02:55 +02006348 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6349 goto nla_put_failure;
6350 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006351 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6352 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006353 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6354 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006355
6356 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6357 if (!bss)
6358 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006359 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006360 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006361 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006362
6363 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006364 /* indicate whether we have probe response data or not */
6365 if (rcu_access_pointer(res->proberesp_ies) &&
6366 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6367 goto fail_unlock_rcu;
6368
6369 /* this pointer prefers to be pointed to probe response data
6370 * but is always valid
6371 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006372 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006373 if (ies) {
6374 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6375 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006376 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6377 ies->len, ies->data))
6378 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006379 }
Johannes Berg0e227082014-08-12 20:34:30 +02006380
6381 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006382 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006383 if (ies && ies->from_beacon) {
6384 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006385 goto fail_unlock_rcu;
6386 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6387 ies->len, ies->data))
6388 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006389 }
6390 rcu_read_unlock();
6391
David S. Miller9360ffd2012-03-29 04:41:26 -04006392 if (res->beacon_interval &&
6393 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6394 goto nla_put_failure;
6395 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6396 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006397 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006398 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6399 jiffies_to_msecs(jiffies - intbss->ts)))
6400 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006401
Johannes Berg77965c92009-02-18 18:45:06 +01006402 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006403 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006404 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6405 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006406 break;
6407 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006408 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6409 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006410 break;
6411 default:
6412 break;
6413 }
6414
Johannes Berg48ab9052009-07-10 18:42:31 +02006415 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006416 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006417 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006418 if (intbss == wdev->current_bss &&
6419 nla_put_u32(msg, NL80211_BSS_STATUS,
6420 NL80211_BSS_STATUS_ASSOCIATED))
6421 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006422 break;
6423 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006424 if (intbss == wdev->current_bss &&
6425 nla_put_u32(msg, NL80211_BSS_STATUS,
6426 NL80211_BSS_STATUS_IBSS_JOINED))
6427 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006428 break;
6429 default:
6430 break;
6431 }
6432
Johannes Berg2a519312009-02-10 21:25:55 +01006433 nla_nest_end(msg, bss);
6434
6435 return genlmsg_end(msg, hdr);
6436
Johannes Berg8cef2c92013-02-05 16:54:31 +01006437 fail_unlock_rcu:
6438 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006439 nla_put_failure:
6440 genlmsg_cancel(msg, hdr);
6441 return -EMSGSIZE;
6442}
6443
Johannes Berg97990a02013-04-19 01:02:55 +02006444static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006445{
Johannes Berg48ab9052009-07-10 18:42:31 +02006446 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006447 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006448 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006449 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006450 int err;
6451
Johannes Berg97990a02013-04-19 01:02:55 +02006452 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006453 if (err)
6454 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006455
Johannes Berg48ab9052009-07-10 18:42:31 +02006456 wdev_lock(wdev);
6457 spin_lock_bh(&rdev->bss_lock);
6458 cfg80211_bss_expire(rdev);
6459
Johannes Berg9720bb32011-06-21 09:45:33 +02006460 cb->seq = rdev->bss_generation;
6461
Johannes Berg48ab9052009-07-10 18:42:31 +02006462 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006463 if (++idx <= start)
6464 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006465 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006466 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006467 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006468 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006469 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006470 }
6471 }
6472
Johannes Berg48ab9052009-07-10 18:42:31 +02006473 spin_unlock_bh(&rdev->bss_lock);
6474 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006475
Johannes Berg97990a02013-04-19 01:02:55 +02006476 cb->args[2] = idx;
6477 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006478
Johannes Berg67748892010-10-04 21:14:06 +02006479 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006480}
6481
Eric W. Biederman15e47302012-09-07 20:12:54 +00006482static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Holger Schurig61fa7132009-11-11 12:25:40 +01006483 int flags, struct net_device *dev,
6484 struct survey_info *survey)
6485{
6486 void *hdr;
6487 struct nlattr *infoattr;
6488
Eric W. Biederman15e47302012-09-07 20:12:54 +00006489 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006490 NL80211_CMD_NEW_SURVEY_RESULTS);
6491 if (!hdr)
6492 return -ENOMEM;
6493
David S. Miller9360ffd2012-03-29 04:41:26 -04006494 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6495 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006496
6497 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6498 if (!infoattr)
6499 goto nla_put_failure;
6500
David S. Miller9360ffd2012-03-29 04:41:26 -04006501 if (nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
6502 survey->channel->center_freq))
6503 goto nla_put_failure;
6504
6505 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6506 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6507 goto nla_put_failure;
6508 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6509 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6510 goto nla_put_failure;
6511 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME) &&
6512 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME,
6513 survey->channel_time))
6514 goto nla_put_failure;
6515 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_BUSY) &&
6516 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY,
6517 survey->channel_time_busy))
6518 goto nla_put_failure;
6519 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY) &&
6520 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_EXT_BUSY,
6521 survey->channel_time_ext_busy))
6522 goto nla_put_failure;
6523 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_RX) &&
6524 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_RX,
6525 survey->channel_time_rx))
6526 goto nla_put_failure;
6527 if ((survey->filled & SURVEY_INFO_CHANNEL_TIME_TX) &&
6528 nla_put_u64(msg, NL80211_SURVEY_INFO_CHANNEL_TIME_TX,
6529 survey->channel_time_tx))
6530 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006531
6532 nla_nest_end(msg, infoattr);
6533
6534 return genlmsg_end(msg, hdr);
6535
6536 nla_put_failure:
6537 genlmsg_cancel(msg, hdr);
6538 return -EMSGSIZE;
6539}
6540
6541static int nl80211_dump_survey(struct sk_buff *skb,
6542 struct netlink_callback *cb)
6543{
6544 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006545 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006546 struct wireless_dev *wdev;
6547 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006548 int res;
6549
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006550 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006551 if (res)
6552 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006553
Johannes Berg97990a02013-04-19 01:02:55 +02006554 if (!wdev->netdev) {
6555 res = -EINVAL;
6556 goto out_err;
6557 }
6558
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006559 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006560 res = -EOPNOTSUPP;
6561 goto out_err;
6562 }
6563
6564 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006565 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006566 if (res == -ENOENT)
6567 break;
6568 if (res)
6569 goto out_err;
6570
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006571 /* Survey without a channel doesn't make sense */
6572 if (!survey.channel) {
6573 res = -EINVAL;
6574 goto out;
6575 }
6576
Johannes Bergea9eba62014-11-21 15:24:31 +01006577 if (survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006578 survey_idx++;
6579 continue;
6580 }
6581
Holger Schurig61fa7132009-11-11 12:25:40 +01006582 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006583 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006584 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02006585 wdev->netdev, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006586 goto out;
6587 survey_idx++;
6588 }
6589
6590 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006591 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006592 res = skb->len;
6593 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006594 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006595 return res;
6596}
6597
Samuel Ortizb23aa672009-07-01 21:26:54 +02006598static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6599{
6600 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6601 NL80211_WPA_VERSION_2));
6602}
6603
Jouni Malinen636a5d32009-03-19 13:39:22 +02006604static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6605{
Johannes Berg4c476992010-10-04 21:36:35 +02006606 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6607 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006608 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006609 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6610 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006611 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006612 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006613 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006614
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006615 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6616 return -EINVAL;
6617
6618 if (!info->attrs[NL80211_ATTR_MAC])
6619 return -EINVAL;
6620
Jouni Malinen17780922009-03-27 20:52:47 +02006621 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6622 return -EINVAL;
6623
Johannes Berg19957bb2009-07-02 17:20:43 +02006624 if (!info->attrs[NL80211_ATTR_SSID])
6625 return -EINVAL;
6626
6627 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6628 return -EINVAL;
6629
Johannes Bergfffd0932009-07-08 14:22:54 +02006630 err = nl80211_parse_key(info, &key);
6631 if (err)
6632 return err;
6633
6634 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006635 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6636 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006637 if (!key.p.key || !key.p.key_len)
6638 return -EINVAL;
6639 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6640 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6641 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6642 key.p.key_len != WLAN_KEY_LEN_WEP104))
6643 return -EINVAL;
6644 if (key.idx > 4)
6645 return -EINVAL;
6646 } else {
6647 key.p.key_len = 0;
6648 key.p.key = NULL;
6649 }
6650
Johannes Bergafea0b72010-08-10 09:46:42 +02006651 if (key.idx >= 0) {
6652 int i;
6653 bool ok = false;
6654 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6655 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6656 ok = true;
6657 break;
6658 }
6659 }
Johannes Berg4c476992010-10-04 21:36:35 +02006660 if (!ok)
6661 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006662 }
6663
Johannes Berg4c476992010-10-04 21:36:35 +02006664 if (!rdev->ops->auth)
6665 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006666
Johannes Berg074ac8d2010-09-16 14:58:22 +02006667 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006668 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6669 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006670
Johannes Berg19957bb2009-07-02 17:20:43 +02006671 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006672 chan = nl80211_get_valid_chan(&rdev->wiphy,
6673 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6674 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006675 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006676
Johannes Berg19957bb2009-07-02 17:20:43 +02006677 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6678 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6679
6680 if (info->attrs[NL80211_ATTR_IE]) {
6681 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6682 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6683 }
6684
6685 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006686 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006687 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006688
Jouni Malinene39e5b52012-09-30 19:29:39 +03006689 if (auth_type == NL80211_AUTHTYPE_SAE &&
6690 !info->attrs[NL80211_ATTR_SAE_DATA])
6691 return -EINVAL;
6692
6693 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6694 if (auth_type != NL80211_AUTHTYPE_SAE)
6695 return -EINVAL;
6696 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6697 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6698 /* need to include at least Auth Transaction and Status Code */
6699 if (sae_data_len < 4)
6700 return -EINVAL;
6701 }
6702
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006703 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6704
Johannes Berg95de8172012-01-20 13:55:25 +01006705 /*
6706 * Since we no longer track auth state, ignore
6707 * requests to only change local state.
6708 */
6709 if (local_state_change)
6710 return 0;
6711
Johannes Berg91bf9b22013-05-15 17:44:01 +02006712 wdev_lock(dev->ieee80211_ptr);
6713 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6714 ssid, ssid_len, ie, ie_len,
6715 key.p.key, key.p.key_len, key.idx,
6716 sae_data, sae_data_len);
6717 wdev_unlock(dev->ieee80211_ptr);
6718 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006719}
6720
Johannes Bergc0692b82010-08-27 14:26:53 +03006721static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6722 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006723 struct cfg80211_crypto_settings *settings,
6724 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006725{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006726 memset(settings, 0, sizeof(*settings));
6727
Samuel Ortizb23aa672009-07-01 21:26:54 +02006728 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6729
Johannes Bergc0692b82010-08-27 14:26:53 +03006730 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6731 u16 proto;
6732 proto = nla_get_u16(
6733 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6734 settings->control_port_ethertype = cpu_to_be16(proto);
6735 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6736 proto != ETH_P_PAE)
6737 return -EINVAL;
6738 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6739 settings->control_port_no_encrypt = true;
6740 } else
6741 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6742
Samuel Ortizb23aa672009-07-01 21:26:54 +02006743 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6744 void *data;
6745 int len, i;
6746
6747 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6748 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6749 settings->n_ciphers_pairwise = len / sizeof(u32);
6750
6751 if (len % sizeof(u32))
6752 return -EINVAL;
6753
Johannes Berg3dc27d22009-07-02 21:36:37 +02006754 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006755 return -EINVAL;
6756
6757 memcpy(settings->ciphers_pairwise, data, len);
6758
6759 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006760 if (!cfg80211_supported_cipher_suite(
6761 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006762 settings->ciphers_pairwise[i]))
6763 return -EINVAL;
6764 }
6765
6766 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6767 settings->cipher_group =
6768 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006769 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6770 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006771 return -EINVAL;
6772 }
6773
6774 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6775 settings->wpa_versions =
6776 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6777 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6778 return -EINVAL;
6779 }
6780
6781 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6782 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006783 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006784
6785 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6786 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6787 settings->n_akm_suites = len / sizeof(u32);
6788
6789 if (len % sizeof(u32))
6790 return -EINVAL;
6791
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006792 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6793 return -EINVAL;
6794
Samuel Ortizb23aa672009-07-01 21:26:54 +02006795 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006796 }
6797
6798 return 0;
6799}
6800
Jouni Malinen636a5d32009-03-19 13:39:22 +02006801static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6802{
Johannes Berg4c476992010-10-04 21:36:35 +02006803 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6804 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006805 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006806 struct cfg80211_assoc_request req = {};
6807 const u8 *bssid, *ssid;
6808 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006809
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006810 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6811 return -EINVAL;
6812
6813 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02006814 !info->attrs[NL80211_ATTR_SSID] ||
6815 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006816 return -EINVAL;
6817
Johannes Berg4c476992010-10-04 21:36:35 +02006818 if (!rdev->ops->assoc)
6819 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006820
Johannes Berg074ac8d2010-09-16 14:58:22 +02006821 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006822 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6823 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006824
Johannes Berg19957bb2009-07-02 17:20:43 +02006825 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006826
Jouni Malinen664834d2014-01-15 00:01:44 +02006827 chan = nl80211_get_valid_chan(&rdev->wiphy,
6828 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6829 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006830 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006831
Johannes Berg19957bb2009-07-02 17:20:43 +02006832 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6833 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006834
6835 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006836 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6837 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006838 }
6839
Jouni Malinendc6382c2009-05-06 22:09:37 +03006840 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006841 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03006842 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02006843 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01006844 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02006845 else if (mfp != NL80211_MFP_NO)
6846 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03006847 }
6848
Johannes Berg3e5d7642009-07-07 14:37:26 +02006849 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01006850 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02006851
Ben Greear7e7c8922011-11-18 11:31:59 -08006852 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006853 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08006854
6855 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006856 memcpy(&req.ht_capa_mask,
6857 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
6858 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08006859
6860 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006861 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08006862 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006863 memcpy(&req.ht_capa,
6864 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
6865 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08006866 }
6867
Johannes Bergee2aca32013-02-21 17:36:01 +01006868 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01006869 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01006870
6871 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01006872 memcpy(&req.vht_capa_mask,
6873 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
6874 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01006875
6876 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01006877 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01006878 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01006879 memcpy(&req.vht_capa,
6880 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
6881 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01006882 }
6883
Assaf Kraussbab5ab72014-09-03 15:25:01 +03006884 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
6885 if (!(rdev->wiphy.features &
6886 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
6887 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
6888 return -EINVAL;
6889 req.flags |= ASSOC_REQ_USE_RRM;
6890 }
6891
Johannes Bergf62fab72013-02-21 20:09:09 +01006892 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006893 if (!err) {
6894 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01006895 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
6896 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02006897 wdev_unlock(dev->ieee80211_ptr);
6898 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006899
Jouni Malinen636a5d32009-03-19 13:39:22 +02006900 return err;
6901}
6902
6903static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
6904{
Johannes Berg4c476992010-10-04 21:36:35 +02006905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6906 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006907 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006908 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006909 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006910 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006911
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006912 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6913 return -EINVAL;
6914
6915 if (!info->attrs[NL80211_ATTR_MAC])
6916 return -EINVAL;
6917
6918 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6919 return -EINVAL;
6920
Johannes Berg4c476992010-10-04 21:36:35 +02006921 if (!rdev->ops->deauth)
6922 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006923
Johannes Berg074ac8d2010-09-16 14:58:22 +02006924 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006925 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6926 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006927
Johannes Berg19957bb2009-07-02 17:20:43 +02006928 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006929
Johannes Berg19957bb2009-07-02 17:20:43 +02006930 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6931 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006932 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006933 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006934 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006935
6936 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006937 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6938 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006939 }
6940
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006941 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6942
Johannes Berg91bf9b22013-05-15 17:44:01 +02006943 wdev_lock(dev->ieee80211_ptr);
6944 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
6945 local_state_change);
6946 wdev_unlock(dev->ieee80211_ptr);
6947 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006948}
6949
6950static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
6951{
Johannes Berg4c476992010-10-04 21:36:35 +02006952 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6953 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006954 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02006955 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02006956 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006957 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006958
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006959 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6960 return -EINVAL;
6961
6962 if (!info->attrs[NL80211_ATTR_MAC])
6963 return -EINVAL;
6964
6965 if (!info->attrs[NL80211_ATTR_REASON_CODE])
6966 return -EINVAL;
6967
Johannes Berg4c476992010-10-04 21:36:35 +02006968 if (!rdev->ops->disassoc)
6969 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006970
Johannes Berg074ac8d2010-09-16 14:58:22 +02006971 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006972 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6973 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006974
Johannes Berg19957bb2009-07-02 17:20:43 +02006975 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006976
Johannes Berg19957bb2009-07-02 17:20:43 +02006977 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
6978 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006979 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02006980 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02006981 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02006982
6983 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02006984 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6985 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02006986 }
6987
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006988 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6989
Johannes Berg91bf9b22013-05-15 17:44:01 +02006990 wdev_lock(dev->ieee80211_ptr);
6991 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
6992 local_state_change);
6993 wdev_unlock(dev->ieee80211_ptr);
6994 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006995}
6996
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01006997static bool
6998nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
6999 int mcast_rate[IEEE80211_NUM_BANDS],
7000 int rateval)
7001{
7002 struct wiphy *wiphy = &rdev->wiphy;
7003 bool found = false;
7004 int band, i;
7005
7006 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7007 struct ieee80211_supported_band *sband;
7008
7009 sband = wiphy->bands[band];
7010 if (!sband)
7011 continue;
7012
7013 for (i = 0; i < sband->n_bitrates; i++) {
7014 if (sband->bitrates[i].bitrate == rateval) {
7015 mcast_rate[band] = i + 1;
7016 found = true;
7017 break;
7018 }
7019 }
7020 }
7021
7022 return found;
7023}
7024
Johannes Berg04a773a2009-04-19 21:24:32 +02007025static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7026{
Johannes Berg4c476992010-10-04 21:36:35 +02007027 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7028 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007029 struct cfg80211_ibss_params ibss;
7030 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007031 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007032 int err;
7033
Johannes Berg8e30bc52009-04-22 17:45:38 +02007034 memset(&ibss, 0, sizeof(ibss));
7035
Johannes Berg04a773a2009-04-19 21:24:32 +02007036 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7037 return -EINVAL;
7038
Johannes Berg683b6d32012-11-08 21:25:48 +01007039 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007040 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7041 return -EINVAL;
7042
Johannes Berg8e30bc52009-04-22 17:45:38 +02007043 ibss.beacon_interval = 100;
7044
7045 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7046 ibss.beacon_interval =
7047 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7048 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7049 return -EINVAL;
7050 }
7051
Johannes Berg4c476992010-10-04 21:36:35 +02007052 if (!rdev->ops->join_ibss)
7053 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007054
Johannes Berg4c476992010-10-04 21:36:35 +02007055 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7056 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007057
Johannes Berg79c97e92009-07-07 03:56:12 +02007058 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007059
Johannes Berg39193492011-09-16 13:45:25 +02007060 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007061 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007062
7063 if (!is_valid_ether_addr(ibss.bssid))
7064 return -EINVAL;
7065 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007066 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7067 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7068
7069 if (info->attrs[NL80211_ATTR_IE]) {
7070 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7071 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7072 }
7073
Johannes Berg683b6d32012-11-08 21:25:48 +01007074 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7075 if (err)
7076 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007077
Ilan Peer174e0cd2014-02-23 09:13:01 +02007078 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7079 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007080 return -EINVAL;
7081
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007082 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007083 case NL80211_CHAN_WIDTH_5:
7084 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007085 case NL80211_CHAN_WIDTH_20_NOHT:
7086 break;
7087 case NL80211_CHAN_WIDTH_20:
7088 case NL80211_CHAN_WIDTH_40:
7089 if (rdev->wiphy.features & NL80211_FEATURE_HT_IBSS)
7090 break;
7091 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007092 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007093 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007094
Johannes Berg04a773a2009-04-19 21:24:32 +02007095 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007096 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007097
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007098 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7099 u8 *rates =
7100 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7101 int n_rates =
7102 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7103 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007104 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007105
Johannes Berg34850ab2011-07-18 18:08:35 +02007106 err = ieee80211_get_ratemask(sband, rates, n_rates,
7107 &ibss.basic_rates);
7108 if (err)
7109 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007110 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007111
Simon Wunderlich803768f2013-06-28 10:39:58 +02007112 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7113 memcpy(&ibss.ht_capa_mask,
7114 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7115 sizeof(ibss.ht_capa_mask));
7116
7117 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7118 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7119 return -EINVAL;
7120 memcpy(&ibss.ht_capa,
7121 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7122 sizeof(ibss.ht_capa));
7123 }
7124
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007125 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7126 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7127 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7128 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007129
Johannes Berg4c476992010-10-04 21:36:35 +02007130 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307131 bool no_ht = false;
7132
Johannes Berg4c476992010-10-04 21:36:35 +02007133 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307134 info->attrs[NL80211_ATTR_KEYS],
7135 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007136 if (IS_ERR(connkeys))
7137 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307138
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007139 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7140 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307141 kfree(connkeys);
7142 return -EINVAL;
7143 }
Johannes Berg4c476992010-10-04 21:36:35 +02007144 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007145
Antonio Quartulli267335d2012-01-31 20:25:47 +01007146 ibss.control_port =
7147 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7148
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007149 ibss.userspace_handles_dfs =
7150 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7151
Johannes Berg4c476992010-10-04 21:36:35 +02007152 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007153 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007154 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007155 return err;
7156}
7157
7158static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7159{
Johannes Berg4c476992010-10-04 21:36:35 +02007160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7161 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007162
Johannes Berg4c476992010-10-04 21:36:35 +02007163 if (!rdev->ops->leave_ibss)
7164 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007165
Johannes Berg4c476992010-10-04 21:36:35 +02007166 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7167 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007168
Johannes Berg4c476992010-10-04 21:36:35 +02007169 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007170}
7171
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007172static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7173{
7174 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7175 struct net_device *dev = info->user_ptr[1];
7176 int mcast_rate[IEEE80211_NUM_BANDS];
7177 u32 nla_rate;
7178 int err;
7179
7180 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7181 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7182 return -EOPNOTSUPP;
7183
7184 if (!rdev->ops->set_mcast_rate)
7185 return -EOPNOTSUPP;
7186
7187 memset(mcast_rate, 0, sizeof(mcast_rate));
7188
7189 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7190 return -EINVAL;
7191
7192 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7193 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7194 return -EINVAL;
7195
7196 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7197
7198 return err;
7199}
7200
Johannes Bergad7e7182013-11-13 13:37:47 +01007201static struct sk_buff *
7202__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
7203 int approxlen, u32 portid, u32 seq,
7204 enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007205 enum nl80211_attrs attr,
7206 const struct nl80211_vendor_cmd_info *info,
7207 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007208{
7209 struct sk_buff *skb;
7210 void *hdr;
7211 struct nlattr *data;
7212
7213 skb = nlmsg_new(approxlen + 100, gfp);
7214 if (!skb)
7215 return NULL;
7216
7217 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7218 if (!hdr) {
7219 kfree_skb(skb);
7220 return NULL;
7221 }
7222
7223 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7224 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007225
7226 if (info) {
7227 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7228 info->vendor_id))
7229 goto nla_put_failure;
7230 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7231 info->subcmd))
7232 goto nla_put_failure;
7233 }
7234
Johannes Bergad7e7182013-11-13 13:37:47 +01007235 data = nla_nest_start(skb, attr);
7236
7237 ((void **)skb->cb)[0] = rdev;
7238 ((void **)skb->cb)[1] = hdr;
7239 ((void **)skb->cb)[2] = data;
7240
7241 return skb;
7242
7243 nla_put_failure:
7244 kfree_skb(skb);
7245 return NULL;
7246}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007247
Johannes Berge03ad6e2014-01-01 17:22:30 +01007248struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
7249 enum nl80211_commands cmd,
7250 enum nl80211_attrs attr,
7251 int vendor_event_idx,
7252 int approxlen, gfp_t gfp)
7253{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007254 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007255 const struct nl80211_vendor_cmd_info *info;
7256
7257 switch (cmd) {
7258 case NL80211_CMD_TESTMODE:
7259 if (WARN_ON(vendor_event_idx != -1))
7260 return NULL;
7261 info = NULL;
7262 break;
7263 case NL80211_CMD_VENDOR:
7264 if (WARN_ON(vendor_event_idx < 0 ||
7265 vendor_event_idx >= wiphy->n_vendor_events))
7266 return NULL;
7267 info = &wiphy->vendor_events[vendor_event_idx];
7268 break;
7269 default:
7270 WARN_ON(1);
7271 return NULL;
7272 }
7273
7274 return __cfg80211_alloc_vendor_skb(rdev, approxlen, 0, 0,
7275 cmd, attr, info, gfp);
7276}
7277EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7278
7279void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7280{
7281 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7282 void *hdr = ((void **)skb->cb)[1];
7283 struct nlattr *data = ((void **)skb->cb)[2];
7284 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7285
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007286 /* clear CB data for netlink core to own from now on */
7287 memset(skb->cb, 0, sizeof(skb->cb));
7288
Johannes Berge03ad6e2014-01-01 17:22:30 +01007289 nla_nest_end(skb, data);
7290 genlmsg_end(skb, hdr);
7291
7292 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7293 mcgrp = NL80211_MCGRP_VENDOR;
7294
7295 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7296 mcgrp, gfp);
7297}
7298EXPORT_SYMBOL(__cfg80211_send_event_skb);
7299
Johannes Bergaff89a92009-07-01 21:26:51 +02007300#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007301static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7302{
Johannes Berg4c476992010-10-04 21:36:35 +02007303 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007304 struct wireless_dev *wdev =
7305 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007306 int err;
7307
David Spinadelfc73f112013-07-31 18:04:15 +03007308 if (!rdev->ops->testmode_cmd)
7309 return -EOPNOTSUPP;
7310
7311 if (IS_ERR(wdev)) {
7312 err = PTR_ERR(wdev);
7313 if (err != -EINVAL)
7314 return err;
7315 wdev = NULL;
7316 } else if (wdev->wiphy != &rdev->wiphy) {
7317 return -EINVAL;
7318 }
7319
Johannes Bergaff89a92009-07-01 21:26:51 +02007320 if (!info->attrs[NL80211_ATTR_TESTDATA])
7321 return -EINVAL;
7322
Johannes Bergad7e7182013-11-13 13:37:47 +01007323 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007324 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007325 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7326 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007327 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007328
Johannes Bergaff89a92009-07-01 21:26:51 +02007329 return err;
7330}
7331
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007332static int nl80211_testmode_dump(struct sk_buff *skb,
7333 struct netlink_callback *cb)
7334{
Johannes Berg00918d32011-12-13 17:22:05 +01007335 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007336 int err;
7337 long phy_idx;
7338 void *data = NULL;
7339 int data_len = 0;
7340
Johannes Berg5fe231e2013-05-08 21:45:15 +02007341 rtnl_lock();
7342
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007343 if (cb->args[0]) {
7344 /*
7345 * 0 is a valid index, but not valid for args[0],
7346 * so we need to offset by 1.
7347 */
7348 phy_idx = cb->args[0] - 1;
7349 } else {
7350 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7351 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7352 nl80211_policy);
7353 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007354 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007355
Johannes Berg2bd7e352012-06-15 14:23:16 +02007356 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7357 nl80211_fam.attrbuf);
7358 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007359 err = PTR_ERR(rdev);
7360 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007361 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007362 phy_idx = rdev->wiphy_idx;
7363 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007364
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007365 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7366 cb->args[1] =
7367 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7368 }
7369
7370 if (cb->args[1]) {
7371 data = nla_data((void *)cb->args[1]);
7372 data_len = nla_len((void *)cb->args[1]);
7373 }
7374
Johannes Berg00918d32011-12-13 17:22:05 +01007375 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7376 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007377 err = -ENOENT;
7378 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007379 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007380
Johannes Berg00918d32011-12-13 17:22:05 +01007381 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007382 err = -EOPNOTSUPP;
7383 goto out_err;
7384 }
7385
7386 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007387 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007388 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7389 NL80211_CMD_TESTMODE);
7390 struct nlattr *tmdata;
7391
Dan Carpentercb35fba2013-08-14 14:50:01 +03007392 if (!hdr)
7393 break;
7394
David S. Miller9360ffd2012-03-29 04:41:26 -04007395 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007396 genlmsg_cancel(skb, hdr);
7397 break;
7398 }
7399
7400 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7401 if (!tmdata) {
7402 genlmsg_cancel(skb, hdr);
7403 break;
7404 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007405 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007406 nla_nest_end(skb, tmdata);
7407
7408 if (err == -ENOBUFS || err == -ENOENT) {
7409 genlmsg_cancel(skb, hdr);
7410 break;
7411 } else if (err) {
7412 genlmsg_cancel(skb, hdr);
7413 goto out_err;
7414 }
7415
7416 genlmsg_end(skb, hdr);
7417 }
7418
7419 err = skb->len;
7420 /* see above */
7421 cb->args[0] = phy_idx + 1;
7422 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007423 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007424 return err;
7425}
Johannes Bergaff89a92009-07-01 21:26:51 +02007426#endif
7427
Samuel Ortizb23aa672009-07-01 21:26:54 +02007428static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7429{
Johannes Berg4c476992010-10-04 21:36:35 +02007430 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7431 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007432 struct cfg80211_connect_params connect;
7433 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007434 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007435 int err;
7436
7437 memset(&connect, 0, sizeof(connect));
7438
7439 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7440 return -EINVAL;
7441
7442 if (!info->attrs[NL80211_ATTR_SSID] ||
7443 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7444 return -EINVAL;
7445
7446 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7447 connect.auth_type =
7448 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007449 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7450 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007451 return -EINVAL;
7452 } else
7453 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7454
7455 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7456
Johannes Bergc0692b82010-08-27 14:26:53 +03007457 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007458 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007459 if (err)
7460 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007461
Johannes Berg074ac8d2010-09-16 14:58:22 +02007462 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007463 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7464 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007465
Johannes Berg79c97e92009-07-07 03:56:12 +02007466 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007467
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307468 connect.bg_scan_period = -1;
7469 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7470 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7471 connect.bg_scan_period =
7472 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7473 }
7474
Samuel Ortizb23aa672009-07-01 21:26:54 +02007475 if (info->attrs[NL80211_ATTR_MAC])
7476 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007477 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7478 connect.bssid_hint =
7479 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007480 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7481 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7482
7483 if (info->attrs[NL80211_ATTR_IE]) {
7484 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7485 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7486 }
7487
Jouni Malinencee00a92013-01-15 17:15:57 +02007488 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7489 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7490 if (connect.mfp != NL80211_MFP_REQUIRED &&
7491 connect.mfp != NL80211_MFP_NO)
7492 return -EINVAL;
7493 } else {
7494 connect.mfp = NL80211_MFP_NO;
7495 }
7496
Samuel Ortizb23aa672009-07-01 21:26:54 +02007497 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007498 connect.channel = nl80211_get_valid_chan(
7499 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7500 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007501 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007502 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007503 connect.channel_hint = nl80211_get_valid_chan(
7504 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7505 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007506 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007507 }
7508
Johannes Bergfffd0932009-07-08 14:22:54 +02007509 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7510 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307511 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007512 if (IS_ERR(connkeys))
7513 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007514 }
7515
Ben Greear7e7c8922011-11-18 11:31:59 -08007516 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7517 connect.flags |= ASSOC_REQ_DISABLE_HT;
7518
7519 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7520 memcpy(&connect.ht_capa_mask,
7521 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7522 sizeof(connect.ht_capa_mask));
7523
7524 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007525 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007526 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007527 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007528 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007529 memcpy(&connect.ht_capa,
7530 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7531 sizeof(connect.ht_capa));
7532 }
7533
Johannes Bergee2aca32013-02-21 17:36:01 +01007534 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7535 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7536
7537 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7538 memcpy(&connect.vht_capa_mask,
7539 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7540 sizeof(connect.vht_capa_mask));
7541
7542 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7543 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007544 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007545 return -EINVAL;
7546 }
7547 memcpy(&connect.vht_capa,
7548 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7549 sizeof(connect.vht_capa));
7550 }
7551
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007552 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7553 if (!(rdev->wiphy.features &
7554 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7555 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7556 return -EINVAL;
7557 connect.flags |= ASSOC_REQ_USE_RRM;
7558 }
7559
Johannes Berg83739b02013-05-15 17:44:01 +02007560 wdev_lock(dev->ieee80211_ptr);
7561 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7562 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007563 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007564 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007565 return err;
7566}
7567
7568static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7569{
Johannes Berg4c476992010-10-04 21:36:35 +02007570 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7571 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007572 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007573 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007574
7575 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7576 reason = WLAN_REASON_DEAUTH_LEAVING;
7577 else
7578 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7579
7580 if (reason == 0)
7581 return -EINVAL;
7582
Johannes Berg074ac8d2010-09-16 14:58:22 +02007583 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007584 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7585 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007586
Johannes Berg83739b02013-05-15 17:44:01 +02007587 wdev_lock(dev->ieee80211_ptr);
7588 ret = cfg80211_disconnect(rdev, dev, reason, true);
7589 wdev_unlock(dev->ieee80211_ptr);
7590 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007591}
7592
Johannes Berg463d0182009-07-14 00:33:35 +02007593static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7594{
Johannes Berg4c476992010-10-04 21:36:35 +02007595 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007596 struct net *net;
7597 int err;
7598 u32 pid;
7599
7600 if (!info->attrs[NL80211_ATTR_PID])
7601 return -EINVAL;
7602
7603 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7604
Johannes Berg463d0182009-07-14 00:33:35 +02007605 net = get_net_ns_by_pid(pid);
Johannes Berg4c476992010-10-04 21:36:35 +02007606 if (IS_ERR(net))
7607 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007608
7609 err = 0;
7610
7611 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007612 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7613 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007614
Johannes Berg463d0182009-07-14 00:33:35 +02007615 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007616 return err;
7617}
7618
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007619static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7620{
Johannes Berg4c476992010-10-04 21:36:35 +02007621 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007622 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7623 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007624 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007625 struct cfg80211_pmksa pmksa;
7626
7627 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7628
7629 if (!info->attrs[NL80211_ATTR_MAC])
7630 return -EINVAL;
7631
7632 if (!info->attrs[NL80211_ATTR_PMKID])
7633 return -EINVAL;
7634
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007635 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7636 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7637
Johannes Berg074ac8d2010-09-16 14:58:22 +02007638 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007639 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7640 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007641
7642 switch (info->genlhdr->cmd) {
7643 case NL80211_CMD_SET_PMKSA:
7644 rdev_ops = rdev->ops->set_pmksa;
7645 break;
7646 case NL80211_CMD_DEL_PMKSA:
7647 rdev_ops = rdev->ops->del_pmksa;
7648 break;
7649 default:
7650 WARN_ON(1);
7651 break;
7652 }
7653
Johannes Berg4c476992010-10-04 21:36:35 +02007654 if (!rdev_ops)
7655 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007656
Johannes Berg4c476992010-10-04 21:36:35 +02007657 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007658}
7659
7660static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7661{
Johannes Berg4c476992010-10-04 21:36:35 +02007662 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7663 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007664
Johannes Berg074ac8d2010-09-16 14:58:22 +02007665 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007666 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7667 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007668
Johannes Berg4c476992010-10-04 21:36:35 +02007669 if (!rdev->ops->flush_pmksa)
7670 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007671
Hila Gonene35e4d22012-06-27 17:19:42 +03007672 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007673}
7674
Arik Nemtsov109086c2011-09-28 14:12:50 +03007675static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7676{
7677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7678 struct net_device *dev = info->user_ptr[1];
7679 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307680 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007681 u16 status_code;
7682 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007683 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007684
7685 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7686 !rdev->ops->tdls_mgmt)
7687 return -EOPNOTSUPP;
7688
7689 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7690 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7691 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7692 !info->attrs[NL80211_ATTR_IE] ||
7693 !info->attrs[NL80211_ATTR_MAC])
7694 return -EINVAL;
7695
7696 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7697 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7698 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7699 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007700 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307701 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7702 peer_capability =
7703 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007704
Hila Gonene35e4d22012-06-27 17:19:42 +03007705 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307706 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007707 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007708 nla_data(info->attrs[NL80211_ATTR_IE]),
7709 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007710}
7711
7712static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7713{
7714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7715 struct net_device *dev = info->user_ptr[1];
7716 enum nl80211_tdls_operation operation;
7717 u8 *peer;
7718
7719 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7720 !rdev->ops->tdls_oper)
7721 return -EOPNOTSUPP;
7722
7723 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7724 !info->attrs[NL80211_ATTR_MAC])
7725 return -EINVAL;
7726
7727 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7728 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7729
Hila Gonene35e4d22012-06-27 17:19:42 +03007730 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007731}
7732
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007733static int nl80211_remain_on_channel(struct sk_buff *skb,
7734 struct genl_info *info)
7735{
Johannes Berg4c476992010-10-04 21:36:35 +02007736 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007737 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007738 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007739 struct sk_buff *msg;
7740 void *hdr;
7741 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007742 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007743 int err;
7744
7745 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7746 !info->attrs[NL80211_ATTR_DURATION])
7747 return -EINVAL;
7748
7749 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7750
Johannes Berg7c4ef712011-11-18 15:33:48 +01007751 if (!rdev->ops->remain_on_channel ||
7752 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007753 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007754
Johannes Bergebf348f2012-06-01 12:50:54 +02007755 /*
7756 * We should be on that channel for at least a minimum amount of
7757 * time (10ms) but no longer than the driver supports.
7758 */
7759 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7760 duration > rdev->wiphy.max_remain_on_channel_duration)
7761 return -EINVAL;
7762
Johannes Berg683b6d32012-11-08 21:25:48 +01007763 err = nl80211_parse_chandef(rdev, info, &chandef);
7764 if (err)
7765 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007766
7767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007768 if (!msg)
7769 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007770
Eric W. Biederman15e47302012-09-07 20:12:54 +00007771 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007772 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007773 if (!hdr) {
7774 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007775 goto free_msg;
7776 }
7777
Johannes Berg683b6d32012-11-08 21:25:48 +01007778 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7779 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007780
7781 if (err)
7782 goto free_msg;
7783
David S. Miller9360ffd2012-03-29 04:41:26 -04007784 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
7785 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007786
7787 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02007788
7789 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007790
7791 nla_put_failure:
7792 err = -ENOBUFS;
7793 free_msg:
7794 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007795 return err;
7796}
7797
7798static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
7799 struct genl_info *info)
7800{
Johannes Berg4c476992010-10-04 21:36:35 +02007801 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007802 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007803 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007804
7805 if (!info->attrs[NL80211_ATTR_COOKIE])
7806 return -EINVAL;
7807
Johannes Berg4c476992010-10-04 21:36:35 +02007808 if (!rdev->ops->cancel_remain_on_channel)
7809 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007810
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007811 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
7812
Hila Gonene35e4d22012-06-27 17:19:42 +03007813 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007814}
7815
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007816static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
7817 u8 *rates, u8 rates_len)
7818{
7819 u8 i;
7820 u32 mask = 0;
7821
7822 for (i = 0; i < rates_len; i++) {
7823 int rate = (rates[i] & 0x7f) * 5;
7824 int ridx;
7825 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
7826 struct ieee80211_rate *srate =
7827 &sband->bitrates[ridx];
7828 if (rate == srate->bitrate) {
7829 mask |= 1 << ridx;
7830 break;
7831 }
7832 }
7833 if (ridx == sband->n_bitrates)
7834 return 0; /* rate not found */
7835 }
7836
7837 return mask;
7838}
7839
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007840static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
7841 u8 *rates, u8 rates_len,
7842 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
7843{
7844 u8 i;
7845
7846 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
7847
7848 for (i = 0; i < rates_len; i++) {
7849 int ridx, rbit;
7850
7851 ridx = rates[i] / 8;
7852 rbit = BIT(rates[i] % 8);
7853
7854 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03007855 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007856 return false;
7857
7858 /* check availability */
7859 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
7860 mcs[ridx] |= rbit;
7861 else
7862 return false;
7863 }
7864
7865 return true;
7866}
7867
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007868static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
7869{
7870 u16 mcs_mask = 0;
7871
7872 switch (vht_mcs_map) {
7873 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
7874 break;
7875 case IEEE80211_VHT_MCS_SUPPORT_0_7:
7876 mcs_mask = 0x00FF;
7877 break;
7878 case IEEE80211_VHT_MCS_SUPPORT_0_8:
7879 mcs_mask = 0x01FF;
7880 break;
7881 case IEEE80211_VHT_MCS_SUPPORT_0_9:
7882 mcs_mask = 0x03FF;
7883 break;
7884 default:
7885 break;
7886 }
7887
7888 return mcs_mask;
7889}
7890
7891static void vht_build_mcs_mask(u16 vht_mcs_map,
7892 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
7893{
7894 u8 nss;
7895
7896 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
7897 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
7898 vht_mcs_map >>= 2;
7899 }
7900}
7901
7902static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
7903 struct nl80211_txrate_vht *txrate,
7904 u16 mcs[NL80211_VHT_NSS_MAX])
7905{
7906 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7907 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
7908 u8 i;
7909
7910 if (!sband->vht_cap.vht_supported)
7911 return false;
7912
7913 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
7914
7915 /* Build vht_mcs_mask from VHT capabilities */
7916 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
7917
7918 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
7919 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
7920 mcs[i] = txrate->mcs[i];
7921 else
7922 return false;
7923 }
7924
7925 return true;
7926}
7927
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00007928static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007929 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
7930 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007931 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
7932 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007933 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01007934 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007935};
7936
7937static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
7938 struct genl_info *info)
7939{
7940 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02007941 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007942 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02007943 int rem, i;
7944 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007945 struct nlattr *tx_rates;
7946 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007947 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007948
Johannes Berg4c476992010-10-04 21:36:35 +02007949 if (!rdev->ops->set_bitrate_mask)
7950 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007951
7952 memset(&mask, 0, sizeof(mask));
7953 /* Default to all rates enabled */
7954 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
7955 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01007956
7957 if (!sband)
7958 continue;
7959
7960 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007961 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01007962 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01007963 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01007964
7965 if (!sband->vht_cap.vht_supported)
7966 continue;
7967
7968 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
7969 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007970 }
7971
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01007972 /* if no rates are given set it back to the defaults */
7973 if (!info->attrs[NL80211_ATTR_TX_RATES])
7974 goto out;
7975
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007976 /*
7977 * The nested attribute uses enum nl80211_band as the index. This maps
7978 * directly to the enum ieee80211_band values used in cfg80211.
7979 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01007980 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01007981 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007982 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01007983 int err;
7984
Johannes Berg4c476992010-10-04 21:36:35 +02007985 if (band < 0 || band >= IEEE80211_NUM_BANDS)
7986 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007987 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02007988 if (sband == NULL)
7989 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01007990 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
7991 nla_len(tx_rates), nl80211_txattr_policy);
7992 if (err)
7993 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02007994 if (tb[NL80211_TXRATE_LEGACY]) {
7995 mask.control[band].legacy = rateset_to_mask(
7996 sband,
7997 nla_data(tb[NL80211_TXRATE_LEGACY]),
7998 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05307999 if ((mask.control[band].legacy == 0) &&
8000 nla_len(tb[NL80211_TXRATE_LEGACY]))
8001 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008002 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008003 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008004 if (!ht_rateset_to_mask(
8005 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008006 nla_data(tb[NL80211_TXRATE_HT]),
8007 nla_len(tb[NL80211_TXRATE_HT]),
8008 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008009 return -EINVAL;
8010 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008011 if (tb[NL80211_TXRATE_VHT]) {
8012 if (!vht_set_mcs_mask(
8013 sband,
8014 nla_data(tb[NL80211_TXRATE_VHT]),
8015 mask.control[band].vht_mcs))
8016 return -EINVAL;
8017 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008018 if (tb[NL80211_TXRATE_GI]) {
8019 mask.control[band].gi =
8020 nla_get_u8(tb[NL80211_TXRATE_GI]);
8021 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8022 return -EINVAL;
8023 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008024
8025 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008026 /* don't allow empty legacy rates if HT or VHT
8027 * are not even supported.
8028 */
8029 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8030 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008031 return -EINVAL;
8032
8033 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008034 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008035 goto out;
8036
8037 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8038 if (mask.control[band].vht_mcs[i])
8039 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008040
8041 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008042 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008043 }
8044 }
8045
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008046out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008047 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008048}
8049
Johannes Berg2e161f72010-08-12 15:38:38 +02008050static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008051{
Johannes Berg4c476992010-10-04 21:36:35 +02008052 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008053 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008054 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008055
8056 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8057 return -EINVAL;
8058
Johannes Berg2e161f72010-08-12 15:38:38 +02008059 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8060 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008061
Johannes Berg71bbc992012-06-15 15:30:18 +02008062 switch (wdev->iftype) {
8063 case NL80211_IFTYPE_STATION:
8064 case NL80211_IFTYPE_ADHOC:
8065 case NL80211_IFTYPE_P2P_CLIENT:
8066 case NL80211_IFTYPE_AP:
8067 case NL80211_IFTYPE_AP_VLAN:
8068 case NL80211_IFTYPE_MESH_POINT:
8069 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008070 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008071 break;
8072 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008073 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008074 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008075
8076 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008077 if (!rdev->ops->mgmt_tx)
8078 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008079
Eric W. Biederman15e47302012-09-07 20:12:54 +00008080 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008081 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8082 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008083}
8084
Johannes Berg2e161f72010-08-12 15:38:38 +02008085static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008086{
Johannes Berg4c476992010-10-04 21:36:35 +02008087 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008088 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008089 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008090 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008091 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008092 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008093 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008094 struct cfg80211_mgmt_tx_params params = {
8095 .dont_wait_for_ack =
8096 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8097 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008098
Johannes Berg683b6d32012-11-08 21:25:48 +01008099 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008100 return -EINVAL;
8101
Johannes Berg4c476992010-10-04 21:36:35 +02008102 if (!rdev->ops->mgmt_tx)
8103 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008104
Johannes Berg71bbc992012-06-15 15:30:18 +02008105 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008106 case NL80211_IFTYPE_P2P_DEVICE:
8107 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8108 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008109 case NL80211_IFTYPE_STATION:
8110 case NL80211_IFTYPE_ADHOC:
8111 case NL80211_IFTYPE_P2P_CLIENT:
8112 case NL80211_IFTYPE_AP:
8113 case NL80211_IFTYPE_AP_VLAN:
8114 case NL80211_IFTYPE_MESH_POINT:
8115 case NL80211_IFTYPE_P2P_GO:
8116 break;
8117 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008118 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008119 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008120
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008121 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008122 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008123 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008124 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008125
8126 /*
8127 * We should wait on the channel for at least a minimum amount
8128 * of time (10ms) but no longer than the driver supports.
8129 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008130 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8131 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008132 return -EINVAL;
8133
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008134 }
8135
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008136 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008137
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008138 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008139 return -EINVAL;
8140
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008141 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308142
Antonio Quartulliea141b752013-06-11 14:20:03 +02008143 /* get the channel if any has been specified, otherwise pass NULL to
8144 * the driver. The latter will use the current one
8145 */
8146 chandef.chan = NULL;
8147 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8148 err = nl80211_parse_chandef(rdev, info, &chandef);
8149 if (err)
8150 return err;
8151 }
8152
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008153 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008154 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008155
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008156 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8157 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8158
8159 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8160 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8161 int i;
8162
8163 if (len % sizeof(u16))
8164 return -EINVAL;
8165
8166 params.n_csa_offsets = len / sizeof(u16);
8167 params.csa_offsets =
8168 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8169
8170 /* check that all the offsets fit the frame */
8171 for (i = 0; i < params.n_csa_offsets; i++) {
8172 if (params.csa_offsets[i] >= params.len)
8173 return -EINVAL;
8174 }
8175 }
8176
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008177 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008178 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8179 if (!msg)
8180 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008181
Eric W. Biederman15e47302012-09-07 20:12:54 +00008182 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008183 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008184 if (!hdr) {
8185 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008186 goto free_msg;
8187 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008188 }
Johannes Berge247bd902011-11-04 11:18:21 +01008189
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008190 params.chan = chandef.chan;
8191 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008192 if (err)
8193 goto free_msg;
8194
Johannes Berge247bd902011-11-04 11:18:21 +01008195 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008196 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8197 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008198
Johannes Berge247bd902011-11-04 11:18:21 +01008199 genlmsg_end(msg, hdr);
8200 return genlmsg_reply(msg, info);
8201 }
8202
8203 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008204
8205 nla_put_failure:
8206 err = -ENOBUFS;
8207 free_msg:
8208 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008209 return err;
8210}
8211
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008212static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8213{
8214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008215 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008216 u64 cookie;
8217
8218 if (!info->attrs[NL80211_ATTR_COOKIE])
8219 return -EINVAL;
8220
8221 if (!rdev->ops->mgmt_tx_cancel_wait)
8222 return -EOPNOTSUPP;
8223
Johannes Berg71bbc992012-06-15 15:30:18 +02008224 switch (wdev->iftype) {
8225 case NL80211_IFTYPE_STATION:
8226 case NL80211_IFTYPE_ADHOC:
8227 case NL80211_IFTYPE_P2P_CLIENT:
8228 case NL80211_IFTYPE_AP:
8229 case NL80211_IFTYPE_AP_VLAN:
8230 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008231 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008232 break;
8233 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008234 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008235 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008236
8237 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8238
Hila Gonene35e4d22012-06-27 17:19:42 +03008239 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008240}
8241
Kalle Valoffb9eb32010-02-17 17:58:10 +02008242static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8243{
Johannes Berg4c476992010-10-04 21:36:35 +02008244 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008245 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008246 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008247 u8 ps_state;
8248 bool state;
8249 int err;
8250
Johannes Berg4c476992010-10-04 21:36:35 +02008251 if (!info->attrs[NL80211_ATTR_PS_STATE])
8252 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008253
8254 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8255
Johannes Berg4c476992010-10-04 21:36:35 +02008256 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8257 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008258
8259 wdev = dev->ieee80211_ptr;
8260
Johannes Berg4c476992010-10-04 21:36:35 +02008261 if (!rdev->ops->set_power_mgmt)
8262 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008263
8264 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8265
8266 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008267 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008268
Hila Gonene35e4d22012-06-27 17:19:42 +03008269 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008270 if (!err)
8271 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008272 return err;
8273}
8274
8275static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8276{
Johannes Berg4c476992010-10-04 21:36:35 +02008277 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008278 enum nl80211_ps_state ps_state;
8279 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008280 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008281 struct sk_buff *msg;
8282 void *hdr;
8283 int err;
8284
Kalle Valoffb9eb32010-02-17 17:58:10 +02008285 wdev = dev->ieee80211_ptr;
8286
Johannes Berg4c476992010-10-04 21:36:35 +02008287 if (!rdev->ops->set_power_mgmt)
8288 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008289
8290 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008291 if (!msg)
8292 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008293
Eric W. Biederman15e47302012-09-07 20:12:54 +00008294 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008295 NL80211_CMD_GET_POWER_SAVE);
8296 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008297 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008298 goto free_msg;
8299 }
8300
8301 if (wdev->ps)
8302 ps_state = NL80211_PS_ENABLED;
8303 else
8304 ps_state = NL80211_PS_DISABLED;
8305
David S. Miller9360ffd2012-03-29 04:41:26 -04008306 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8307 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008308
8309 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008310 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008311
Johannes Berg4c476992010-10-04 21:36:35 +02008312 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008313 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008314 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008315 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008316 return err;
8317}
8318
Johannes Berg94e860f2014-01-20 23:58:15 +01008319static const struct nla_policy
8320nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008321 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8322 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8323 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008324 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8325 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8326 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008327};
8328
Thomas Pedersen84f10702012-07-12 16:17:33 -07008329static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008330 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008331{
8332 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008333 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008334 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008335
Johannes Bergd9d8b012012-11-26 12:51:52 +01008336 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008337 return -EINVAL;
8338
Thomas Pedersen84f10702012-07-12 16:17:33 -07008339 if (!rdev->ops->set_cqm_txe_config)
8340 return -EOPNOTSUPP;
8341
8342 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8343 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8344 return -EOPNOTSUPP;
8345
Hila Gonene35e4d22012-06-27 17:19:42 +03008346 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008347}
8348
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008349static int nl80211_set_cqm_rssi(struct genl_info *info,
8350 s32 threshold, u32 hysteresis)
8351{
Johannes Berg4c476992010-10-04 21:36:35 +02008352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008353 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008354 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008355
8356 if (threshold > 0)
8357 return -EINVAL;
8358
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008359 /* disabling - hysteresis should also be zero then */
8360 if (threshold == 0)
8361 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008362
Johannes Berg4c476992010-10-04 21:36:35 +02008363 if (!rdev->ops->set_cqm_rssi_config)
8364 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008365
Johannes Berg074ac8d2010-09-16 14:58:22 +02008366 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008367 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8368 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008369
Hila Gonene35e4d22012-06-27 17:19:42 +03008370 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008371}
8372
8373static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8374{
8375 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8376 struct nlattr *cqm;
8377 int err;
8378
8379 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008380 if (!cqm)
8381 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008382
8383 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8384 nl80211_attr_cqm_policy);
8385 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008386 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008387
8388 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8389 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008390 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8391 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008392
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008393 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8394 }
8395
8396 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8397 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8398 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8399 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8400 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8401 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8402
8403 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8404 }
8405
8406 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008407}
8408
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008409static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8410{
8411 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8412 struct net_device *dev = info->user_ptr[1];
8413 struct ocb_setup setup = {};
8414 int err;
8415
8416 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8417 if (err)
8418 return err;
8419
8420 return cfg80211_join_ocb(rdev, dev, &setup);
8421}
8422
8423static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8424{
8425 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8426 struct net_device *dev = info->user_ptr[1];
8427
8428 return cfg80211_leave_ocb(rdev, dev);
8429}
8430
Johannes Berg29cbe682010-12-03 09:20:44 +01008431static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8432{
8433 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8434 struct net_device *dev = info->user_ptr[1];
8435 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008436 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008437 int err;
8438
8439 /* start with default */
8440 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008441 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008442
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008443 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008444 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008445 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008446 if (err)
8447 return err;
8448 }
8449
8450 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8451 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8452 return -EINVAL;
8453
Javier Cardonac80d5452010-12-16 17:37:49 -08008454 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8455 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8456
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008457 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8458 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8459 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8460 return -EINVAL;
8461
Marco Porsch9bdbf042013-01-07 16:04:51 +01008462 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8463 setup.beacon_interval =
8464 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8465 if (setup.beacon_interval < 10 ||
8466 setup.beacon_interval > 10000)
8467 return -EINVAL;
8468 }
8469
8470 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8471 setup.dtim_period =
8472 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8473 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8474 return -EINVAL;
8475 }
8476
Javier Cardonac80d5452010-12-16 17:37:49 -08008477 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8478 /* parse additional setup parameters if given */
8479 err = nl80211_parse_mesh_setup(info, &setup);
8480 if (err)
8481 return err;
8482 }
8483
Thomas Pedersend37bb182013-03-04 13:06:13 -08008484 if (setup.user_mpm)
8485 cfg.auto_open_plinks = false;
8486
Johannes Bergcc1d2802012-05-16 23:50:20 +02008487 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008488 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8489 if (err)
8490 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008491 } else {
8492 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008493 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008494 }
8495
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008496 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8497 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8498 int n_rates =
8499 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8500 struct ieee80211_supported_band *sband;
8501
8502 if (!setup.chandef.chan)
8503 return -EINVAL;
8504
8505 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8506
8507 err = ieee80211_get_ratemask(sband, rates, n_rates,
8508 &setup.basic_rates);
8509 if (err)
8510 return err;
8511 }
8512
Javier Cardonac80d5452010-12-16 17:37:49 -08008513 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008514}
8515
8516static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8517{
8518 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8519 struct net_device *dev = info->user_ptr[1];
8520
8521 return cfg80211_leave_mesh(rdev, dev);
8522}
8523
Johannes Bergdfb89c52012-06-27 09:23:48 +02008524#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008525static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8526 struct cfg80211_registered_device *rdev)
8527{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008528 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008529 struct nlattr *nl_pats, *nl_pat;
8530 int i, pat_len;
8531
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008532 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008533 return 0;
8534
8535 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8536 if (!nl_pats)
8537 return -ENOBUFS;
8538
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008539 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008540 nl_pat = nla_nest_start(msg, i + 1);
8541 if (!nl_pat)
8542 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008543 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008544 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008545 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008546 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8547 wowlan->patterns[i].pattern) ||
8548 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008549 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008550 return -ENOBUFS;
8551 nla_nest_end(msg, nl_pat);
8552 }
8553 nla_nest_end(msg, nl_pats);
8554
8555 return 0;
8556}
8557
Johannes Berg2a0e0472013-01-23 22:57:40 +01008558static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8559 struct cfg80211_wowlan_tcp *tcp)
8560{
8561 struct nlattr *nl_tcp;
8562
8563 if (!tcp)
8564 return 0;
8565
8566 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8567 if (!nl_tcp)
8568 return -ENOBUFS;
8569
8570 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8571 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8572 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8573 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8574 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8575 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8576 tcp->payload_len, tcp->payload) ||
8577 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8578 tcp->data_interval) ||
8579 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8580 tcp->wake_len, tcp->wake_data) ||
8581 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8582 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8583 return -ENOBUFS;
8584
8585 if (tcp->payload_seq.len &&
8586 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8587 sizeof(tcp->payload_seq), &tcp->payload_seq))
8588 return -ENOBUFS;
8589
8590 if (tcp->payload_tok.len &&
8591 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8592 sizeof(tcp->payload_tok) + tcp->tokens_size,
8593 &tcp->payload_tok))
8594 return -ENOBUFS;
8595
Johannes Berge248ad32013-05-16 10:24:28 +02008596 nla_nest_end(msg, nl_tcp);
8597
Johannes Berg2a0e0472013-01-23 22:57:40 +01008598 return 0;
8599}
8600
Johannes Bergff1b6e62011-05-04 15:37:28 +02008601static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8602{
8603 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8604 struct sk_buff *msg;
8605 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008606 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008607
Johannes Berg964dc9e2013-06-03 17:25:34 +02008608 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008609 return -EOPNOTSUPP;
8610
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008611 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008612 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008613 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8614 rdev->wiphy.wowlan_config->tcp->payload_len +
8615 rdev->wiphy.wowlan_config->tcp->wake_len +
8616 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008617 }
8618
8619 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008620 if (!msg)
8621 return -ENOMEM;
8622
Eric W. Biederman15e47302012-09-07 20:12:54 +00008623 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008624 NL80211_CMD_GET_WOWLAN);
8625 if (!hdr)
8626 goto nla_put_failure;
8627
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008628 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008629 struct nlattr *nl_wowlan;
8630
8631 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8632 if (!nl_wowlan)
8633 goto nla_put_failure;
8634
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008635 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008636 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008637 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008638 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008639 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008640 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008641 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008642 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008643 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008644 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008645 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008646 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008647 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008648 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8649 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008650
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008651 if (nl80211_send_wowlan_patterns(msg, rdev))
8652 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008653
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008654 if (nl80211_send_wowlan_tcp(msg,
8655 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008656 goto nla_put_failure;
8657
Johannes Bergff1b6e62011-05-04 15:37:28 +02008658 nla_nest_end(msg, nl_wowlan);
8659 }
8660
8661 genlmsg_end(msg, hdr);
8662 return genlmsg_reply(msg, info);
8663
8664nla_put_failure:
8665 nlmsg_free(msg);
8666 return -ENOBUFS;
8667}
8668
Johannes Berg2a0e0472013-01-23 22:57:40 +01008669static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8670 struct nlattr *attr,
8671 struct cfg80211_wowlan *trig)
8672{
8673 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8674 struct cfg80211_wowlan_tcp *cfg;
8675 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8676 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8677 u32 size;
8678 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8679 int err, port;
8680
Johannes Berg964dc9e2013-06-03 17:25:34 +02008681 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008682 return -EINVAL;
8683
8684 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8685 nla_data(attr), nla_len(attr),
8686 nl80211_wowlan_tcp_policy);
8687 if (err)
8688 return err;
8689
8690 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8691 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8692 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8693 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8694 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8695 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8696 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8697 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8698 return -EINVAL;
8699
8700 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008701 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008702 return -EINVAL;
8703
8704 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008705 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008706 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008707 return -EINVAL;
8708
8709 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008710 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008711 return -EINVAL;
8712
8713 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8714 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8715 return -EINVAL;
8716
8717 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8718 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8719
8720 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8721 tokens_size = tokln - sizeof(*tok);
8722
8723 if (!tok->len || tokens_size % tok->len)
8724 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008725 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008726 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008727 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008728 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008729 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008730 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008731 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008732 return -EINVAL;
8733 if (tok->offset + tok->len > data_size)
8734 return -EINVAL;
8735 }
8736
8737 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
8738 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008739 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008740 return -EINVAL;
8741 if (seq->len == 0 || seq->len > 4)
8742 return -EINVAL;
8743 if (seq->len + seq->offset > data_size)
8744 return -EINVAL;
8745 }
8746
8747 size = sizeof(*cfg);
8748 size += data_size;
8749 size += wake_size + wake_mask_size;
8750 size += tokens_size;
8751
8752 cfg = kzalloc(size, GFP_KERNEL);
8753 if (!cfg)
8754 return -ENOMEM;
8755 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
8756 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
8757 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
8758 ETH_ALEN);
8759 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
8760 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
8761 else
8762 port = 0;
8763#ifdef CONFIG_INET
8764 /* allocate a socket and port for it and use it */
8765 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
8766 IPPROTO_TCP, &cfg->sock, 1);
8767 if (err) {
8768 kfree(cfg);
8769 return err;
8770 }
8771 if (inet_csk_get_port(cfg->sock->sk, port)) {
8772 sock_release(cfg->sock);
8773 kfree(cfg);
8774 return -EADDRINUSE;
8775 }
8776 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
8777#else
8778 if (!port) {
8779 kfree(cfg);
8780 return -EINVAL;
8781 }
8782 cfg->src_port = port;
8783#endif
8784
8785 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
8786 cfg->payload_len = data_size;
8787 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
8788 memcpy((void *)cfg->payload,
8789 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
8790 data_size);
8791 if (seq)
8792 cfg->payload_seq = *seq;
8793 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
8794 cfg->wake_len = wake_size;
8795 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
8796 memcpy((void *)cfg->wake_data,
8797 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
8798 wake_size);
8799 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
8800 data_size + wake_size;
8801 memcpy((void *)cfg->wake_mask,
8802 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
8803 wake_mask_size);
8804 if (tok) {
8805 cfg->tokens_size = tokens_size;
8806 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
8807 }
8808
8809 trig->tcp = cfg;
8810
8811 return 0;
8812}
8813
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008814static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
8815 const struct wiphy_wowlan_support *wowlan,
8816 struct nlattr *attr,
8817 struct cfg80211_wowlan *trig)
8818{
8819 struct nlattr **tb;
8820 int err;
8821
8822 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
8823 if (!tb)
8824 return -ENOMEM;
8825
8826 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
8827 err = -EOPNOTSUPP;
8828 goto out;
8829 }
8830
8831 err = nla_parse(tb, NL80211_ATTR_MAX,
8832 nla_data(attr), nla_len(attr),
8833 nl80211_policy);
8834 if (err)
8835 goto out;
8836
Johannes Bergad2b26a2014-06-12 21:39:05 +02008837 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008838 err = PTR_ERR_OR_ZERO(trig->nd_config);
8839 if (err)
8840 trig->nd_config = NULL;
8841
8842out:
8843 kfree(tb);
8844 return err;
8845}
8846
Johannes Bergff1b6e62011-05-04 15:37:28 +02008847static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
8848{
8849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8850 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008851 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02008852 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008853 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008854 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008855 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008856
Johannes Berg964dc9e2013-06-03 17:25:34 +02008857 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008858 return -EOPNOTSUPP;
8859
Johannes Bergae33bd82012-07-12 16:25:02 +02008860 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
8861 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008862 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02008863 goto set_wakeup;
8864 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02008865
8866 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
8867 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8868 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
8869 nl80211_wowlan_policy);
8870 if (err)
8871 return err;
8872
8873 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
8874 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
8875 return -EINVAL;
8876 new_triggers.any = true;
8877 }
8878
8879 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
8880 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
8881 return -EINVAL;
8882 new_triggers.disconnect = true;
8883 }
8884
8885 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
8886 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
8887 return -EINVAL;
8888 new_triggers.magic_pkt = true;
8889 }
8890
Johannes Berg77dbbb12011-07-13 10:48:55 +02008891 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
8892 return -EINVAL;
8893
8894 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
8895 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
8896 return -EINVAL;
8897 new_triggers.gtk_rekey_failure = true;
8898 }
8899
8900 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
8901 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
8902 return -EINVAL;
8903 new_triggers.eap_identity_req = true;
8904 }
8905
8906 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
8907 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
8908 return -EINVAL;
8909 new_triggers.four_way_handshake = true;
8910 }
8911
8912 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
8913 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
8914 return -EINVAL;
8915 new_triggers.rfkill_release = true;
8916 }
8917
Johannes Bergff1b6e62011-05-04 15:37:28 +02008918 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
8919 struct nlattr *pat;
8920 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008921 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008922 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02008923
8924 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8925 rem)
8926 n_patterns++;
8927 if (n_patterns > wowlan->n_patterns)
8928 return -EINVAL;
8929
8930 new_triggers.patterns = kcalloc(n_patterns,
8931 sizeof(new_triggers.patterns[0]),
8932 GFP_KERNEL);
8933 if (!new_triggers.patterns)
8934 return -ENOMEM;
8935
8936 new_triggers.n_patterns = n_patterns;
8937 i = 0;
8938
8939 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
8940 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02008941 u8 *mask_pat;
8942
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008943 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
8944 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008945 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008946 if (!pat_tb[NL80211_PKTPAT_MASK] ||
8947 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02008948 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008949 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008950 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008951 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008952 goto error;
8953 if (pat_len > wowlan->pattern_max_len ||
8954 pat_len < wowlan->pattern_min_len)
8955 goto error;
8956
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008957 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008958 pkt_offset = 0;
8959 else
8960 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008961 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008962 if (pkt_offset > wowlan->max_pkt_offset)
8963 goto error;
8964 new_triggers.patterns[i].pkt_offset = pkt_offset;
8965
Johannes Berg922bd802014-05-19 17:59:50 +02008966 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
8967 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008968 err = -ENOMEM;
8969 goto error;
8970 }
Johannes Berg922bd802014-05-19 17:59:50 +02008971 new_triggers.patterns[i].mask = mask_pat;
8972 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008973 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02008974 mask_pat += mask_len;
8975 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008976 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02008977 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008978 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02008979 pat_len);
8980 i++;
8981 }
8982 }
8983
Johannes Berg2a0e0472013-01-23 22:57:40 +01008984 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
8985 err = nl80211_parse_wowlan_tcp(
8986 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
8987 &new_triggers);
8988 if (err)
8989 goto error;
8990 }
8991
Luciano Coelho8cd4d452014-09-17 11:55:28 +03008992 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
8993 err = nl80211_parse_wowlan_nd(
8994 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
8995 &new_triggers);
8996 if (err)
8997 goto error;
8998 }
8999
Johannes Bergae33bd82012-07-12 16:25:02 +02009000 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9001 if (!ntrig) {
9002 err = -ENOMEM;
9003 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009004 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009005 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009006 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009007
Johannes Bergae33bd82012-07-12 16:25:02 +02009008 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009009 if (rdev->ops->set_wakeup &&
9010 prev_enabled != !!rdev->wiphy.wowlan_config)
9011 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009012
Johannes Bergff1b6e62011-05-04 15:37:28 +02009013 return 0;
9014 error:
9015 for (i = 0; i < new_triggers.n_patterns; i++)
9016 kfree(new_triggers.patterns[i].mask);
9017 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009018 if (new_triggers.tcp && new_triggers.tcp->sock)
9019 sock_release(new_triggers.tcp->sock);
9020 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009021 return err;
9022}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009023#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009024
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009025static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9026 struct cfg80211_registered_device *rdev)
9027{
9028 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9029 int i, j, pat_len;
9030 struct cfg80211_coalesce_rules *rule;
9031
9032 if (!rdev->coalesce->n_rules)
9033 return 0;
9034
9035 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9036 if (!nl_rules)
9037 return -ENOBUFS;
9038
9039 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9040 nl_rule = nla_nest_start(msg, i + 1);
9041 if (!nl_rule)
9042 return -ENOBUFS;
9043
9044 rule = &rdev->coalesce->rules[i];
9045 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9046 rule->delay))
9047 return -ENOBUFS;
9048
9049 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9050 rule->condition))
9051 return -ENOBUFS;
9052
9053 nl_pats = nla_nest_start(msg,
9054 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9055 if (!nl_pats)
9056 return -ENOBUFS;
9057
9058 for (j = 0; j < rule->n_patterns; j++) {
9059 nl_pat = nla_nest_start(msg, j + 1);
9060 if (!nl_pat)
9061 return -ENOBUFS;
9062 pat_len = rule->patterns[j].pattern_len;
9063 if (nla_put(msg, NL80211_PKTPAT_MASK,
9064 DIV_ROUND_UP(pat_len, 8),
9065 rule->patterns[j].mask) ||
9066 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9067 rule->patterns[j].pattern) ||
9068 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9069 rule->patterns[j].pkt_offset))
9070 return -ENOBUFS;
9071 nla_nest_end(msg, nl_pat);
9072 }
9073 nla_nest_end(msg, nl_pats);
9074 nla_nest_end(msg, nl_rule);
9075 }
9076 nla_nest_end(msg, nl_rules);
9077
9078 return 0;
9079}
9080
9081static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9082{
9083 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9084 struct sk_buff *msg;
9085 void *hdr;
9086
9087 if (!rdev->wiphy.coalesce)
9088 return -EOPNOTSUPP;
9089
9090 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9091 if (!msg)
9092 return -ENOMEM;
9093
9094 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9095 NL80211_CMD_GET_COALESCE);
9096 if (!hdr)
9097 goto nla_put_failure;
9098
9099 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9100 goto nla_put_failure;
9101
9102 genlmsg_end(msg, hdr);
9103 return genlmsg_reply(msg, info);
9104
9105nla_put_failure:
9106 nlmsg_free(msg);
9107 return -ENOBUFS;
9108}
9109
9110void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9111{
9112 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9113 int i, j;
9114 struct cfg80211_coalesce_rules *rule;
9115
9116 if (!coalesce)
9117 return;
9118
9119 for (i = 0; i < coalesce->n_rules; i++) {
9120 rule = &coalesce->rules[i];
9121 for (j = 0; j < rule->n_patterns; j++)
9122 kfree(rule->patterns[j].mask);
9123 kfree(rule->patterns);
9124 }
9125 kfree(coalesce->rules);
9126 kfree(coalesce);
9127 rdev->coalesce = NULL;
9128}
9129
9130static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9131 struct nlattr *rule,
9132 struct cfg80211_coalesce_rules *new_rule)
9133{
9134 int err, i;
9135 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9136 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9137 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9138 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9139
9140 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9141 nla_len(rule), nl80211_coalesce_policy);
9142 if (err)
9143 return err;
9144
9145 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9146 new_rule->delay =
9147 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9148 if (new_rule->delay > coalesce->max_delay)
9149 return -EINVAL;
9150
9151 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9152 new_rule->condition =
9153 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9154 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9155 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9156 return -EINVAL;
9157
9158 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9159 return -EINVAL;
9160
9161 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9162 rem)
9163 n_patterns++;
9164 if (n_patterns > coalesce->n_patterns)
9165 return -EINVAL;
9166
9167 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9168 GFP_KERNEL);
9169 if (!new_rule->patterns)
9170 return -ENOMEM;
9171
9172 new_rule->n_patterns = n_patterns;
9173 i = 0;
9174
9175 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9176 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009177 u8 *mask_pat;
9178
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009179 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9180 nla_len(pat), NULL);
9181 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9182 !pat_tb[NL80211_PKTPAT_PATTERN])
9183 return -EINVAL;
9184 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9185 mask_len = DIV_ROUND_UP(pat_len, 8);
9186 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9187 return -EINVAL;
9188 if (pat_len > coalesce->pattern_max_len ||
9189 pat_len < coalesce->pattern_min_len)
9190 return -EINVAL;
9191
9192 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9193 pkt_offset = 0;
9194 else
9195 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9196 if (pkt_offset > coalesce->max_pkt_offset)
9197 return -EINVAL;
9198 new_rule->patterns[i].pkt_offset = pkt_offset;
9199
Johannes Berg922bd802014-05-19 17:59:50 +02009200 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9201 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009202 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009203
9204 new_rule->patterns[i].mask = mask_pat;
9205 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9206 mask_len);
9207
9208 mask_pat += mask_len;
9209 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009210 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009211 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9212 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009213 i++;
9214 }
9215
9216 return 0;
9217}
9218
9219static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9220{
9221 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9222 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9223 struct cfg80211_coalesce new_coalesce = {};
9224 struct cfg80211_coalesce *n_coalesce;
9225 int err, rem_rule, n_rules = 0, i, j;
9226 struct nlattr *rule;
9227 struct cfg80211_coalesce_rules *tmp_rule;
9228
9229 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9230 return -EOPNOTSUPP;
9231
9232 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9233 cfg80211_rdev_free_coalesce(rdev);
9234 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9235 return 0;
9236 }
9237
9238 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9239 rem_rule)
9240 n_rules++;
9241 if (n_rules > coalesce->n_rules)
9242 return -EINVAL;
9243
9244 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9245 GFP_KERNEL);
9246 if (!new_coalesce.rules)
9247 return -ENOMEM;
9248
9249 new_coalesce.n_rules = n_rules;
9250 i = 0;
9251
9252 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9253 rem_rule) {
9254 err = nl80211_parse_coalesce_rule(rdev, rule,
9255 &new_coalesce.rules[i]);
9256 if (err)
9257 goto error;
9258
9259 i++;
9260 }
9261
9262 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9263 if (err)
9264 goto error;
9265
9266 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9267 if (!n_coalesce) {
9268 err = -ENOMEM;
9269 goto error;
9270 }
9271 cfg80211_rdev_free_coalesce(rdev);
9272 rdev->coalesce = n_coalesce;
9273
9274 return 0;
9275error:
9276 for (i = 0; i < new_coalesce.n_rules; i++) {
9277 tmp_rule = &new_coalesce.rules[i];
9278 for (j = 0; j < tmp_rule->n_patterns; j++)
9279 kfree(tmp_rule->patterns[j].mask);
9280 kfree(tmp_rule->patterns);
9281 }
9282 kfree(new_coalesce.rules);
9283
9284 return err;
9285}
9286
Johannes Berge5497d72011-07-05 16:35:40 +02009287static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9288{
9289 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9290 struct net_device *dev = info->user_ptr[1];
9291 struct wireless_dev *wdev = dev->ieee80211_ptr;
9292 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9293 struct cfg80211_gtk_rekey_data rekey_data;
9294 int err;
9295
9296 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9297 return -EINVAL;
9298
9299 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9300 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9301 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9302 nl80211_rekey_policy);
9303 if (err)
9304 return err;
9305
9306 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9307 return -ERANGE;
9308 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9309 return -ERANGE;
9310 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9311 return -ERANGE;
9312
Johannes Berg78f686c2014-09-10 22:28:06 +03009313 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9314 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9315 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009316
9317 wdev_lock(wdev);
9318 if (!wdev->current_bss) {
9319 err = -ENOTCONN;
9320 goto out;
9321 }
9322
9323 if (!rdev->ops->set_rekey_data) {
9324 err = -EOPNOTSUPP;
9325 goto out;
9326 }
9327
Hila Gonene35e4d22012-06-27 17:19:42 +03009328 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009329 out:
9330 wdev_unlock(wdev);
9331 return err;
9332}
9333
Johannes Berg28946da2011-11-04 11:18:12 +01009334static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9335 struct genl_info *info)
9336{
9337 struct net_device *dev = info->user_ptr[1];
9338 struct wireless_dev *wdev = dev->ieee80211_ptr;
9339
9340 if (wdev->iftype != NL80211_IFTYPE_AP &&
9341 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9342 return -EINVAL;
9343
Eric W. Biederman15e47302012-09-07 20:12:54 +00009344 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009345 return -EBUSY;
9346
Eric W. Biederman15e47302012-09-07 20:12:54 +00009347 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009348 return 0;
9349}
9350
Johannes Berg7f6cf312011-11-04 11:18:15 +01009351static int nl80211_probe_client(struct sk_buff *skb,
9352 struct genl_info *info)
9353{
9354 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9355 struct net_device *dev = info->user_ptr[1];
9356 struct wireless_dev *wdev = dev->ieee80211_ptr;
9357 struct sk_buff *msg;
9358 void *hdr;
9359 const u8 *addr;
9360 u64 cookie;
9361 int err;
9362
9363 if (wdev->iftype != NL80211_IFTYPE_AP &&
9364 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9365 return -EOPNOTSUPP;
9366
9367 if (!info->attrs[NL80211_ATTR_MAC])
9368 return -EINVAL;
9369
9370 if (!rdev->ops->probe_client)
9371 return -EOPNOTSUPP;
9372
9373 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9374 if (!msg)
9375 return -ENOMEM;
9376
Eric W. Biederman15e47302012-09-07 20:12:54 +00009377 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009378 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009379 if (!hdr) {
9380 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009381 goto free_msg;
9382 }
9383
9384 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9385
Hila Gonene35e4d22012-06-27 17:19:42 +03009386 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009387 if (err)
9388 goto free_msg;
9389
David S. Miller9360ffd2012-03-29 04:41:26 -04009390 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9391 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009392
9393 genlmsg_end(msg, hdr);
9394
9395 return genlmsg_reply(msg, info);
9396
9397 nla_put_failure:
9398 err = -ENOBUFS;
9399 free_msg:
9400 nlmsg_free(msg);
9401 return err;
9402}
9403
Johannes Berg5e760232011-11-04 11:18:17 +01009404static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9405{
9406 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009407 struct cfg80211_beacon_registration *reg, *nreg;
9408 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009409
9410 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9411 return -EOPNOTSUPP;
9412
Ben Greear37c73b52012-10-26 14:49:25 -07009413 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9414 if (!nreg)
9415 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009416
Ben Greear37c73b52012-10-26 14:49:25 -07009417 /* First, check if already registered. */
9418 spin_lock_bh(&rdev->beacon_registrations_lock);
9419 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9420 if (reg->nlportid == info->snd_portid) {
9421 rv = -EALREADY;
9422 goto out_err;
9423 }
9424 }
9425 /* Add it to the list */
9426 nreg->nlportid = info->snd_portid;
9427 list_add(&nreg->list, &rdev->beacon_registrations);
9428
9429 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009430
9431 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009432out_err:
9433 spin_unlock_bh(&rdev->beacon_registrations_lock);
9434 kfree(nreg);
9435 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009436}
9437
Johannes Berg98104fde2012-06-16 00:19:54 +02009438static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9439{
9440 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9441 struct wireless_dev *wdev = info->user_ptr[1];
9442 int err;
9443
9444 if (!rdev->ops->start_p2p_device)
9445 return -EOPNOTSUPP;
9446
9447 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9448 return -EOPNOTSUPP;
9449
9450 if (wdev->p2p_started)
9451 return 0;
9452
Luciano Coelhob6a55012014-02-27 11:07:21 +02009453 if (rfkill_blocked(rdev->rfkill))
9454 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009455
Johannes Bergeeb126e2012-10-23 15:16:50 +02009456 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009457 if (err)
9458 return err;
9459
9460 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009461 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009462
9463 return 0;
9464}
9465
9466static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9467{
9468 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9469 struct wireless_dev *wdev = info->user_ptr[1];
9470
9471 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9472 return -EOPNOTSUPP;
9473
9474 if (!rdev->ops->stop_p2p_device)
9475 return -EOPNOTSUPP;
9476
Johannes Bergf9f47522013-03-19 15:04:07 +01009477 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009478
9479 return 0;
9480}
9481
Johannes Berg3713b4e2013-02-14 16:19:38 +01009482static int nl80211_get_protocol_features(struct sk_buff *skb,
9483 struct genl_info *info)
9484{
9485 void *hdr;
9486 struct sk_buff *msg;
9487
9488 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9489 if (!msg)
9490 return -ENOMEM;
9491
9492 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9493 NL80211_CMD_GET_PROTOCOL_FEATURES);
9494 if (!hdr)
9495 goto nla_put_failure;
9496
9497 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9498 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9499 goto nla_put_failure;
9500
9501 genlmsg_end(msg, hdr);
9502 return genlmsg_reply(msg, info);
9503
9504 nla_put_failure:
9505 kfree_skb(msg);
9506 return -ENOBUFS;
9507}
9508
Jouni Malinen355199e2013-02-27 17:14:27 +02009509static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9510{
9511 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9512 struct cfg80211_update_ft_ies_params ft_params;
9513 struct net_device *dev = info->user_ptr[1];
9514
9515 if (!rdev->ops->update_ft_ies)
9516 return -EOPNOTSUPP;
9517
9518 if (!info->attrs[NL80211_ATTR_MDID] ||
9519 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9520 return -EINVAL;
9521
9522 memset(&ft_params, 0, sizeof(ft_params));
9523 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9524 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9525 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9526
9527 return rdev_update_ft_ies(rdev, dev, &ft_params);
9528}
9529
Arend van Spriel5de17982013-04-18 15:49:00 +02009530static int nl80211_crit_protocol_start(struct sk_buff *skb,
9531 struct genl_info *info)
9532{
9533 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9534 struct wireless_dev *wdev = info->user_ptr[1];
9535 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9536 u16 duration;
9537 int ret;
9538
9539 if (!rdev->ops->crit_proto_start)
9540 return -EOPNOTSUPP;
9541
9542 if (WARN_ON(!rdev->ops->crit_proto_stop))
9543 return -EINVAL;
9544
9545 if (rdev->crit_proto_nlportid)
9546 return -EBUSY;
9547
9548 /* determine protocol if provided */
9549 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9550 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9551
9552 if (proto >= NUM_NL80211_CRIT_PROTO)
9553 return -EINVAL;
9554
9555 /* timeout must be provided */
9556 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9557 return -EINVAL;
9558
9559 duration =
9560 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9561
9562 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9563 return -ERANGE;
9564
9565 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9566 if (!ret)
9567 rdev->crit_proto_nlportid = info->snd_portid;
9568
9569 return ret;
9570}
9571
9572static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9573 struct genl_info *info)
9574{
9575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9576 struct wireless_dev *wdev = info->user_ptr[1];
9577
9578 if (!rdev->ops->crit_proto_stop)
9579 return -EOPNOTSUPP;
9580
9581 if (rdev->crit_proto_nlportid) {
9582 rdev->crit_proto_nlportid = 0;
9583 rdev_crit_proto_stop(rdev, wdev);
9584 }
9585 return 0;
9586}
9587
Johannes Bergad7e7182013-11-13 13:37:47 +01009588static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9589{
9590 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9591 struct wireless_dev *wdev =
9592 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9593 int i, err;
9594 u32 vid, subcmd;
9595
9596 if (!rdev->wiphy.vendor_commands)
9597 return -EOPNOTSUPP;
9598
9599 if (IS_ERR(wdev)) {
9600 err = PTR_ERR(wdev);
9601 if (err != -EINVAL)
9602 return err;
9603 wdev = NULL;
9604 } else if (wdev->wiphy != &rdev->wiphy) {
9605 return -EINVAL;
9606 }
9607
9608 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9609 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9610 return -EINVAL;
9611
9612 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9613 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9614 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9615 const struct wiphy_vendor_command *vcmd;
9616 void *data = NULL;
9617 int len = 0;
9618
9619 vcmd = &rdev->wiphy.vendor_commands[i];
9620
9621 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9622 continue;
9623
9624 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9625 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9626 if (!wdev)
9627 return -EINVAL;
9628 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9629 !wdev->netdev)
9630 return -EINVAL;
9631
9632 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9633 if (wdev->netdev &&
9634 !netif_running(wdev->netdev))
9635 return -ENETDOWN;
9636 if (!wdev->netdev && !wdev->p2p_started)
9637 return -ENETDOWN;
9638 }
9639 } else {
9640 wdev = NULL;
9641 }
9642
9643 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9644 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9645 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9646 }
9647
9648 rdev->cur_cmd_info = info;
9649 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9650 data, len);
9651 rdev->cur_cmd_info = NULL;
9652 return err;
9653 }
9654
9655 return -EOPNOTSUPP;
9656}
9657
9658struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9659 enum nl80211_commands cmd,
9660 enum nl80211_attrs attr,
9661 int approxlen)
9662{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009663 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009664
9665 if (WARN_ON(!rdev->cur_cmd_info))
9666 return NULL;
9667
9668 return __cfg80211_alloc_vendor_skb(rdev, approxlen,
9669 rdev->cur_cmd_info->snd_portid,
9670 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009671 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009672}
9673EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9674
9675int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9676{
9677 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9678 void *hdr = ((void **)skb->cb)[1];
9679 struct nlattr *data = ((void **)skb->cb)[2];
9680
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009681 /* clear CB data for netlink core to own from now on */
9682 memset(skb->cb, 0, sizeof(skb->cb));
9683
Johannes Bergad7e7182013-11-13 13:37:47 +01009684 if (WARN_ON(!rdev->cur_cmd_info)) {
9685 kfree_skb(skb);
9686 return -EINVAL;
9687 }
9688
9689 nla_nest_end(skb, data);
9690 genlmsg_end(skb, hdr);
9691 return genlmsg_reply(skb, rdev->cur_cmd_info);
9692}
9693EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9694
9695
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009696static int nl80211_set_qos_map(struct sk_buff *skb,
9697 struct genl_info *info)
9698{
9699 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9700 struct cfg80211_qos_map *qos_map = NULL;
9701 struct net_device *dev = info->user_ptr[1];
9702 u8 *pos, len, num_des, des_len, des;
9703 int ret;
9704
9705 if (!rdev->ops->set_qos_map)
9706 return -EOPNOTSUPP;
9707
9708 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9709 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9710 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9711
9712 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9713 len > IEEE80211_QOS_MAP_LEN_MAX)
9714 return -EINVAL;
9715
9716 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
9717 if (!qos_map)
9718 return -ENOMEM;
9719
9720 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
9721 if (num_des) {
9722 des_len = num_des *
9723 sizeof(struct cfg80211_dscp_exception);
9724 memcpy(qos_map->dscp_exception, pos, des_len);
9725 qos_map->num_des = num_des;
9726 for (des = 0; des < num_des; des++) {
9727 if (qos_map->dscp_exception[des].up > 7) {
9728 kfree(qos_map);
9729 return -EINVAL;
9730 }
9731 }
9732 pos += des_len;
9733 }
9734 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
9735 }
9736
9737 wdev_lock(dev->ieee80211_ptr);
9738 ret = nl80211_key_allowed(dev->ieee80211_ptr);
9739 if (!ret)
9740 ret = rdev_set_qos_map(rdev, dev, qos_map);
9741 wdev_unlock(dev->ieee80211_ptr);
9742
9743 kfree(qos_map);
9744 return ret;
9745}
9746
Johannes Berg960d01a2014-09-09 22:55:35 +03009747static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
9748{
9749 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9750 struct net_device *dev = info->user_ptr[1];
9751 struct wireless_dev *wdev = dev->ieee80211_ptr;
9752 const u8 *peer;
9753 u8 tsid, up;
9754 u16 admitted_time = 0;
9755 int err;
9756
Johannes Berg723e73a2014-10-22 09:25:06 +02009757 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +03009758 return -EOPNOTSUPP;
9759
9760 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
9761 !info->attrs[NL80211_ATTR_USER_PRIO])
9762 return -EINVAL;
9763
9764 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9765 if (tsid >= IEEE80211_NUM_TIDS)
9766 return -EINVAL;
9767
9768 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
9769 if (up >= IEEE80211_NUM_UPS)
9770 return -EINVAL;
9771
9772 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +02009773 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +03009774 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +02009775 * need more attributes for that (e.g. BA session requirement);
9776 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +03009777 */
9778 return -EINVAL;
9779 }
9780
9781 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9782
9783 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
9784 admitted_time =
9785 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
9786 if (!admitted_time)
9787 return -EINVAL;
9788 }
9789
9790 wdev_lock(wdev);
9791 switch (wdev->iftype) {
9792 case NL80211_IFTYPE_STATION:
9793 case NL80211_IFTYPE_P2P_CLIENT:
9794 if (wdev->current_bss)
9795 break;
9796 err = -ENOTCONN;
9797 goto out;
9798 default:
9799 err = -EOPNOTSUPP;
9800 goto out;
9801 }
9802
9803 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
9804
9805 out:
9806 wdev_unlock(wdev);
9807 return err;
9808}
9809
9810static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
9811{
9812 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9813 struct net_device *dev = info->user_ptr[1];
9814 struct wireless_dev *wdev = dev->ieee80211_ptr;
9815 const u8 *peer;
9816 u8 tsid;
9817 int err;
9818
9819 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
9820 return -EINVAL;
9821
9822 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
9823 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
9824
9825 wdev_lock(wdev);
9826 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
9827 wdev_unlock(wdev);
9828
9829 return err;
9830}
9831
Arik Nemtsov1057d352014-11-19 12:54:26 +02009832static int nl80211_tdls_channel_switch(struct sk_buff *skb,
9833 struct genl_info *info)
9834{
9835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9836 struct net_device *dev = info->user_ptr[1];
9837 struct wireless_dev *wdev = dev->ieee80211_ptr;
9838 struct cfg80211_chan_def chandef = {};
9839 const u8 *addr;
9840 u8 oper_class;
9841 int err;
9842
9843 if (!rdev->ops->tdls_channel_switch ||
9844 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9845 return -EOPNOTSUPP;
9846
9847 switch (dev->ieee80211_ptr->iftype) {
9848 case NL80211_IFTYPE_STATION:
9849 case NL80211_IFTYPE_P2P_CLIENT:
9850 break;
9851 default:
9852 return -EOPNOTSUPP;
9853 }
9854
9855 if (!info->attrs[NL80211_ATTR_MAC] ||
9856 !info->attrs[NL80211_ATTR_OPER_CLASS])
9857 return -EINVAL;
9858
9859 err = nl80211_parse_chandef(rdev, info, &chandef);
9860 if (err)
9861 return err;
9862
9863 /*
9864 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
9865 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
9866 * specification is not defined for them.
9867 */
9868 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
9869 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
9870 chandef.width != NL80211_CHAN_WIDTH_20)
9871 return -EINVAL;
9872
9873 /* we will be active on the TDLS link */
9874 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
9875 return -EINVAL;
9876
9877 /* don't allow switching to DFS channels */
9878 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
9879 return -EINVAL;
9880
9881 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9882 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
9883
9884 wdev_lock(wdev);
9885 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
9886 wdev_unlock(wdev);
9887
9888 return err;
9889}
9890
9891static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
9892 struct genl_info *info)
9893{
9894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9895 struct net_device *dev = info->user_ptr[1];
9896 struct wireless_dev *wdev = dev->ieee80211_ptr;
9897 const u8 *addr;
9898
9899 if (!rdev->ops->tdls_channel_switch ||
9900 !rdev->ops->tdls_cancel_channel_switch ||
9901 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
9902 return -EOPNOTSUPP;
9903
9904 switch (dev->ieee80211_ptr->iftype) {
9905 case NL80211_IFTYPE_STATION:
9906 case NL80211_IFTYPE_P2P_CLIENT:
9907 break;
9908 default:
9909 return -EOPNOTSUPP;
9910 }
9911
9912 if (!info->attrs[NL80211_ATTR_MAC])
9913 return -EINVAL;
9914
9915 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9916
9917 wdev_lock(wdev);
9918 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
9919 wdev_unlock(wdev);
9920
9921 return 0;
9922}
9923
Johannes Berg4c476992010-10-04 21:36:35 +02009924#define NL80211_FLAG_NEED_WIPHY 0x01
9925#define NL80211_FLAG_NEED_NETDEV 0x02
9926#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +02009927#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
9928#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
9929 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +02009930#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +02009931/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +02009932#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
9933 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +03009934#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +02009935
Johannes Bergf84f7712013-11-14 17:14:45 +01009936static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +02009937 struct genl_info *info)
9938{
9939 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +02009940 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02009941 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +02009942 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
9943
9944 if (rtnl)
9945 rtnl_lock();
9946
9947 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +02009948 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +02009949 if (IS_ERR(rdev)) {
9950 if (rtnl)
9951 rtnl_unlock();
9952 return PTR_ERR(rdev);
9953 }
9954 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +02009955 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
9956 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02009957 ASSERT_RTNL();
9958
Johannes Berg89a54e42012-06-15 14:33:17 +02009959 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
9960 info->attrs);
9961 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +02009962 if (rtnl)
9963 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +02009964 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +02009965 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009966
Johannes Berg89a54e42012-06-15 14:33:17 +02009967 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009968 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +02009969
Johannes Berg1bf614e2012-06-15 15:23:36 +02009970 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
9971 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009972 if (rtnl)
9973 rtnl_unlock();
9974 return -EINVAL;
9975 }
9976
9977 info->user_ptr[1] = dev;
9978 } else {
9979 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +02009980 }
Johannes Berg89a54e42012-06-15 14:33:17 +02009981
Johannes Berg1bf614e2012-06-15 15:23:36 +02009982 if (dev) {
9983 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
9984 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +02009985 if (rtnl)
9986 rtnl_unlock();
9987 return -ENETDOWN;
9988 }
9989
9990 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009991 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
9992 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +02009993 if (rtnl)
9994 rtnl_unlock();
9995 return -ENETDOWN;
9996 }
Johannes Berg1bf614e2012-06-15 15:23:36 +02009997 }
9998
Johannes Berg4c476992010-10-04 21:36:35 +02009999 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010000 }
10001
10002 return 0;
10003}
10004
Johannes Bergf84f7712013-11-14 17:14:45 +010010005static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010006 struct genl_info *info)
10007{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010008 if (info->user_ptr[1]) {
10009 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10010 struct wireless_dev *wdev = info->user_ptr[1];
10011
10012 if (wdev->netdev)
10013 dev_put(wdev->netdev);
10014 } else {
10015 dev_put(info->user_ptr[1]);
10016 }
10017 }
Johannes Berg5393b912014-09-10 15:00:16 +030010018
Johannes Berg4c476992010-10-04 21:36:35 +020010019 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10020 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010021
10022 /* If needed, clear the netlink message payload from the SKB
10023 * as it might contain key data that shouldn't stick around on
10024 * the heap after the SKB is freed. The netlink message header
10025 * is still needed for further processing, so leave it intact.
10026 */
10027 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10028 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10029
10030 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10031 }
Johannes Berg4c476992010-10-04 21:36:35 +020010032}
10033
Johannes Berg4534de82013-11-14 17:14:46 +010010034static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010035 {
10036 .cmd = NL80211_CMD_GET_WIPHY,
10037 .doit = nl80211_get_wiphy,
10038 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010039 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010040 .policy = nl80211_policy,
10041 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010042 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10043 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010044 },
10045 {
10046 .cmd = NL80211_CMD_SET_WIPHY,
10047 .doit = nl80211_set_wiphy,
10048 .policy = nl80211_policy,
10049 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010050 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010051 },
10052 {
10053 .cmd = NL80211_CMD_GET_INTERFACE,
10054 .doit = nl80211_get_interface,
10055 .dumpit = nl80211_dump_interface,
10056 .policy = nl80211_policy,
10057 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010058 .internal_flags = NL80211_FLAG_NEED_WDEV |
10059 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010060 },
10061 {
10062 .cmd = NL80211_CMD_SET_INTERFACE,
10063 .doit = nl80211_set_interface,
10064 .policy = nl80211_policy,
10065 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010066 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10067 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010068 },
10069 {
10070 .cmd = NL80211_CMD_NEW_INTERFACE,
10071 .doit = nl80211_new_interface,
10072 .policy = nl80211_policy,
10073 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010074 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10075 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010076 },
10077 {
10078 .cmd = NL80211_CMD_DEL_INTERFACE,
10079 .doit = nl80211_del_interface,
10080 .policy = nl80211_policy,
10081 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010082 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010083 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010084 },
Johannes Berg41ade002007-12-19 02:03:29 +010010085 {
10086 .cmd = NL80211_CMD_GET_KEY,
10087 .doit = nl80211_get_key,
10088 .policy = nl80211_policy,
10089 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010090 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010091 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010092 },
10093 {
10094 .cmd = NL80211_CMD_SET_KEY,
10095 .doit = nl80211_set_key,
10096 .policy = nl80211_policy,
10097 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010098 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010099 NL80211_FLAG_NEED_RTNL |
10100 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010101 },
10102 {
10103 .cmd = NL80211_CMD_NEW_KEY,
10104 .doit = nl80211_new_key,
10105 .policy = nl80211_policy,
10106 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010107 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010108 NL80211_FLAG_NEED_RTNL |
10109 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010110 },
10111 {
10112 .cmd = NL80211_CMD_DEL_KEY,
10113 .doit = nl80211_del_key,
10114 .policy = nl80211_policy,
10115 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010116 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010117 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010118 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010119 {
10120 .cmd = NL80211_CMD_SET_BEACON,
10121 .policy = nl80211_policy,
10122 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010123 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010124 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010125 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010126 },
10127 {
Johannes Berg88600202012-02-13 15:17:18 +010010128 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010129 .policy = nl80211_policy,
10130 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010131 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010132 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010133 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010134 },
10135 {
Johannes Berg88600202012-02-13 15:17:18 +010010136 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010137 .policy = nl80211_policy,
10138 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010139 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010140 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010141 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010142 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010143 {
10144 .cmd = NL80211_CMD_GET_STATION,
10145 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010146 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010147 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010148 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10149 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010150 },
10151 {
10152 .cmd = NL80211_CMD_SET_STATION,
10153 .doit = nl80211_set_station,
10154 .policy = nl80211_policy,
10155 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010156 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010157 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010158 },
10159 {
10160 .cmd = NL80211_CMD_NEW_STATION,
10161 .doit = nl80211_new_station,
10162 .policy = nl80211_policy,
10163 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010164 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010165 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010166 },
10167 {
10168 .cmd = NL80211_CMD_DEL_STATION,
10169 .doit = nl80211_del_station,
10170 .policy = nl80211_policy,
10171 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010172 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010173 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010174 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010175 {
10176 .cmd = NL80211_CMD_GET_MPATH,
10177 .doit = nl80211_get_mpath,
10178 .dumpit = nl80211_dump_mpath,
10179 .policy = nl80211_policy,
10180 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010181 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010182 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010183 },
10184 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010185 .cmd = NL80211_CMD_GET_MPP,
10186 .doit = nl80211_get_mpp,
10187 .dumpit = nl80211_dump_mpp,
10188 .policy = nl80211_policy,
10189 .flags = GENL_ADMIN_PERM,
10190 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10191 NL80211_FLAG_NEED_RTNL,
10192 },
10193 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010194 .cmd = NL80211_CMD_SET_MPATH,
10195 .doit = nl80211_set_mpath,
10196 .policy = nl80211_policy,
10197 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010198 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010199 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010200 },
10201 {
10202 .cmd = NL80211_CMD_NEW_MPATH,
10203 .doit = nl80211_new_mpath,
10204 .policy = nl80211_policy,
10205 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010206 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010207 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010208 },
10209 {
10210 .cmd = NL80211_CMD_DEL_MPATH,
10211 .doit = nl80211_del_mpath,
10212 .policy = nl80211_policy,
10213 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010214 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010215 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010216 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010217 {
10218 .cmd = NL80211_CMD_SET_BSS,
10219 .doit = nl80211_set_bss,
10220 .policy = nl80211_policy,
10221 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010222 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010223 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010224 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010225 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010226 .cmd = NL80211_CMD_GET_REG,
10227 .doit = nl80211_get_reg,
10228 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010229 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010230 /* can be retrieved by unprivileged users */
10231 },
10232 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010233 .cmd = NL80211_CMD_SET_REG,
10234 .doit = nl80211_set_reg,
10235 .policy = nl80211_policy,
10236 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010237 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010238 },
10239 {
10240 .cmd = NL80211_CMD_REQ_SET_REG,
10241 .doit = nl80211_req_set_reg,
10242 .policy = nl80211_policy,
10243 .flags = GENL_ADMIN_PERM,
10244 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010245 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010246 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10247 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010248 .policy = nl80211_policy,
10249 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010250 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010251 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010252 },
10253 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010254 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10255 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010256 .policy = nl80211_policy,
10257 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010258 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010259 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010260 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010261 {
Johannes Berg2a519312009-02-10 21:25:55 +010010262 .cmd = NL80211_CMD_TRIGGER_SCAN,
10263 .doit = nl80211_trigger_scan,
10264 .policy = nl80211_policy,
10265 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010266 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010267 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010268 },
10269 {
10270 .cmd = NL80211_CMD_GET_SCAN,
10271 .policy = nl80211_policy,
10272 .dumpit = nl80211_dump_scan,
10273 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010274 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010275 .cmd = NL80211_CMD_START_SCHED_SCAN,
10276 .doit = nl80211_start_sched_scan,
10277 .policy = nl80211_policy,
10278 .flags = GENL_ADMIN_PERM,
10279 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10280 NL80211_FLAG_NEED_RTNL,
10281 },
10282 {
10283 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10284 .doit = nl80211_stop_sched_scan,
10285 .policy = nl80211_policy,
10286 .flags = GENL_ADMIN_PERM,
10287 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10288 NL80211_FLAG_NEED_RTNL,
10289 },
10290 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010291 .cmd = NL80211_CMD_AUTHENTICATE,
10292 .doit = nl80211_authenticate,
10293 .policy = nl80211_policy,
10294 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010295 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010296 NL80211_FLAG_NEED_RTNL |
10297 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010298 },
10299 {
10300 .cmd = NL80211_CMD_ASSOCIATE,
10301 .doit = nl80211_associate,
10302 .policy = nl80211_policy,
10303 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010304 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010305 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010306 },
10307 {
10308 .cmd = NL80211_CMD_DEAUTHENTICATE,
10309 .doit = nl80211_deauthenticate,
10310 .policy = nl80211_policy,
10311 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010312 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010313 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010314 },
10315 {
10316 .cmd = NL80211_CMD_DISASSOCIATE,
10317 .doit = nl80211_disassociate,
10318 .policy = nl80211_policy,
10319 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010320 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010321 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010322 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010323 {
10324 .cmd = NL80211_CMD_JOIN_IBSS,
10325 .doit = nl80211_join_ibss,
10326 .policy = nl80211_policy,
10327 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010328 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010329 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010330 },
10331 {
10332 .cmd = NL80211_CMD_LEAVE_IBSS,
10333 .doit = nl80211_leave_ibss,
10334 .policy = nl80211_policy,
10335 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010336 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010337 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010338 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010339#ifdef CONFIG_NL80211_TESTMODE
10340 {
10341 .cmd = NL80211_CMD_TESTMODE,
10342 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010343 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010344 .policy = nl80211_policy,
10345 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010346 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10347 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010348 },
10349#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010350 {
10351 .cmd = NL80211_CMD_CONNECT,
10352 .doit = nl80211_connect,
10353 .policy = nl80211_policy,
10354 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010355 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010356 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010357 },
10358 {
10359 .cmd = NL80211_CMD_DISCONNECT,
10360 .doit = nl80211_disconnect,
10361 .policy = nl80211_policy,
10362 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010363 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010364 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010365 },
Johannes Berg463d0182009-07-14 00:33:35 +020010366 {
10367 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10368 .doit = nl80211_wiphy_netns,
10369 .policy = nl80211_policy,
10370 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010371 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10372 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010373 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010374 {
10375 .cmd = NL80211_CMD_GET_SURVEY,
10376 .policy = nl80211_policy,
10377 .dumpit = nl80211_dump_survey,
10378 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010379 {
10380 .cmd = NL80211_CMD_SET_PMKSA,
10381 .doit = nl80211_setdel_pmksa,
10382 .policy = nl80211_policy,
10383 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010384 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010385 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010386 },
10387 {
10388 .cmd = NL80211_CMD_DEL_PMKSA,
10389 .doit = nl80211_setdel_pmksa,
10390 .policy = nl80211_policy,
10391 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010392 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010393 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010394 },
10395 {
10396 .cmd = NL80211_CMD_FLUSH_PMKSA,
10397 .doit = nl80211_flush_pmksa,
10398 .policy = nl80211_policy,
10399 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010400 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010401 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010402 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010403 {
10404 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10405 .doit = nl80211_remain_on_channel,
10406 .policy = nl80211_policy,
10407 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010408 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010409 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010410 },
10411 {
10412 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10413 .doit = nl80211_cancel_remain_on_channel,
10414 .policy = nl80211_policy,
10415 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010416 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010417 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010418 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010419 {
10420 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10421 .doit = nl80211_set_tx_bitrate_mask,
10422 .policy = nl80211_policy,
10423 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010424 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10425 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010426 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010427 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010428 .cmd = NL80211_CMD_REGISTER_FRAME,
10429 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010430 .policy = nl80211_policy,
10431 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010432 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010433 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010434 },
10435 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010436 .cmd = NL80211_CMD_FRAME,
10437 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010438 .policy = nl80211_policy,
10439 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010440 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010441 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010442 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010443 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010444 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10445 .doit = nl80211_tx_mgmt_cancel_wait,
10446 .policy = nl80211_policy,
10447 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010448 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010449 NL80211_FLAG_NEED_RTNL,
10450 },
10451 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010452 .cmd = NL80211_CMD_SET_POWER_SAVE,
10453 .doit = nl80211_set_power_save,
10454 .policy = nl80211_policy,
10455 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010456 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10457 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010458 },
10459 {
10460 .cmd = NL80211_CMD_GET_POWER_SAVE,
10461 .doit = nl80211_get_power_save,
10462 .policy = nl80211_policy,
10463 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010464 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10465 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010466 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010467 {
10468 .cmd = NL80211_CMD_SET_CQM,
10469 .doit = nl80211_set_cqm,
10470 .policy = nl80211_policy,
10471 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010472 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10473 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010474 },
Johannes Bergf444de02010-05-05 15:25:02 +020010475 {
10476 .cmd = NL80211_CMD_SET_CHANNEL,
10477 .doit = nl80211_set_channel,
10478 .policy = nl80211_policy,
10479 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010480 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10481 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010482 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010483 {
10484 .cmd = NL80211_CMD_SET_WDS_PEER,
10485 .doit = nl80211_set_wds_peer,
10486 .policy = nl80211_policy,
10487 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010488 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10489 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010490 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010491 {
10492 .cmd = NL80211_CMD_JOIN_MESH,
10493 .doit = nl80211_join_mesh,
10494 .policy = nl80211_policy,
10495 .flags = GENL_ADMIN_PERM,
10496 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10497 NL80211_FLAG_NEED_RTNL,
10498 },
10499 {
10500 .cmd = NL80211_CMD_LEAVE_MESH,
10501 .doit = nl80211_leave_mesh,
10502 .policy = nl80211_policy,
10503 .flags = GENL_ADMIN_PERM,
10504 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10505 NL80211_FLAG_NEED_RTNL,
10506 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010507 {
10508 .cmd = NL80211_CMD_JOIN_OCB,
10509 .doit = nl80211_join_ocb,
10510 .policy = nl80211_policy,
10511 .flags = GENL_ADMIN_PERM,
10512 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10513 NL80211_FLAG_NEED_RTNL,
10514 },
10515 {
10516 .cmd = NL80211_CMD_LEAVE_OCB,
10517 .doit = nl80211_leave_ocb,
10518 .policy = nl80211_policy,
10519 .flags = GENL_ADMIN_PERM,
10520 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10521 NL80211_FLAG_NEED_RTNL,
10522 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010523#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010524 {
10525 .cmd = NL80211_CMD_GET_WOWLAN,
10526 .doit = nl80211_get_wowlan,
10527 .policy = nl80211_policy,
10528 /* can be retrieved by unprivileged users */
10529 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10530 NL80211_FLAG_NEED_RTNL,
10531 },
10532 {
10533 .cmd = NL80211_CMD_SET_WOWLAN,
10534 .doit = nl80211_set_wowlan,
10535 .policy = nl80211_policy,
10536 .flags = GENL_ADMIN_PERM,
10537 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10538 NL80211_FLAG_NEED_RTNL,
10539 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010540#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010541 {
10542 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10543 .doit = nl80211_set_rekey_data,
10544 .policy = nl80211_policy,
10545 .flags = GENL_ADMIN_PERM,
10546 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010547 NL80211_FLAG_NEED_RTNL |
10548 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010549 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010550 {
10551 .cmd = NL80211_CMD_TDLS_MGMT,
10552 .doit = nl80211_tdls_mgmt,
10553 .policy = nl80211_policy,
10554 .flags = GENL_ADMIN_PERM,
10555 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10556 NL80211_FLAG_NEED_RTNL,
10557 },
10558 {
10559 .cmd = NL80211_CMD_TDLS_OPER,
10560 .doit = nl80211_tdls_oper,
10561 .policy = nl80211_policy,
10562 .flags = GENL_ADMIN_PERM,
10563 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10564 NL80211_FLAG_NEED_RTNL,
10565 },
Johannes Berg28946da2011-11-04 11:18:12 +010010566 {
10567 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10568 .doit = nl80211_register_unexpected_frame,
10569 .policy = nl80211_policy,
10570 .flags = GENL_ADMIN_PERM,
10571 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10572 NL80211_FLAG_NEED_RTNL,
10573 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010574 {
10575 .cmd = NL80211_CMD_PROBE_CLIENT,
10576 .doit = nl80211_probe_client,
10577 .policy = nl80211_policy,
10578 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010579 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010580 NL80211_FLAG_NEED_RTNL,
10581 },
Johannes Berg5e760232011-11-04 11:18:17 +010010582 {
10583 .cmd = NL80211_CMD_REGISTER_BEACONS,
10584 .doit = nl80211_register_beacons,
10585 .policy = nl80211_policy,
10586 .flags = GENL_ADMIN_PERM,
10587 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10588 NL80211_FLAG_NEED_RTNL,
10589 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010590 {
10591 .cmd = NL80211_CMD_SET_NOACK_MAP,
10592 .doit = nl80211_set_noack_map,
10593 .policy = nl80211_policy,
10594 .flags = GENL_ADMIN_PERM,
10595 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10596 NL80211_FLAG_NEED_RTNL,
10597 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010598 {
10599 .cmd = NL80211_CMD_START_P2P_DEVICE,
10600 .doit = nl80211_start_p2p_device,
10601 .policy = nl80211_policy,
10602 .flags = GENL_ADMIN_PERM,
10603 .internal_flags = NL80211_FLAG_NEED_WDEV |
10604 NL80211_FLAG_NEED_RTNL,
10605 },
10606 {
10607 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10608 .doit = nl80211_stop_p2p_device,
10609 .policy = nl80211_policy,
10610 .flags = GENL_ADMIN_PERM,
10611 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10612 NL80211_FLAG_NEED_RTNL,
10613 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010614 {
10615 .cmd = NL80211_CMD_SET_MCAST_RATE,
10616 .doit = nl80211_set_mcast_rate,
10617 .policy = nl80211_policy,
10618 .flags = GENL_ADMIN_PERM,
10619 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10620 NL80211_FLAG_NEED_RTNL,
10621 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010622 {
10623 .cmd = NL80211_CMD_SET_MAC_ACL,
10624 .doit = nl80211_set_mac_acl,
10625 .policy = nl80211_policy,
10626 .flags = GENL_ADMIN_PERM,
10627 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10628 NL80211_FLAG_NEED_RTNL,
10629 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010630 {
10631 .cmd = NL80211_CMD_RADAR_DETECT,
10632 .doit = nl80211_start_radar_detection,
10633 .policy = nl80211_policy,
10634 .flags = GENL_ADMIN_PERM,
10635 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10636 NL80211_FLAG_NEED_RTNL,
10637 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010638 {
10639 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10640 .doit = nl80211_get_protocol_features,
10641 .policy = nl80211_policy,
10642 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010643 {
10644 .cmd = NL80211_CMD_UPDATE_FT_IES,
10645 .doit = nl80211_update_ft_ies,
10646 .policy = nl80211_policy,
10647 .flags = GENL_ADMIN_PERM,
10648 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10649 NL80211_FLAG_NEED_RTNL,
10650 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010651 {
10652 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10653 .doit = nl80211_crit_protocol_start,
10654 .policy = nl80211_policy,
10655 .flags = GENL_ADMIN_PERM,
10656 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10657 NL80211_FLAG_NEED_RTNL,
10658 },
10659 {
10660 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10661 .doit = nl80211_crit_protocol_stop,
10662 .policy = nl80211_policy,
10663 .flags = GENL_ADMIN_PERM,
10664 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10665 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010666 },
10667 {
10668 .cmd = NL80211_CMD_GET_COALESCE,
10669 .doit = nl80211_get_coalesce,
10670 .policy = nl80211_policy,
10671 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10672 NL80211_FLAG_NEED_RTNL,
10673 },
10674 {
10675 .cmd = NL80211_CMD_SET_COALESCE,
10676 .doit = nl80211_set_coalesce,
10677 .policy = nl80211_policy,
10678 .flags = GENL_ADMIN_PERM,
10679 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10680 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010681 },
10682 {
10683 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10684 .doit = nl80211_channel_switch,
10685 .policy = nl80211_policy,
10686 .flags = GENL_ADMIN_PERM,
10687 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10688 NL80211_FLAG_NEED_RTNL,
10689 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010690 {
10691 .cmd = NL80211_CMD_VENDOR,
10692 .doit = nl80211_vendor_cmd,
10693 .policy = nl80211_policy,
10694 .flags = GENL_ADMIN_PERM,
10695 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10696 NL80211_FLAG_NEED_RTNL,
10697 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010698 {
10699 .cmd = NL80211_CMD_SET_QOS_MAP,
10700 .doit = nl80211_set_qos_map,
10701 .policy = nl80211_policy,
10702 .flags = GENL_ADMIN_PERM,
10703 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10704 NL80211_FLAG_NEED_RTNL,
10705 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010706 {
10707 .cmd = NL80211_CMD_ADD_TX_TS,
10708 .doit = nl80211_add_tx_ts,
10709 .policy = nl80211_policy,
10710 .flags = GENL_ADMIN_PERM,
10711 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10712 NL80211_FLAG_NEED_RTNL,
10713 },
10714 {
10715 .cmd = NL80211_CMD_DEL_TX_TS,
10716 .doit = nl80211_del_tx_ts,
10717 .policy = nl80211_policy,
10718 .flags = GENL_ADMIN_PERM,
10719 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10720 NL80211_FLAG_NEED_RTNL,
10721 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020010722 {
10723 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
10724 .doit = nl80211_tdls_channel_switch,
10725 .policy = nl80211_policy,
10726 .flags = GENL_ADMIN_PERM,
10727 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10728 NL80211_FLAG_NEED_RTNL,
10729 },
10730 {
10731 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
10732 .doit = nl80211_tdls_cancel_channel_switch,
10733 .policy = nl80211_policy,
10734 .flags = GENL_ADMIN_PERM,
10735 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10736 NL80211_FLAG_NEED_RTNL,
10737 },
Johannes Berg55682962007-09-20 13:09:35 -040010738};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010739
Johannes Berg55682962007-09-20 13:09:35 -040010740/* notification functions */
10741
Johannes Berg3bb20552014-05-26 13:52:25 +020010742void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
10743 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040010744{
10745 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020010746 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040010747
Johannes Berg3bb20552014-05-26 13:52:25 +020010748 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
10749 cmd != NL80211_CMD_DEL_WIPHY);
10750
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010751 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010752 if (!msg)
10753 return;
10754
Johannes Berg3bb20552014-05-26 13:52:25 +020010755 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040010756 nlmsg_free(msg);
10757 return;
10758 }
10759
Johannes Berg68eb5502013-11-19 15:19:38 +010010760 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010761 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040010762}
10763
Johannes Berg362a4152009-05-24 16:43:15 +020010764static int nl80211_add_scan_req(struct sk_buff *msg,
10765 struct cfg80211_registered_device *rdev)
10766{
10767 struct cfg80211_scan_request *req = rdev->scan_req;
10768 struct nlattr *nest;
10769 int i;
10770
10771 if (WARN_ON(!req))
10772 return 0;
10773
10774 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
10775 if (!nest)
10776 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010777 for (i = 0; i < req->n_ssids; i++) {
10778 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
10779 goto nla_put_failure;
10780 }
Johannes Berg362a4152009-05-24 16:43:15 +020010781 nla_nest_end(msg, nest);
10782
10783 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
10784 if (!nest)
10785 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040010786 for (i = 0; i < req->n_channels; i++) {
10787 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
10788 goto nla_put_failure;
10789 }
Johannes Berg362a4152009-05-24 16:43:15 +020010790 nla_nest_end(msg, nest);
10791
David S. Miller9360ffd2012-03-29 04:41:26 -040010792 if (req->ie &&
10793 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
10794 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020010795
Johannes Bergae917c92013-10-25 11:05:22 +020010796 if (req->flags &&
10797 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
10798 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070010799
Johannes Berg362a4152009-05-24 16:43:15 +020010800 return 0;
10801 nla_put_failure:
10802 return -ENOBUFS;
10803}
10804
Johannes Berga538e2d2009-06-16 19:56:42 +020010805static int nl80211_send_scan_msg(struct sk_buff *msg,
10806 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010807 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010808 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020010809 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010010810{
10811 void *hdr;
10812
Eric W. Biederman15e47302012-09-07 20:12:54 +000010813 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010010814 if (!hdr)
10815 return -1;
10816
David S. Miller9360ffd2012-03-29 04:41:26 -040010817 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020010818 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
10819 wdev->netdev->ifindex)) ||
10820 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040010821 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010010822
Johannes Berg362a4152009-05-24 16:43:15 +020010823 /* ignore errors and send incomplete event anyway */
10824 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010010825
10826 return genlmsg_end(msg, hdr);
10827
10828 nla_put_failure:
10829 genlmsg_cancel(msg, hdr);
10830 return -EMSGSIZE;
10831}
10832
Luciano Coelho807f8a82011-05-11 17:09:35 +030010833static int
10834nl80211_send_sched_scan_msg(struct sk_buff *msg,
10835 struct cfg80211_registered_device *rdev,
10836 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000010837 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030010838{
10839 void *hdr;
10840
Eric W. Biederman15e47302012-09-07 20:12:54 +000010841 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010842 if (!hdr)
10843 return -1;
10844
David S. Miller9360ffd2012-03-29 04:41:26 -040010845 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
10846 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
10847 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030010848
10849 return genlmsg_end(msg, hdr);
10850
10851 nla_put_failure:
10852 genlmsg_cancel(msg, hdr);
10853 return -EMSGSIZE;
10854}
10855
Johannes Berga538e2d2009-06-16 19:56:42 +020010856void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020010857 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020010858{
10859 struct sk_buff *msg;
10860
Thomas Graf58050fc2012-06-28 03:57:45 +000010861 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010862 if (!msg)
10863 return;
10864
Johannes Bergfd014282012-06-18 19:17:03 +020010865 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020010866 NL80211_CMD_TRIGGER_SCAN) < 0) {
10867 nlmsg_free(msg);
10868 return;
10869 }
10870
Johannes Berg68eb5502013-11-19 15:19:38 +010010871 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010872 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020010873}
10874
Johannes Bergf9d15d12014-01-22 11:14:19 +020010875struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
10876 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010010877{
10878 struct sk_buff *msg;
10879
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010880 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010881 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020010882 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010883
Johannes Bergfd014282012-06-18 19:17:03 +020010884 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020010885 aborted ? NL80211_CMD_SCAN_ABORTED :
10886 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010010887 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020010888 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010010889 }
10890
Johannes Bergf9d15d12014-01-22 11:14:19 +020010891 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010010892}
10893
Johannes Bergf9d15d12014-01-22 11:14:19 +020010894void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
10895 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010010896{
Johannes Berg2a519312009-02-10 21:25:55 +010010897 if (!msg)
10898 return;
10899
Johannes Berg68eb5502013-11-19 15:19:38 +010010900 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010901 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010010902}
10903
Luciano Coelho807f8a82011-05-11 17:09:35 +030010904void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
10905 struct net_device *netdev)
10906{
10907 struct sk_buff *msg;
10908
10909 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
10910 if (!msg)
10911 return;
10912
10913 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
10914 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
10915 nlmsg_free(msg);
10916 return;
10917 }
10918
Johannes Berg68eb5502013-11-19 15:19:38 +010010919 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010920 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010921}
10922
10923void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
10924 struct net_device *netdev, u32 cmd)
10925{
10926 struct sk_buff *msg;
10927
Thomas Graf58050fc2012-06-28 03:57:45 +000010928 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010929 if (!msg)
10930 return;
10931
10932 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
10933 nlmsg_free(msg);
10934 return;
10935 }
10936
Johannes Berg68eb5502013-11-19 15:19:38 +010010937 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010938 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030010939}
10940
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010941/*
10942 * This can happen on global regulatory changes or device specific settings
10943 * based on custom world regulatory domains.
10944 */
10945void nl80211_send_reg_change_event(struct regulatory_request *request)
10946{
10947 struct sk_buff *msg;
10948 void *hdr;
10949
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070010950 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010951 if (!msg)
10952 return;
10953
10954 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_CHANGE);
10955 if (!hdr) {
10956 nlmsg_free(msg);
10957 return;
10958 }
10959
10960 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040010961 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
10962 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010963
David S. Miller9360ffd2012-03-29 04:41:26 -040010964 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
10965 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10966 NL80211_REGDOM_TYPE_WORLD))
10967 goto nla_put_failure;
10968 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
10969 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10970 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
10971 goto nla_put_failure;
10972 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
10973 request->intersect) {
10974 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10975 NL80211_REGDOM_TYPE_INTERSECTION))
10976 goto nla_put_failure;
10977 } else {
10978 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
10979 NL80211_REGDOM_TYPE_COUNTRY) ||
10980 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
10981 request->alpha2))
10982 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010983 }
10984
Johannes Bergf4173762012-12-03 18:23:37 +010010985 if (request->wiphy_idx != WIPHY_IDX_INVALID &&
David S. Miller9360ffd2012-03-29 04:41:26 -040010986 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
10987 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010988
Johannes Berg3b7b72e2011-10-22 19:05:51 +020010989 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010990
Johannes Bergbc43b282009-07-25 10:54:13 +020010991 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010010992 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010010993 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020010994 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040010995
10996 return;
10997
10998nla_put_failure:
10999 genlmsg_cancel(msg, hdr);
11000 nlmsg_free(msg);
11001}
11002
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011003static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11004 struct net_device *netdev,
11005 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011006 enum nl80211_commands cmd, gfp_t gfp,
11007 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011008{
11009 struct sk_buff *msg;
11010 void *hdr;
11011
Johannes Berge6d6e342009-07-01 21:26:47 +020011012 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011013 if (!msg)
11014 return;
11015
11016 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11017 if (!hdr) {
11018 nlmsg_free(msg);
11019 return;
11020 }
11021
David S. Miller9360ffd2012-03-29 04:41:26 -040011022 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11023 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11024 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11025 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011026
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011027 if (uapsd_queues >= 0) {
11028 struct nlattr *nla_wmm =
11029 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11030 if (!nla_wmm)
11031 goto nla_put_failure;
11032
11033 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11034 uapsd_queues))
11035 goto nla_put_failure;
11036
11037 nla_nest_end(msg, nla_wmm);
11038 }
11039
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011040 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011041
Johannes Berg68eb5502013-11-19 15:19:38 +010011042 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011043 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011044 return;
11045
11046 nla_put_failure:
11047 genlmsg_cancel(msg, hdr);
11048 nlmsg_free(msg);
11049}
11050
11051void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011052 struct net_device *netdev, const u8 *buf,
11053 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011054{
11055 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011056 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011057}
11058
11059void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11060 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011061 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011062{
Johannes Berge6d6e342009-07-01 21:26:47 +020011063 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011064 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011065}
11066
Jouni Malinen53b46b82009-03-27 20:53:56 +020011067void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011068 struct net_device *netdev, const u8 *buf,
11069 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011070{
11071 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011072 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011073}
11074
Jouni Malinen53b46b82009-03-27 20:53:56 +020011075void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11076 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011077 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011078{
11079 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011080 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011081}
11082
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011083void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11084 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011085{
Johannes Berg947add32013-02-22 22:05:20 +010011086 struct wireless_dev *wdev = dev->ieee80211_ptr;
11087 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011088 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011089 const struct ieee80211_mgmt *mgmt = (void *)buf;
11090 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011091
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011092 if (WARN_ON(len < 2))
11093 return;
11094
11095 if (ieee80211_is_deauth(mgmt->frame_control))
11096 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11097 else
11098 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11099
11100 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011101 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011102}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011103EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011104
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011105static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11106 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011107 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011108{
11109 struct sk_buff *msg;
11110 void *hdr;
11111
Johannes Berge6d6e342009-07-01 21:26:47 +020011112 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011113 if (!msg)
11114 return;
11115
11116 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11117 if (!hdr) {
11118 nlmsg_free(msg);
11119 return;
11120 }
11121
David S. Miller9360ffd2012-03-29 04:41:26 -040011122 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11123 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11124 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11125 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11126 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011127
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011128 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011129
Johannes Berg68eb5502013-11-19 15:19:38 +010011130 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011131 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011132 return;
11133
11134 nla_put_failure:
11135 genlmsg_cancel(msg, hdr);
11136 nlmsg_free(msg);
11137}
11138
11139void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011140 struct net_device *netdev, const u8 *addr,
11141 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011142{
11143 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011144 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011145}
11146
11147void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011148 struct net_device *netdev, const u8 *addr,
11149 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011150{
Johannes Berge6d6e342009-07-01 21:26:47 +020011151 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11152 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011153}
11154
Samuel Ortizb23aa672009-07-01 21:26:54 +020011155void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11156 struct net_device *netdev, const u8 *bssid,
11157 const u8 *req_ie, size_t req_ie_len,
11158 const u8 *resp_ie, size_t resp_ie_len,
11159 u16 status, gfp_t gfp)
11160{
11161 struct sk_buff *msg;
11162 void *hdr;
11163
Thomas Graf58050fc2012-06-28 03:57:45 +000011164 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011165 if (!msg)
11166 return;
11167
11168 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11169 if (!hdr) {
11170 nlmsg_free(msg);
11171 return;
11172 }
11173
David S. Miller9360ffd2012-03-29 04:41:26 -040011174 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11175 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11176 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11177 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11178 (req_ie &&
11179 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11180 (resp_ie &&
11181 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11182 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011183
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011184 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011185
Johannes Berg68eb5502013-11-19 15:19:38 +010011186 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011187 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011188 return;
11189
11190 nla_put_failure:
11191 genlmsg_cancel(msg, hdr);
11192 nlmsg_free(msg);
11193
11194}
11195
11196void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11197 struct net_device *netdev, const u8 *bssid,
11198 const u8 *req_ie, size_t req_ie_len,
11199 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11200{
11201 struct sk_buff *msg;
11202 void *hdr;
11203
Thomas Graf58050fc2012-06-28 03:57:45 +000011204 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011205 if (!msg)
11206 return;
11207
11208 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11209 if (!hdr) {
11210 nlmsg_free(msg);
11211 return;
11212 }
11213
David S. Miller9360ffd2012-03-29 04:41:26 -040011214 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11215 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11216 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11217 (req_ie &&
11218 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11219 (resp_ie &&
11220 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11221 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011222
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011223 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011224
Johannes Berg68eb5502013-11-19 15:19:38 +010011225 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011226 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011227 return;
11228
11229 nla_put_failure:
11230 genlmsg_cancel(msg, hdr);
11231 nlmsg_free(msg);
11232
11233}
11234
11235void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11236 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011237 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011238{
11239 struct sk_buff *msg;
11240 void *hdr;
11241
Thomas Graf58050fc2012-06-28 03:57:45 +000011242 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011243 if (!msg)
11244 return;
11245
11246 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11247 if (!hdr) {
11248 nlmsg_free(msg);
11249 return;
11250 }
11251
David S. Miller9360ffd2012-03-29 04:41:26 -040011252 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11253 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11254 (from_ap && reason &&
11255 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11256 (from_ap &&
11257 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11258 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11259 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011260
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011261 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011262
Johannes Berg68eb5502013-11-19 15:19:38 +010011263 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011264 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011265 return;
11266
11267 nla_put_failure:
11268 genlmsg_cancel(msg, hdr);
11269 nlmsg_free(msg);
11270
11271}
11272
Johannes Berg04a773a2009-04-19 21:24:32 +020011273void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11274 struct net_device *netdev, const u8 *bssid,
11275 gfp_t gfp)
11276{
11277 struct sk_buff *msg;
11278 void *hdr;
11279
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011280 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011281 if (!msg)
11282 return;
11283
11284 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11285 if (!hdr) {
11286 nlmsg_free(msg);
11287 return;
11288 }
11289
David S. Miller9360ffd2012-03-29 04:41:26 -040011290 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11291 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11292 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11293 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011294
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011295 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011296
Johannes Berg68eb5502013-11-19 15:19:38 +010011297 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011298 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011299 return;
11300
11301 nla_put_failure:
11302 genlmsg_cancel(msg, hdr);
11303 nlmsg_free(msg);
11304}
11305
Johannes Berg947add32013-02-22 22:05:20 +010011306void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11307 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011308{
Johannes Berg947add32013-02-22 22:05:20 +010011309 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011310 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011311 struct sk_buff *msg;
11312 void *hdr;
11313
Johannes Berg947add32013-02-22 22:05:20 +010011314 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11315 return;
11316
11317 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11318
Javier Cardonac93b5e72011-04-07 15:08:34 -070011319 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11320 if (!msg)
11321 return;
11322
11323 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11324 if (!hdr) {
11325 nlmsg_free(msg);
11326 return;
11327 }
11328
David S. Miller9360ffd2012-03-29 04:41:26 -040011329 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011330 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11331 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011332 (ie_len && ie &&
11333 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11334 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011335
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011336 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011337
Johannes Berg68eb5502013-11-19 15:19:38 +010011338 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011339 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011340 return;
11341
11342 nla_put_failure:
11343 genlmsg_cancel(msg, hdr);
11344 nlmsg_free(msg);
11345}
Johannes Berg947add32013-02-22 22:05:20 +010011346EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011347
Jouni Malinena3b8b052009-03-27 21:59:49 +020011348void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11349 struct net_device *netdev, const u8 *addr,
11350 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011351 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011352{
11353 struct sk_buff *msg;
11354 void *hdr;
11355
Johannes Berge6d6e342009-07-01 21:26:47 +020011356 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011357 if (!msg)
11358 return;
11359
11360 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11361 if (!hdr) {
11362 nlmsg_free(msg);
11363 return;
11364 }
11365
David S. Miller9360ffd2012-03-29 04:41:26 -040011366 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11367 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11368 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11369 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11370 (key_id != -1 &&
11371 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11372 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11373 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011374
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011375 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011376
Johannes Berg68eb5502013-11-19 15:19:38 +010011377 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011378 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011379 return;
11380
11381 nla_put_failure:
11382 genlmsg_cancel(msg, hdr);
11383 nlmsg_free(msg);
11384}
11385
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011386void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11387 struct ieee80211_channel *channel_before,
11388 struct ieee80211_channel *channel_after)
11389{
11390 struct sk_buff *msg;
11391 void *hdr;
11392 struct nlattr *nl_freq;
11393
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011394 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011395 if (!msg)
11396 return;
11397
11398 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11399 if (!hdr) {
11400 nlmsg_free(msg);
11401 return;
11402 }
11403
11404 /*
11405 * Since we are applying the beacon hint to a wiphy we know its
11406 * wiphy_idx is valid
11407 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011408 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11409 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011410
11411 /* Before */
11412 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11413 if (!nl_freq)
11414 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011415 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011416 goto nla_put_failure;
11417 nla_nest_end(msg, nl_freq);
11418
11419 /* After */
11420 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11421 if (!nl_freq)
11422 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011423 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011424 goto nla_put_failure;
11425 nla_nest_end(msg, nl_freq);
11426
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011427 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011428
Johannes Berg463d0182009-07-14 00:33:35 +020011429 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011430 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011431 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011432 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011433
11434 return;
11435
11436nla_put_failure:
11437 genlmsg_cancel(msg, hdr);
11438 nlmsg_free(msg);
11439}
11440
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011441static void nl80211_send_remain_on_chan_event(
11442 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011443 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011444 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011445 unsigned int duration, gfp_t gfp)
11446{
11447 struct sk_buff *msg;
11448 void *hdr;
11449
11450 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11451 if (!msg)
11452 return;
11453
11454 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11455 if (!hdr) {
11456 nlmsg_free(msg);
11457 return;
11458 }
11459
David S. Miller9360ffd2012-03-29 04:41:26 -040011460 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011461 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11462 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011463 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011464 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011465 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11466 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011467 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11468 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011469
David S. Miller9360ffd2012-03-29 04:41:26 -040011470 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11471 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11472 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011473
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011474 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011475
Johannes Berg68eb5502013-11-19 15:19:38 +010011476 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011477 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011478 return;
11479
11480 nla_put_failure:
11481 genlmsg_cancel(msg, hdr);
11482 nlmsg_free(msg);
11483}
11484
Johannes Berg947add32013-02-22 22:05:20 +010011485void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11486 struct ieee80211_channel *chan,
11487 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011488{
Johannes Berg947add32013-02-22 22:05:20 +010011489 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011490 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011491
11492 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011493 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011494 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011495 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011496}
Johannes Berg947add32013-02-22 22:05:20 +010011497EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011498
Johannes Berg947add32013-02-22 22:05:20 +010011499void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11500 struct ieee80211_channel *chan,
11501 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011502{
Johannes Berg947add32013-02-22 22:05:20 +010011503 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011504 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011505
11506 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011507 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011508 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011509}
Johannes Berg947add32013-02-22 22:05:20 +010011510EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011511
Johannes Berg947add32013-02-22 22:05:20 +010011512void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11513 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011514{
Johannes Berg947add32013-02-22 22:05:20 +010011515 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011516 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011517 struct sk_buff *msg;
11518
Johannes Berg947add32013-02-22 22:05:20 +010011519 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11520
Thomas Graf58050fc2012-06-28 03:57:45 +000011521 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011522 if (!msg)
11523 return;
11524
John W. Linville66266b32012-03-15 13:25:41 -040011525 if (nl80211_send_station(msg, 0, 0, 0,
11526 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011527 nlmsg_free(msg);
11528 return;
11529 }
11530
Johannes Berg68eb5502013-11-19 15:19:38 +010011531 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011532 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011533}
Johannes Berg947add32013-02-22 22:05:20 +010011534EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011535
Johannes Berg947add32013-02-22 22:05:20 +010011536void cfg80211_del_sta(struct net_device *dev, const u8 *mac_addr, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011537{
Johannes Berg947add32013-02-22 22:05:20 +010011538 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011539 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011540 struct sk_buff *msg;
11541 void *hdr;
11542
Johannes Berg947add32013-02-22 22:05:20 +010011543 trace_cfg80211_del_sta(dev, mac_addr);
11544
Thomas Graf58050fc2012-06-28 03:57:45 +000011545 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011546 if (!msg)
11547 return;
11548
11549 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DEL_STATION);
11550 if (!hdr) {
11551 nlmsg_free(msg);
11552 return;
11553 }
11554
David S. Miller9360ffd2012-03-29 04:41:26 -040011555 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11556 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
11557 goto nla_put_failure;
Jouni Malinenec15e682011-03-23 15:29:52 +020011558
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011559 genlmsg_end(msg, hdr);
Jouni Malinenec15e682011-03-23 15:29:52 +020011560
Johannes Berg68eb5502013-11-19 15:19:38 +010011561 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011562 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011563 return;
11564
11565 nla_put_failure:
11566 genlmsg_cancel(msg, hdr);
11567 nlmsg_free(msg);
11568}
Johannes Berg947add32013-02-22 22:05:20 +010011569EXPORT_SYMBOL(cfg80211_del_sta);
Jouni Malinenec15e682011-03-23 15:29:52 +020011570
Johannes Berg947add32013-02-22 22:05:20 +010011571void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11572 enum nl80211_connect_failed_reason reason,
11573 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011574{
Johannes Berg947add32013-02-22 22:05:20 +010011575 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011576 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011577 struct sk_buff *msg;
11578 void *hdr;
11579
11580 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11581 if (!msg)
11582 return;
11583
11584 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11585 if (!hdr) {
11586 nlmsg_free(msg);
11587 return;
11588 }
11589
11590 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11591 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11592 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11593 goto nla_put_failure;
11594
11595 genlmsg_end(msg, hdr);
11596
Johannes Berg68eb5502013-11-19 15:19:38 +010011597 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011598 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011599 return;
11600
11601 nla_put_failure:
11602 genlmsg_cancel(msg, hdr);
11603 nlmsg_free(msg);
11604}
Johannes Berg947add32013-02-22 22:05:20 +010011605EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011606
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011607static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11608 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011609{
11610 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011611 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011612 struct sk_buff *msg;
11613 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011614 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011615
Eric W. Biederman15e47302012-09-07 20:12:54 +000011616 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011617 return false;
11618
11619 msg = nlmsg_new(100, gfp);
11620 if (!msg)
11621 return true;
11622
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011623 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011624 if (!hdr) {
11625 nlmsg_free(msg);
11626 return true;
11627 }
11628
David S. Miller9360ffd2012-03-29 04:41:26 -040011629 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11630 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11631 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11632 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011633
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011634 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011635 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011636 return true;
11637
11638 nla_put_failure:
11639 genlmsg_cancel(msg, hdr);
11640 nlmsg_free(msg);
11641 return true;
11642}
11643
Johannes Berg947add32013-02-22 22:05:20 +010011644bool cfg80211_rx_spurious_frame(struct net_device *dev,
11645 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011646{
Johannes Berg947add32013-02-22 22:05:20 +010011647 struct wireless_dev *wdev = dev->ieee80211_ptr;
11648 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011649
Johannes Berg947add32013-02-22 22:05:20 +010011650 trace_cfg80211_rx_spurious_frame(dev, addr);
11651
11652 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11653 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11654 trace_cfg80211_return_bool(false);
11655 return false;
11656 }
11657 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11658 addr, gfp);
11659 trace_cfg80211_return_bool(ret);
11660 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011661}
Johannes Berg947add32013-02-22 22:05:20 +010011662EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11663
11664bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11665 const u8 *addr, gfp_t gfp)
11666{
11667 struct wireless_dev *wdev = dev->ieee80211_ptr;
11668 bool ret;
11669
11670 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11671
11672 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11673 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11674 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11675 trace_cfg80211_return_bool(false);
11676 return false;
11677 }
11678 ret = __nl80211_unexpected_frame(dev,
11679 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11680 addr, gfp);
11681 trace_cfg80211_return_bool(ret);
11682 return ret;
11683}
11684EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011685
Johannes Berg2e161f72010-08-12 15:38:38 +020011686int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011687 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011688 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011689 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011690{
Johannes Berg71bbc992012-06-15 15:30:18 +020011691 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011692 struct sk_buff *msg;
11693 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011694
11695 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11696 if (!msg)
11697 return -ENOMEM;
11698
Johannes Berg2e161f72010-08-12 15:38:38 +020011699 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020011700 if (!hdr) {
11701 nlmsg_free(msg);
11702 return -ENOMEM;
11703 }
11704
David S. Miller9360ffd2012-03-29 04:41:26 -040011705 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011706 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11707 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011708 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011709 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
11710 (sig_dbm &&
11711 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011712 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11713 (flags &&
11714 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011715 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011716
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011717 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011718
Eric W. Biederman15e47302012-09-07 20:12:54 +000011719 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020011720
11721 nla_put_failure:
11722 genlmsg_cancel(msg, hdr);
11723 nlmsg_free(msg);
11724 return -ENOBUFS;
11725}
11726
Johannes Berg947add32013-02-22 22:05:20 +010011727void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
11728 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011729{
Johannes Berg947add32013-02-22 22:05:20 +010011730 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011731 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020011732 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011733 struct sk_buff *msg;
11734 void *hdr;
11735
Johannes Berg947add32013-02-22 22:05:20 +010011736 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
11737
Jouni Malinen026331c2010-02-15 12:53:10 +020011738 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11739 if (!msg)
11740 return;
11741
Johannes Berg2e161f72010-08-12 15:38:38 +020011742 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020011743 if (!hdr) {
11744 nlmsg_free(msg);
11745 return;
11746 }
11747
David S. Miller9360ffd2012-03-29 04:41:26 -040011748 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011749 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11750 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030011751 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011752 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
11753 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
11754 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
11755 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020011756
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011757 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020011758
Johannes Berg68eb5502013-11-19 15:19:38 +010011759 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011760 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020011761 return;
11762
11763 nla_put_failure:
11764 genlmsg_cancel(msg, hdr);
11765 nlmsg_free(msg);
11766}
Johannes Berg947add32013-02-22 22:05:20 +010011767EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020011768
Johannes Berg5b97f492014-11-26 12:37:43 +010011769static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
11770 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011771{
Johannes Berg947add32013-02-22 22:05:20 +010011772 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010011773 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
11774 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11775 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011776
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011777 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010011778 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011779
Johannes Berg5b97f492014-11-26 12:37:43 +010011780 cb = (void **)msg->cb;
11781
11782 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
11783 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011784 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010011785 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011786 }
11787
David S. Miller9360ffd2012-03-29 04:41:26 -040011788 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011789 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040011790 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011791
Johannes Berg5b97f492014-11-26 12:37:43 +010011792 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011793 goto nla_put_failure;
11794
Johannes Berg5b97f492014-11-26 12:37:43 +010011795 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
11796 if (!cb[1])
11797 goto nla_put_failure;
11798
11799 cb[2] = rdev;
11800
11801 return msg;
11802 nla_put_failure:
11803 nlmsg_free(msg);
11804 return NULL;
11805}
11806
11807static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
11808{
11809 void **cb = (void **)msg->cb;
11810 struct cfg80211_registered_device *rdev = cb[2];
11811
11812 nla_nest_end(msg, cb[1]);
11813 genlmsg_end(msg, cb[0]);
11814
11815 memset(msg->cb, 0, sizeof(msg->cb));
11816
11817 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
11818 NL80211_MCGRP_MLME, gfp);
11819}
11820
11821void cfg80211_cqm_rssi_notify(struct net_device *dev,
11822 enum nl80211_cqm_rssi_threshold_event rssi_event,
11823 gfp_t gfp)
11824{
11825 struct sk_buff *msg;
11826
11827 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
11828
11829 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
11830 if (!msg)
11831 return;
11832
David S. Miller9360ffd2012-03-29 04:41:26 -040011833 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
11834 rssi_event))
11835 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011836
Johannes Berg5b97f492014-11-26 12:37:43 +010011837 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011838
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011839 return;
11840
11841 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011842 nlmsg_free(msg);
11843}
Johannes Berg947add32013-02-22 22:05:20 +010011844EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020011845
Johannes Berg5b97f492014-11-26 12:37:43 +010011846void cfg80211_cqm_txe_notify(struct net_device *dev,
11847 const u8 *peer, u32 num_packets,
11848 u32 rate, u32 intvl, gfp_t gfp)
11849{
11850 struct sk_buff *msg;
11851
11852 msg = cfg80211_prepare_cqm(dev, peer, gfp);
11853 if (!msg)
11854 return;
11855
11856 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
11857 goto nla_put_failure;
11858
11859 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
11860 goto nla_put_failure;
11861
11862 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
11863 goto nla_put_failure;
11864
11865 cfg80211_send_cqm(msg, gfp);
11866 return;
11867
11868 nla_put_failure:
11869 nlmsg_free(msg);
11870}
11871EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
11872
11873void cfg80211_cqm_pktloss_notify(struct net_device *dev,
11874 const u8 *peer, u32 num_packets, gfp_t gfp)
11875{
11876 struct sk_buff *msg;
11877
11878 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
11879
11880 msg = cfg80211_prepare_cqm(dev, peer, gfp);
11881 if (!msg)
11882 return;
11883
11884 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
11885 goto nla_put_failure;
11886
11887 cfg80211_send_cqm(msg, gfp);
11888 return;
11889
11890 nla_put_failure:
11891 nlmsg_free(msg);
11892}
11893EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
11894
Johannes Berg947add32013-02-22 22:05:20 +010011895static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
11896 struct net_device *netdev, const u8 *bssid,
11897 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020011898{
11899 struct sk_buff *msg;
11900 struct nlattr *rekey_attr;
11901 void *hdr;
11902
Thomas Graf58050fc2012-06-28 03:57:45 +000011903 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011904 if (!msg)
11905 return;
11906
11907 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
11908 if (!hdr) {
11909 nlmsg_free(msg);
11910 return;
11911 }
11912
David S. Miller9360ffd2012-03-29 04:41:26 -040011913 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11914 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11915 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11916 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011917
11918 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
11919 if (!rekey_attr)
11920 goto nla_put_failure;
11921
David S. Miller9360ffd2012-03-29 04:41:26 -040011922 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
11923 NL80211_REPLAY_CTR_LEN, replay_ctr))
11924 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020011925
11926 nla_nest_end(msg, rekey_attr);
11927
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011928 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020011929
Johannes Berg68eb5502013-11-19 15:19:38 +010011930 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011931 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020011932 return;
11933
11934 nla_put_failure:
11935 genlmsg_cancel(msg, hdr);
11936 nlmsg_free(msg);
11937}
11938
Johannes Berg947add32013-02-22 22:05:20 +010011939void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
11940 const u8 *replay_ctr, gfp_t gfp)
11941{
11942 struct wireless_dev *wdev = dev->ieee80211_ptr;
11943 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011944 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011945
11946 trace_cfg80211_gtk_rekey_notify(dev, bssid);
11947 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
11948}
11949EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
11950
11951static void
11952nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
11953 struct net_device *netdev, int index,
11954 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011955{
11956 struct sk_buff *msg;
11957 struct nlattr *attr;
11958 void *hdr;
11959
Thomas Graf58050fc2012-06-28 03:57:45 +000011960 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011961 if (!msg)
11962 return;
11963
11964 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
11965 if (!hdr) {
11966 nlmsg_free(msg);
11967 return;
11968 }
11969
David S. Miller9360ffd2012-03-29 04:41:26 -040011970 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11971 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11972 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011973
11974 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
11975 if (!attr)
11976 goto nla_put_failure;
11977
David S. Miller9360ffd2012-03-29 04:41:26 -040011978 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
11979 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
11980 (preauth &&
11981 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
11982 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011983
11984 nla_nest_end(msg, attr);
11985
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011986 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011987
Johannes Berg68eb5502013-11-19 15:19:38 +010011988 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011989 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030011990 return;
11991
11992 nla_put_failure:
11993 genlmsg_cancel(msg, hdr);
11994 nlmsg_free(msg);
11995}
11996
Johannes Berg947add32013-02-22 22:05:20 +010011997void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
11998 const u8 *bssid, bool preauth, gfp_t gfp)
11999{
12000 struct wireless_dev *wdev = dev->ieee80211_ptr;
12001 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012002 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012003
12004 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12005 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12006}
12007EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12008
12009static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12010 struct net_device *netdev,
12011 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012012 gfp_t gfp,
12013 enum nl80211_commands notif,
12014 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012015{
12016 struct sk_buff *msg;
12017 void *hdr;
12018
Thomas Graf58050fc2012-06-28 03:57:45 +000012019 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012020 if (!msg)
12021 return;
12022
Luciano Coelhof8d75522014-11-07 14:31:35 +020012023 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012024 if (!hdr) {
12025 nlmsg_free(msg);
12026 return;
12027 }
12028
Johannes Berg683b6d32012-11-08 21:25:48 +010012029 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12030 goto nla_put_failure;
12031
12032 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012033 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012034
Luciano Coelhof8d75522014-11-07 14:31:35 +020012035 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12036 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12037 goto nla_put_failure;
12038
Thomas Pedersen53145262012-04-06 13:35:47 -070012039 genlmsg_end(msg, hdr);
12040
Johannes Berg68eb5502013-11-19 15:19:38 +010012041 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012042 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012043 return;
12044
12045 nla_put_failure:
12046 genlmsg_cancel(msg, hdr);
12047 nlmsg_free(msg);
12048}
12049
Johannes Berg947add32013-02-22 22:05:20 +010012050void cfg80211_ch_switch_notify(struct net_device *dev,
12051 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012052{
Johannes Berg947add32013-02-22 22:05:20 +010012053 struct wireless_dev *wdev = dev->ieee80211_ptr;
12054 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012055 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012056
Simon Wunderliche487eae2013-11-21 18:19:51 +010012057 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012058
Simon Wunderliche487eae2013-11-21 18:19:51 +010012059 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012060
Michal Kazior9e0e2962014-01-29 14:22:27 +010012061 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012062 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012063 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12064 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012065}
12066EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12067
Luciano Coelhof8d75522014-11-07 14:31:35 +020012068void cfg80211_ch_switch_started_notify(struct net_device *dev,
12069 struct cfg80211_chan_def *chandef,
12070 u8 count)
12071{
12072 struct wireless_dev *wdev = dev->ieee80211_ptr;
12073 struct wiphy *wiphy = wdev->wiphy;
12074 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12075
12076 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12077
12078 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12079 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12080}
12081EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12082
Thomas Pedersen84f10702012-07-12 16:17:33 -070012083void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012084nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012085 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012086 enum nl80211_radar_event event,
12087 struct net_device *netdev, gfp_t gfp)
12088{
12089 struct sk_buff *msg;
12090 void *hdr;
12091
12092 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12093 if (!msg)
12094 return;
12095
12096 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12097 if (!hdr) {
12098 nlmsg_free(msg);
12099 return;
12100 }
12101
12102 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12103 goto nla_put_failure;
12104
12105 /* NOP and radar events don't need a netdev parameter */
12106 if (netdev) {
12107 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12108
12109 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12110 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12111 goto nla_put_failure;
12112 }
12113
12114 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12115 goto nla_put_failure;
12116
12117 if (nl80211_send_chandef(msg, chandef))
12118 goto nla_put_failure;
12119
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012120 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012121
Johannes Berg68eb5502013-11-19 15:19:38 +010012122 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012123 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012124 return;
12125
12126 nla_put_failure:
12127 genlmsg_cancel(msg, hdr);
12128 nlmsg_free(msg);
12129}
12130
Johannes Berg7f6cf312011-11-04 11:18:15 +010012131void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12132 u64 cookie, bool acked, gfp_t gfp)
12133{
12134 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012135 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012136 struct sk_buff *msg;
12137 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012138
Beni Lev4ee3e062012-08-27 12:49:39 +030012139 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12140
Thomas Graf58050fc2012-06-28 03:57:45 +000012141 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012142
Johannes Berg7f6cf312011-11-04 11:18:15 +010012143 if (!msg)
12144 return;
12145
12146 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12147 if (!hdr) {
12148 nlmsg_free(msg);
12149 return;
12150 }
12151
David S. Miller9360ffd2012-03-29 04:41:26 -040012152 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12153 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12154 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12155 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12156 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12157 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012158
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012159 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012160
Johannes Berg68eb5502013-11-19 15:19:38 +010012161 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012162 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012163 return;
12164
12165 nla_put_failure:
12166 genlmsg_cancel(msg, hdr);
12167 nlmsg_free(msg);
12168}
12169EXPORT_SYMBOL(cfg80211_probe_status);
12170
Johannes Berg5e760232011-11-04 11:18:17 +010012171void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12172 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012173 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012174{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012175 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012176 struct sk_buff *msg;
12177 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012178 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012179
Beni Lev4ee3e062012-08-27 12:49:39 +030012180 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12181
Ben Greear37c73b52012-10-26 14:49:25 -070012182 spin_lock_bh(&rdev->beacon_registrations_lock);
12183 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12184 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12185 if (!msg) {
12186 spin_unlock_bh(&rdev->beacon_registrations_lock);
12187 return;
12188 }
Johannes Berg5e760232011-11-04 11:18:17 +010012189
Ben Greear37c73b52012-10-26 14:49:25 -070012190 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12191 if (!hdr)
12192 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012193
Ben Greear37c73b52012-10-26 14:49:25 -070012194 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12195 (freq &&
12196 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12197 (sig_dbm &&
12198 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12199 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12200 goto nla_put_failure;
12201
12202 genlmsg_end(msg, hdr);
12203
12204 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012205 }
Ben Greear37c73b52012-10-26 14:49:25 -070012206 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012207 return;
12208
12209 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012210 spin_unlock_bh(&rdev->beacon_registrations_lock);
12211 if (hdr)
12212 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012213 nlmsg_free(msg);
12214}
12215EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12216
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012217#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012218static int cfg80211_net_detect_results(struct sk_buff *msg,
12219 struct cfg80211_wowlan_wakeup *wakeup)
12220{
12221 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12222 struct nlattr *nl_results, *nl_match, *nl_freqs;
12223 int i, j;
12224
12225 nl_results = nla_nest_start(
12226 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12227 if (!nl_results)
12228 return -EMSGSIZE;
12229
12230 for (i = 0; i < nd->n_matches; i++) {
12231 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12232
12233 nl_match = nla_nest_start(msg, i);
12234 if (!nl_match)
12235 break;
12236
12237 /* The SSID attribute is optional in nl80211, but for
12238 * simplicity reasons it's always present in the
12239 * cfg80211 structure. If a driver can't pass the
12240 * SSID, that needs to be changed. A zero length SSID
12241 * is still a valid SSID (wildcard), so it cannot be
12242 * used for this purpose.
12243 */
12244 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12245 match->ssid.ssid)) {
12246 nla_nest_cancel(msg, nl_match);
12247 goto out;
12248 }
12249
12250 if (match->n_channels) {
12251 nl_freqs = nla_nest_start(
12252 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12253 if (!nl_freqs) {
12254 nla_nest_cancel(msg, nl_match);
12255 goto out;
12256 }
12257
12258 for (j = 0; j < match->n_channels; j++) {
12259 if (nla_put_u32(msg,
12260 NL80211_ATTR_WIPHY_FREQ,
12261 match->channels[j])) {
12262 nla_nest_cancel(msg, nl_freqs);
12263 nla_nest_cancel(msg, nl_match);
12264 goto out;
12265 }
12266 }
12267
12268 nla_nest_end(msg, nl_freqs);
12269 }
12270
12271 nla_nest_end(msg, nl_match);
12272 }
12273
12274out:
12275 nla_nest_end(msg, nl_results);
12276 return 0;
12277}
12278
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012279void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12280 struct cfg80211_wowlan_wakeup *wakeup,
12281 gfp_t gfp)
12282{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012283 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012284 struct sk_buff *msg;
12285 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012286 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012287
12288 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12289
12290 if (wakeup)
12291 size += wakeup->packet_present_len;
12292
12293 msg = nlmsg_new(size, gfp);
12294 if (!msg)
12295 return;
12296
12297 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12298 if (!hdr)
12299 goto free_msg;
12300
12301 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12302 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12303 goto free_msg;
12304
12305 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12306 wdev->netdev->ifindex))
12307 goto free_msg;
12308
12309 if (wakeup) {
12310 struct nlattr *reasons;
12311
12312 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012313 if (!reasons)
12314 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012315
12316 if (wakeup->disconnect &&
12317 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12318 goto free_msg;
12319 if (wakeup->magic_pkt &&
12320 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12321 goto free_msg;
12322 if (wakeup->gtk_rekey_failure &&
12323 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12324 goto free_msg;
12325 if (wakeup->eap_identity_req &&
12326 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12327 goto free_msg;
12328 if (wakeup->four_way_handshake &&
12329 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12330 goto free_msg;
12331 if (wakeup->rfkill_release &&
12332 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12333 goto free_msg;
12334
12335 if (wakeup->pattern_idx >= 0 &&
12336 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12337 wakeup->pattern_idx))
12338 goto free_msg;
12339
Johannes Bergae917c92013-10-25 11:05:22 +020012340 if (wakeup->tcp_match &&
12341 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12342 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012343
Johannes Bergae917c92013-10-25 11:05:22 +020012344 if (wakeup->tcp_connlost &&
12345 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12346 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012347
Johannes Bergae917c92013-10-25 11:05:22 +020012348 if (wakeup->tcp_nomoretokens &&
12349 nla_put_flag(msg,
12350 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12351 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012352
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012353 if (wakeup->packet) {
12354 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12355 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12356
12357 if (!wakeup->packet_80211) {
12358 pkt_attr =
12359 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12360 len_attr =
12361 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12362 }
12363
12364 if (wakeup->packet_len &&
12365 nla_put_u32(msg, len_attr, wakeup->packet_len))
12366 goto free_msg;
12367
12368 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12369 wakeup->packet))
12370 goto free_msg;
12371 }
12372
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012373 if (wakeup->net_detect &&
12374 cfg80211_net_detect_results(msg, wakeup))
12375 goto free_msg;
12376
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012377 nla_nest_end(msg, reasons);
12378 }
12379
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012380 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012381
Johannes Berg68eb5502013-11-19 15:19:38 +010012382 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012383 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012384 return;
12385
12386 free_msg:
12387 nlmsg_free(msg);
12388}
12389EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12390#endif
12391
Jouni Malinen3475b092012-11-16 22:49:57 +020012392void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12393 enum nl80211_tdls_operation oper,
12394 u16 reason_code, gfp_t gfp)
12395{
12396 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012397 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012398 struct sk_buff *msg;
12399 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012400
12401 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12402 reason_code);
12403
12404 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12405 if (!msg)
12406 return;
12407
12408 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12409 if (!hdr) {
12410 nlmsg_free(msg);
12411 return;
12412 }
12413
12414 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12415 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12416 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12417 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12418 (reason_code > 0 &&
12419 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12420 goto nla_put_failure;
12421
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012422 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012423
Johannes Berg68eb5502013-11-19 15:19:38 +010012424 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012425 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012426 return;
12427
12428 nla_put_failure:
12429 genlmsg_cancel(msg, hdr);
12430 nlmsg_free(msg);
12431}
12432EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12433
Jouni Malinen026331c2010-02-15 12:53:10 +020012434static int nl80211_netlink_notify(struct notifier_block * nb,
12435 unsigned long state,
12436 void *_notify)
12437{
12438 struct netlink_notify *notify = _notify;
12439 struct cfg80211_registered_device *rdev;
12440 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012441 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012442
12443 if (state != NETLINK_URELEASE)
12444 return NOTIFY_DONE;
12445
12446 rcu_read_lock();
12447
Johannes Berg5e760232011-11-04 11:18:17 +010012448 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012449 bool schedule_destroy_work = false;
12450
12451 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012452 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012453
Johannes Berg78f22b62014-03-24 17:57:27 +010012454 if (wdev->owner_nlportid == notify->portid)
12455 schedule_destroy_work = true;
12456 }
12457
Ben Greear37c73b52012-10-26 14:49:25 -070012458 spin_lock_bh(&rdev->beacon_registrations_lock);
12459 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12460 list) {
12461 if (reg->nlportid == notify->portid) {
12462 list_del(&reg->list);
12463 kfree(reg);
12464 break;
12465 }
12466 }
12467 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012468
12469 if (schedule_destroy_work) {
12470 struct cfg80211_iface_destroy *destroy;
12471
12472 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12473 if (destroy) {
12474 destroy->nlportid = notify->portid;
12475 spin_lock(&rdev->destroy_list_lock);
12476 list_add(&destroy->list, &rdev->destroy_list);
12477 spin_unlock(&rdev->destroy_list_lock);
12478 schedule_work(&rdev->destroy_work);
12479 }
12480 }
Johannes Berg5e760232011-11-04 11:18:17 +010012481 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012482
12483 rcu_read_unlock();
12484
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012485 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012486}
12487
12488static struct notifier_block nl80211_netlink_notifier = {
12489 .notifier_call = nl80211_netlink_notify,
12490};
12491
Jouni Malinen355199e2013-02-27 17:14:27 +020012492void cfg80211_ft_event(struct net_device *netdev,
12493 struct cfg80211_ft_event_params *ft_event)
12494{
12495 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012496 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012497 struct sk_buff *msg;
12498 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012499
12500 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12501
12502 if (!ft_event->target_ap)
12503 return;
12504
12505 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12506 if (!msg)
12507 return;
12508
12509 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012510 if (!hdr)
12511 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012512
Johannes Bergae917c92013-10-25 11:05:22 +020012513 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12514 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12515 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12516 goto out;
12517
12518 if (ft_event->ies &&
12519 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12520 goto out;
12521 if (ft_event->ric_ies &&
12522 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12523 ft_event->ric_ies))
12524 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012525
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012526 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012527
Johannes Berg68eb5502013-11-19 15:19:38 +010012528 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012529 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012530 return;
12531 out:
12532 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012533}
12534EXPORT_SYMBOL(cfg80211_ft_event);
12535
Arend van Spriel5de17982013-04-18 15:49:00 +020012536void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12537{
12538 struct cfg80211_registered_device *rdev;
12539 struct sk_buff *msg;
12540 void *hdr;
12541 u32 nlportid;
12542
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012543 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012544 if (!rdev->crit_proto_nlportid)
12545 return;
12546
12547 nlportid = rdev->crit_proto_nlportid;
12548 rdev->crit_proto_nlportid = 0;
12549
12550 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12551 if (!msg)
12552 return;
12553
12554 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12555 if (!hdr)
12556 goto nla_put_failure;
12557
12558 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12559 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12560 goto nla_put_failure;
12561
12562 genlmsg_end(msg, hdr);
12563
12564 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12565 return;
12566
12567 nla_put_failure:
12568 if (hdr)
12569 genlmsg_cancel(msg, hdr);
12570 nlmsg_free(msg);
12571
12572}
12573EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12574
Johannes Berg348baf02014-01-24 14:06:29 +010012575void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12576{
12577 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012578 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012579 struct sk_buff *msg;
12580 void *hdr;
12581
12582 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12583 if (!msg)
12584 return;
12585
12586 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12587 if (!hdr)
12588 goto out;
12589
12590 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12591 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12592 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12593 goto out;
12594
12595 genlmsg_end(msg, hdr);
12596
12597 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12598 NL80211_MCGRP_MLME, GFP_KERNEL);
12599 return;
12600 out:
12601 nlmsg_free(msg);
12602}
12603
Johannes Berg55682962007-09-20 13:09:35 -040012604/* initialisation/exit functions */
12605
12606int nl80211_init(void)
12607{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012608 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012609
Johannes Berg2a94fe42013-11-19 15:19:39 +010012610 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12611 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012612 if (err)
12613 return err;
12614
Jouni Malinen026331c2010-02-15 12:53:10 +020012615 err = netlink_register_notifier(&nl80211_netlink_notifier);
12616 if (err)
12617 goto err_out;
12618
Johannes Berg55682962007-09-20 13:09:35 -040012619 return 0;
12620 err_out:
12621 genl_unregister_family(&nl80211_fam);
12622 return err;
12623}
12624
12625void nl80211_exit(void)
12626{
Jouni Malinen026331c2010-02-15 12:53:10 +020012627 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012628 genl_unregister_family(&nl80211_fam);
12629}