blob: b02085301785008be6c9c212df630ac6d19e603f [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010062 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
63 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
64 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
65 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
66 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010068 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010069#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee4772012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300212static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200229 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382ce2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200391 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200398 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200399 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200400 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200401 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500402 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400403};
404
Johannes Berge31b8212010-10-05 19:39:30 +0200405/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000406static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200407 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 [NL80211_KEY_IDX] = { .type = NLA_U8 },
409 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200410 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200411 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
412 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200413 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100414 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
415};
416
417/* policy for the key default flags */
418static const struct nla_policy
419nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
420 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
421 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200422};
423
Johannes Bergff1b6e62011-05-04 15:37:28 +0200424/* policy for WoWLAN attributes */
425static const struct nla_policy
426nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
427 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200431 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100435 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300436 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100437};
438
439static const struct nla_policy
440nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
441 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
442 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
443 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
444 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
445 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
446 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
448 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
449 },
450 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
451 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
452 },
453 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
454 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
455 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200456};
457
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -0700458/* policy for coalesce rule attributes */
459static const struct nla_policy
460nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
461 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
462 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
463 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
464};
465
Johannes Berge5497d72011-07-05 16:35:40 +0200466/* policy for GTK rekey offload attributes */
467static const struct nla_policy
468nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
469 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
470 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
471 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
472};
473
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300474static const struct nla_policy
475nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200476 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300477 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700478 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300479};
480
Johannes Berg97990a02013-04-19 01:02:55 +0200481static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
482 struct netlink_callback *cb,
483 struct cfg80211_registered_device **rdev,
484 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100485{
Johannes Berg67748892010-10-04 21:14:06 +0200486 int err;
487
Johannes Berg67748892010-10-04 21:14:06 +0200488 rtnl_lock();
489
Johannes Berg97990a02013-04-19 01:02:55 +0200490 if (!cb->args[0]) {
491 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
492 nl80211_fam.attrbuf, nl80211_fam.maxattr,
493 nl80211_policy);
494 if (err)
495 goto out_unlock;
496
497 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
498 nl80211_fam.attrbuf);
499 if (IS_ERR(*wdev)) {
500 err = PTR_ERR(*wdev);
501 goto out_unlock;
502 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800503 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200504 /* 0 is the first index - add 1 to parse only once */
505 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200506 cb->args[1] = (*wdev)->identifier;
507 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200508 /* subtract the 1 again here */
509 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200510 struct wireless_dev *tmp;
511
512 if (!wiphy) {
513 err = -ENODEV;
514 goto out_unlock;
515 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800516 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200517 *wdev = NULL;
518
Johannes Berg97990a02013-04-19 01:02:55 +0200519 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
520 if (tmp->identifier == cb->args[1]) {
521 *wdev = tmp;
522 break;
523 }
524 }
Johannes Berg97990a02013-04-19 01:02:55 +0200525
526 if (!*wdev) {
527 err = -ENODEV;
528 goto out_unlock;
529 }
Johannes Berg67748892010-10-04 21:14:06 +0200530 }
531
Johannes Berg67748892010-10-04 21:14:06 +0200532 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200533 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200534 rtnl_unlock();
535 return err;
536}
537
Johannes Berg97990a02013-04-19 01:02:55 +0200538static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200539{
Johannes Berg67748892010-10-04 21:14:06 +0200540 rtnl_unlock();
541}
542
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100543/* IE validation */
544static bool is_valid_ie_attr(const struct nlattr *attr)
545{
546 const u8 *pos;
547 int len;
548
549 if (!attr)
550 return true;
551
552 pos = nla_data(attr);
553 len = nla_len(attr);
554
555 while (len) {
556 u8 elemlen;
557
558 if (len < 2)
559 return false;
560 len -= 2;
561
562 elemlen = pos[1];
563 if (elemlen > len)
564 return false;
565
566 len -= elemlen;
567 pos += 2 + elemlen;
568 }
569
570 return true;
571}
572
Johannes Berg55682962007-09-20 13:09:35 -0400573/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000574static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400575 int flags, u8 cmd)
576{
577 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000578 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400579}
580
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400581static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100582 struct ieee80211_channel *chan,
583 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400584{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200585 /* Some channels must be completely excluded from the
586 * list to protect old user-space tools from breaking
587 */
588 if (!large && chan->flags &
589 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
590 return 0;
591
David S. Miller9360ffd2012-03-29 04:41:26 -0400592 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
593 chan->center_freq))
594 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400595
David S. Miller9360ffd2012-03-29 04:41:26 -0400596 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
597 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
598 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200599 if (chan->flags & IEEE80211_CHAN_NO_IR) {
600 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
601 goto nla_put_failure;
602 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
603 goto nla_put_failure;
604 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100605 if (chan->flags & IEEE80211_CHAN_RADAR) {
606 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
607 goto nla_put_failure;
608 if (large) {
609 u32 time;
610
611 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
612
613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
614 chan->dfs_state))
615 goto nla_put_failure;
616 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
617 time))
618 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100619 if (nla_put_u32(msg,
620 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
621 chan->dfs_cac_ms))
622 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100623 }
624 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400625
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100626 if (large) {
627 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
635 goto nla_put_failure;
636 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
638 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200639 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
641 goto nla_put_failure;
642 if ((chan->flags & IEEE80211_CHAN_GO_CONCURRENT) &&
643 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_GO_CONCURRENT))
644 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200645 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
646 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
647 goto nla_put_failure;
648 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
649 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
650 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100651 }
652
David S. Miller9360ffd2012-03-29 04:41:26 -0400653 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
654 DBM_TO_MBM(chan->max_power)))
655 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400656
657 return 0;
658
659 nla_put_failure:
660 return -ENOBUFS;
661}
662
Johannes Berg55682962007-09-20 13:09:35 -0400663/* netlink command implementations */
664
Johannes Bergb9454e82009-07-08 13:29:08 +0200665struct key_parse {
666 struct key_params p;
667 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200668 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200669 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100670 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200671};
672
673static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
674{
675 struct nlattr *tb[NL80211_KEY_MAX + 1];
676 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
677 nl80211_key_policy);
678 if (err)
679 return err;
680
681 k->def = !!tb[NL80211_KEY_DEFAULT];
682 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
683
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100684 if (k->def) {
685 k->def_uni = true;
686 k->def_multi = true;
687 }
688 if (k->defmgmt)
689 k->def_multi = true;
690
Johannes Bergb9454e82009-07-08 13:29:08 +0200691 if (tb[NL80211_KEY_IDX])
692 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
693
694 if (tb[NL80211_KEY_DATA]) {
695 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
696 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
697 }
698
699 if (tb[NL80211_KEY_SEQ]) {
700 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
701 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
702 }
703
704 if (tb[NL80211_KEY_CIPHER])
705 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
706
Johannes Berge31b8212010-10-05 19:39:30 +0200707 if (tb[NL80211_KEY_TYPE]) {
708 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
709 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
710 return -EINVAL;
711 }
712
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100713 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
714 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100715 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
716 tb[NL80211_KEY_DEFAULT_TYPES],
717 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100718 if (err)
719 return err;
720
721 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
722 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
723 }
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 return 0;
726}
727
728static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
729{
730 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
731 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
732 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
733 }
734
735 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
736 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
737 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
738 }
739
740 if (info->attrs[NL80211_ATTR_KEY_IDX])
741 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
742
743 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
744 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
745
746 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
747 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
748
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100749 if (k->def) {
750 k->def_uni = true;
751 k->def_multi = true;
752 }
753 if (k->defmgmt)
754 k->def_multi = true;
755
Johannes Berge31b8212010-10-05 19:39:30 +0200756 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
757 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
758 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
759 return -EINVAL;
760 }
761
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100762 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
763 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
764 int err = nla_parse_nested(
765 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
766 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
767 nl80211_key_default_policy);
768 if (err)
769 return err;
770
771 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
772 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
773 }
774
Johannes Bergb9454e82009-07-08 13:29:08 +0200775 return 0;
776}
777
778static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
779{
780 int err;
781
782 memset(k, 0, sizeof(*k));
783 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200784 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200785
786 if (info->attrs[NL80211_ATTR_KEY])
787 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
788 else
789 err = nl80211_parse_key_old(info, k);
790
791 if (err)
792 return err;
793
794 if (k->def && k->defmgmt)
795 return -EINVAL;
796
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100797 if (k->defmgmt) {
798 if (k->def_uni || !k->def_multi)
799 return -EINVAL;
800 }
801
Johannes Bergb9454e82009-07-08 13:29:08 +0200802 if (k->idx != -1) {
803 if (k->defmgmt) {
804 if (k->idx < 4 || k->idx > 5)
805 return -EINVAL;
806 } else if (k->def) {
807 if (k->idx < 0 || k->idx > 3)
808 return -EINVAL;
809 } else {
810 if (k->idx < 0 || k->idx > 5)
811 return -EINVAL;
812 }
813 }
814
815 return 0;
816}
817
Johannes Bergfffd0932009-07-08 14:22:54 +0200818static struct cfg80211_cached_keys *
819nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530820 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200821{
822 struct key_parse parse;
823 struct nlattr *key;
824 struct cfg80211_cached_keys *result;
825 int rem, err, def = 0;
826
827 result = kzalloc(sizeof(*result), GFP_KERNEL);
828 if (!result)
829 return ERR_PTR(-ENOMEM);
830
831 result->def = -1;
832 result->defmgmt = -1;
833
834 nla_for_each_nested(key, keys, rem) {
835 memset(&parse, 0, sizeof(parse));
836 parse.idx = -1;
837
838 err = nl80211_parse_key_new(key, &parse);
839 if (err)
840 goto error;
841 err = -EINVAL;
842 if (!parse.p.key)
843 goto error;
844 if (parse.idx < 0 || parse.idx > 4)
845 goto error;
846 if (parse.def) {
847 if (def)
848 goto error;
849 def = 1;
850 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100851 if (!parse.def_uni || !parse.def_multi)
852 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200853 } else if (parse.defmgmt)
854 goto error;
855 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200856 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200857 if (err)
858 goto error;
859 result->params[parse.idx].cipher = parse.p.cipher;
860 result->params[parse.idx].key_len = parse.p.key_len;
861 result->params[parse.idx].key = result->data[parse.idx];
862 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530863
864 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
865 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
866 if (no_ht)
867 *no_ht = true;
868 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200869 }
870
871 return result;
872 error:
873 kfree(result);
874 return ERR_PTR(err);
875}
876
877static int nl80211_key_allowed(struct wireless_dev *wdev)
878{
879 ASSERT_WDEV_LOCK(wdev);
880
Johannes Bergfffd0932009-07-08 14:22:54 +0200881 switch (wdev->iftype) {
882 case NL80211_IFTYPE_AP:
883 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200884 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700885 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200886 break;
887 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200889 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200890 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200891 return -ENOLINK;
892 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100893 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100894 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100895 case NL80211_IFTYPE_MONITOR:
896 case NL80211_IFTYPE_P2P_DEVICE:
897 case NL80211_IFTYPE_WDS:
898 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200899 return -EINVAL;
900 }
901
902 return 0;
903}
904
Jouni Malinen664834d2014-01-15 00:01:44 +0200905static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
906 struct nlattr *tb)
907{
908 struct ieee80211_channel *chan;
909
910 if (tb == NULL)
911 return NULL;
912 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
913 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
914 return NULL;
915 return chan;
916}
917
Johannes Berg7527a782011-05-13 10:58:57 +0200918static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
919{
920 struct nlattr *nl_modes = nla_nest_start(msg, attr);
921 int i;
922
923 if (!nl_modes)
924 goto nla_put_failure;
925
926 i = 0;
927 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400928 if ((ifmodes & 1) && nla_put_flag(msg, i))
929 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200930 ifmodes >>= 1;
931 i++;
932 }
933
934 nla_nest_end(msg, nl_modes);
935 return 0;
936
937nla_put_failure:
938 return -ENOBUFS;
939}
940
941static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100942 struct sk_buff *msg,
943 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200944{
945 struct nlattr *nl_combis;
946 int i, j;
947
948 nl_combis = nla_nest_start(msg,
949 NL80211_ATTR_INTERFACE_COMBINATIONS);
950 if (!nl_combis)
951 goto nla_put_failure;
952
953 for (i = 0; i < wiphy->n_iface_combinations; i++) {
954 const struct ieee80211_iface_combination *c;
955 struct nlattr *nl_combi, *nl_limits;
956
957 c = &wiphy->iface_combinations[i];
958
959 nl_combi = nla_nest_start(msg, i + 1);
960 if (!nl_combi)
961 goto nla_put_failure;
962
963 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
964 if (!nl_limits)
965 goto nla_put_failure;
966
967 for (j = 0; j < c->n_limits; j++) {
968 struct nlattr *nl_limit;
969
970 nl_limit = nla_nest_start(msg, j + 1);
971 if (!nl_limit)
972 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400973 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
974 c->limits[j].max))
975 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200976 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
977 c->limits[j].types))
978 goto nla_put_failure;
979 nla_nest_end(msg, nl_limit);
980 }
981
982 nla_nest_end(msg, nl_limits);
983
David S. Miller9360ffd2012-03-29 04:41:26 -0400984 if (c->beacon_int_infra_match &&
985 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
986 goto nla_put_failure;
987 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
988 c->num_different_channels) ||
989 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
990 c->max_interfaces))
991 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100992 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200993 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
994 c->radar_detect_widths) ||
995 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
996 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100997 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200998
999 nla_nest_end(msg, nl_combi);
1000 }
1001
1002 nla_nest_end(msg, nl_combis);
1003
1004 return 0;
1005nla_put_failure:
1006 return -ENOBUFS;
1007}
1008
Johannes Berg3713b4e2013-02-14 16:19:38 +01001009#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001010static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1011 struct sk_buff *msg)
1012{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001013 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001014 struct nlattr *nl_tcp;
1015
1016 if (!tcp)
1017 return 0;
1018
1019 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1020 if (!nl_tcp)
1021 return -ENOBUFS;
1022
1023 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1024 tcp->data_payload_max))
1025 return -ENOBUFS;
1026
1027 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1028 tcp->data_payload_max))
1029 return -ENOBUFS;
1030
1031 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1032 return -ENOBUFS;
1033
1034 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1035 sizeof(*tcp->tok), tcp->tok))
1036 return -ENOBUFS;
1037
1038 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1039 tcp->data_interval_max))
1040 return -ENOBUFS;
1041
1042 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1043 tcp->wake_payload_max))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_tcp);
1047 return 0;
1048}
1049
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001052 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053{
1054 struct nlattr *nl_wowlan;
1055
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 return 0;
1058
1059 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1060 if (!nl_wowlan)
1061 return -ENOBUFS;
1062
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001066 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001067 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001068 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001069 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001070 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001071 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001073 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001074 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1079 return -ENOBUFS;
1080
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001081 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001082 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001083 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1084 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1085 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1086 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087 };
1088
1089 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1090 sizeof(pat), &pat))
1091 return -ENOBUFS;
1092 }
1093
Luciano Coelho75453cc2015-01-09 14:06:37 +02001094 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1095 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1096 rdev->wiphy.wowlan->max_nd_match_sets))
1097 return -ENOBUFS;
1098
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001099 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001100 return -ENOBUFS;
1101
Luciano Coelho8cd4d452014-09-17 11:55:28 +03001102 /* TODO: send wowlan net detect */
1103
Johannes Berg3713b4e2013-02-14 16:19:38 +01001104 nla_nest_end(msg, nl_wowlan);
1105
1106 return 0;
1107}
1108#endif
1109
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001110static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001111 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001112{
1113 struct nl80211_coalesce_rule_support rule;
1114
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001115 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001116 return 0;
1117
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001118 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1119 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1120 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1121 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1122 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1123 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001124
1125 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1126 return -ENOBUFS;
1127
1128 return 0;
1129}
1130
Johannes Berg3713b4e2013-02-14 16:19:38 +01001131static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1132 struct ieee80211_supported_band *sband)
1133{
1134 struct nlattr *nl_rates, *nl_rate;
1135 struct ieee80211_rate *rate;
1136 int i;
1137
1138 /* add HT info */
1139 if (sband->ht_cap.ht_supported &&
1140 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1141 sizeof(sband->ht_cap.mcs),
1142 &sband->ht_cap.mcs) ||
1143 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1144 sband->ht_cap.cap) ||
1145 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1146 sband->ht_cap.ampdu_factor) ||
1147 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1148 sband->ht_cap.ampdu_density)))
1149 return -ENOBUFS;
1150
1151 /* add VHT info */
1152 if (sband->vht_cap.vht_supported &&
1153 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1154 sizeof(sband->vht_cap.vht_mcs),
1155 &sband->vht_cap.vht_mcs) ||
1156 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1157 sband->vht_cap.cap)))
1158 return -ENOBUFS;
1159
1160 /* add bitrates */
1161 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1162 if (!nl_rates)
1163 return -ENOBUFS;
1164
1165 for (i = 0; i < sband->n_bitrates; i++) {
1166 nl_rate = nla_nest_start(msg, i);
1167 if (!nl_rate)
1168 return -ENOBUFS;
1169
1170 rate = &sband->bitrates[i];
1171 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1172 rate->bitrate))
1173 return -ENOBUFS;
1174 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1175 nla_put_flag(msg,
1176 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1177 return -ENOBUFS;
1178
1179 nla_nest_end(msg, nl_rate);
1180 }
1181
1182 nla_nest_end(msg, nl_rates);
1183
1184 return 0;
1185}
1186
1187static int
1188nl80211_send_mgmt_stypes(struct sk_buff *msg,
1189 const struct ieee80211_txrx_stypes *mgmt_stypes)
1190{
1191 u16 stypes;
1192 struct nlattr *nl_ftypes, *nl_ifs;
1193 enum nl80211_iftype ift;
1194 int i;
1195
1196 if (!mgmt_stypes)
1197 return 0;
1198
1199 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1200 if (!nl_ifs)
1201 return -ENOBUFS;
1202
1203 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1204 nl_ftypes = nla_nest_start(msg, ift);
1205 if (!nl_ftypes)
1206 return -ENOBUFS;
1207 i = 0;
1208 stypes = mgmt_stypes[ift].tx;
1209 while (stypes) {
1210 if ((stypes & 1) &&
1211 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1212 (i << 4) | IEEE80211_FTYPE_MGMT))
1213 return -ENOBUFS;
1214 stypes >>= 1;
1215 i++;
1216 }
1217 nla_nest_end(msg, nl_ftypes);
1218 }
1219
1220 nla_nest_end(msg, nl_ifs);
1221
1222 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1223 if (!nl_ifs)
1224 return -ENOBUFS;
1225
1226 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1227 nl_ftypes = nla_nest_start(msg, ift);
1228 if (!nl_ftypes)
1229 return -ENOBUFS;
1230 i = 0;
1231 stypes = mgmt_stypes[ift].rx;
1232 while (stypes) {
1233 if ((stypes & 1) &&
1234 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1235 (i << 4) | IEEE80211_FTYPE_MGMT))
1236 return -ENOBUFS;
1237 stypes >>= 1;
1238 i++;
1239 }
1240 nla_nest_end(msg, nl_ftypes);
1241 }
1242 nla_nest_end(msg, nl_ifs);
1243
1244 return 0;
1245}
1246
Johannes Berg86e8cf92013-06-19 10:57:22 +02001247struct nl80211_dump_wiphy_state {
1248 s64 filter_wiphy;
1249 long start;
1250 long split_start, band_start, chan_start;
1251 bool split;
1252};
1253
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001254static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001255 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001256 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001257 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001258{
1259 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001260 struct nlattr *nl_bands, *nl_band;
1261 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001262 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001263 enum ieee80211_band band;
1264 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001265 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001266 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001267 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001268 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001269
Johannes Berg3bb20552014-05-26 13:52:25 +02001270 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001271 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001272 return -ENOBUFS;
1273
Johannes Berg86e8cf92013-06-19 10:57:22 +02001274 if (WARN_ON(!state))
1275 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001276
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001278 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001279 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001280 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001281 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001282 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001283
Johannes Berg3bb20552014-05-26 13:52:25 +02001284 if (cmd != NL80211_CMD_NEW_WIPHY)
1285 goto finish;
1286
Johannes Berg86e8cf92013-06-19 10:57:22 +02001287 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001288 case 0:
1289 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001304 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001307 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001308 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001309 goto nla_put_failure;
1310
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001311 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001312 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1313 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001314 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001315 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1316 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001317 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001318 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1319 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001320 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001321 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1322 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001323 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001324 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1325 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001326 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001327 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001328 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001329 state->split_start++;
1330 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001331 break;
1332 case 1:
1333 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001334 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1335 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001336 goto nla_put_failure;
1337
Johannes Berg3713b4e2013-02-14 16:19:38 +01001338 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001339 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001340 goto nla_put_failure;
1341
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001342 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001343 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1344 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001345
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001347 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001349 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001350 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001351
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001352 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001354 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001355 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001356
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001357 if ((rdev->wiphy.available_antennas_tx ||
1358 rdev->wiphy.available_antennas_rx) &&
1359 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001360 u32 tx_ant = 0, rx_ant = 0;
1361 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001362 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001363 if (!res) {
1364 if (nla_put_u32(msg,
1365 NL80211_ATTR_WIPHY_ANTENNA_TX,
1366 tx_ant) ||
1367 nla_put_u32(msg,
1368 NL80211_ATTR_WIPHY_ANTENNA_RX,
1369 rx_ant))
1370 goto nla_put_failure;
1371 }
Johannes Bergee688b002008-01-24 19:38:39 +01001372 }
1373
Johannes Berg86e8cf92013-06-19 10:57:22 +02001374 state->split_start++;
1375 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001376 break;
1377 case 2:
1378 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001379 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001380 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001381 state->split_start++;
1382 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001383 break;
1384 case 3:
1385 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1386 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001387 goto nla_put_failure;
1388
Johannes Berg86e8cf92013-06-19 10:57:22 +02001389 for (band = state->band_start;
1390 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001391 struct ieee80211_supported_band *sband;
1392
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001393 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001394
1395 if (!sband)
1396 continue;
1397
1398 nl_band = nla_nest_start(msg, band);
1399 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001400 goto nla_put_failure;
1401
Johannes Berg86e8cf92013-06-19 10:57:22 +02001402 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001403 case 0:
1404 if (nl80211_send_band_rateinfo(msg, sband))
1405 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001406 state->chan_start++;
1407 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001408 break;
1409 default:
1410 /* add frequencies */
1411 nl_freqs = nla_nest_start(
1412 msg, NL80211_BAND_ATTR_FREQS);
1413 if (!nl_freqs)
1414 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001415
Johannes Berg86e8cf92013-06-19 10:57:22 +02001416 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001417 i < sband->n_channels;
1418 i++) {
1419 nl_freq = nla_nest_start(msg, i);
1420 if (!nl_freq)
1421 goto nla_put_failure;
1422
1423 chan = &sband->channels[i];
1424
Johannes Berg86e8cf92013-06-19 10:57:22 +02001425 if (nl80211_msg_put_channel(
1426 msg, chan,
1427 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001428 goto nla_put_failure;
1429
1430 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001431 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001432 break;
1433 }
1434 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001437 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001438 nla_nest_end(msg, nl_freqs);
1439 }
1440
1441 nla_nest_end(msg, nl_band);
1442
Johannes Berg86e8cf92013-06-19 10:57:22 +02001443 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001445 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001446 band--;
1447 break;
1448 }
Johannes Bergee688b002008-01-24 19:38:39 +01001449 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001451
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001453 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001454 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001455 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001456
Johannes Berg3713b4e2013-02-14 16:19:38 +01001457 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001458 if (state->band_start == 0 && state->chan_start == 0)
1459 state->split_start++;
1460 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001461 break;
1462 case 4:
1463 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1464 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001465 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001466
1467 i = 0;
1468#define CMD(op, n) \
1469 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001470 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001471 i++; \
1472 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1473 goto nla_put_failure; \
1474 } \
1475 } while (0)
1476
1477 CMD(add_virtual_intf, NEW_INTERFACE);
1478 CMD(change_virtual_intf, SET_INTERFACE);
1479 CMD(add_key, NEW_KEY);
1480 CMD(start_ap, START_AP);
1481 CMD(add_station, NEW_STATION);
1482 CMD(add_mpath, NEW_MPATH);
1483 CMD(update_mesh_config, SET_MESH_CONFIG);
1484 CMD(change_bss, SET_BSS);
1485 CMD(auth, AUTHENTICATE);
1486 CMD(assoc, ASSOCIATE);
1487 CMD(deauth, DEAUTHENTICATE);
1488 CMD(disassoc, DISASSOCIATE);
1489 CMD(join_ibss, JOIN_IBSS);
1490 CMD(join_mesh, JOIN_MESH);
1491 CMD(set_pmksa, SET_PMKSA);
1492 CMD(del_pmksa, DEL_PMKSA);
1493 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001494 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001495 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1496 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1497 CMD(mgmt_tx, FRAME);
1498 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001499 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001500 i++;
1501 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1502 goto nla_put_failure;
1503 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001504 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1505 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001506 i++;
1507 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1508 goto nla_put_failure;
1509 }
1510 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001511 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001512 CMD(tdls_mgmt, TDLS_MGMT);
1513 CMD(tdls_oper, TDLS_OPER);
1514 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001515 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001516 CMD(sched_scan_start, START_SCHED_SCAN);
1517 CMD(probe_client, PROBE_CLIENT);
1518 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001519 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001520 i++;
1521 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1522 goto nla_put_failure;
1523 }
1524 CMD(start_p2p_device, START_P2P_DEVICE);
1525 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001526#ifdef CONFIG_NL80211_TESTMODE
1527 CMD(testmode_cmd, TESTMODE);
1528#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001529 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001530 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1531 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001532 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001533 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001534 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001535 if (rdev->wiphy.features &
1536 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001537 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001538 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001539 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001540#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001541
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001542 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001543 i++;
1544 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001545 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001546 }
1547
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001548 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001549 i++;
1550 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1551 goto nla_put_failure;
1552 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001553
Johannes Berg3713b4e2013-02-14 16:19:38 +01001554 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001555 state->split_start++;
1556 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001557 break;
1558 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001559 if (rdev->ops->remain_on_channel &&
1560 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001561 nla_put_u32(msg,
1562 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001563 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001564 goto nla_put_failure;
1565
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001566 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001567 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1568 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001569
Johannes Berg3713b4e2013-02-14 16:19:38 +01001570 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1571 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001572 state->split_start++;
1573 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001574 break;
1575 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001576#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001577 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001578 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001579 state->split_start++;
1580 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001581 break;
1582#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001583 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001584#endif
1585 case 7:
1586 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001587 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001588 goto nla_put_failure;
1589
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001590 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001591 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001592 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001593
Johannes Berg86e8cf92013-06-19 10:57:22 +02001594 state->split_start++;
1595 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001596 break;
1597 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001600 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001601 goto nla_put_failure;
1602
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001603 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001604 /*
1605 * We can only add the per-channel limit information if the
1606 * dump is split, otherwise it makes it too big. Therefore
1607 * only advertise it in that case.
1608 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001609 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001610 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1611 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001612 goto nla_put_failure;
1613
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001615 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001616 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1617 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001618 goto nla_put_failure;
1619
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001620 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1621 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001623 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001624 goto nla_put_failure;
1625
1626 /*
1627 * Any information below this point is only available to
1628 * applications that can deal with it being split. This
1629 * helps ensure that newly added capabilities don't break
1630 * older tools by overrunning their buffers.
1631 *
1632 * We still increment split_start so that in the split
1633 * case we'll continue with more data in the next round,
1634 * but break unconditionally so unsplit data stops here.
1635 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001636 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001637 break;
1638 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001640 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001641 rdev->wiphy.extended_capabilities_len,
1642 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001643 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001644 rdev->wiphy.extended_capabilities_len,
1645 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001646 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001647
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001648 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001649 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001650 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1651 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001652 goto nla_put_failure;
1653
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001654 state->split_start++;
1655 break;
1656 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001657 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07001658 goto nla_put_failure;
1659
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001660 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001661 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1662 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1663 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001664
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001665 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001666 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001667 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001668 goto nla_put_failure;
1669
Johannes Bergad7e7182013-11-13 13:37:47 +01001670 state->split_start++;
1671 break;
1672 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001673 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001674 const struct nl80211_vendor_cmd_info *info;
1675 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001676
Johannes Berg567ffc32013-12-18 14:43:31 +01001677 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1678 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001679 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001680
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001681 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1682 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001683 if (nla_put(msg, i + 1, sizeof(*info), info))
1684 goto nla_put_failure;
1685 }
1686 nla_nest_end(msg, nested);
1687 }
1688
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001689 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001690 const struct nl80211_vendor_cmd_info *info;
1691 struct nlattr *nested;
1692
1693 nested = nla_nest_start(msg,
1694 NL80211_ATTR_VENDOR_EVENTS);
1695 if (!nested)
1696 goto nla_put_failure;
1697
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001698 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1699 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001700 if (nla_put(msg, i + 1, sizeof(*info), info))
1701 goto nla_put_failure;
1702 }
1703 nla_nest_end(msg, nested);
1704 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001705 state->split_start++;
1706 break;
1707 case 12:
1708 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1709 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1710 rdev->wiphy.max_num_csa_counters))
1711 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001712
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001713 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1714 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1715 goto nla_put_failure;
1716
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001717 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1718 sizeof(rdev->wiphy.ext_features),
1719 rdev->wiphy.ext_features))
1720 goto nla_put_failure;
1721
Johannes Berg3713b4e2013-02-14 16:19:38 +01001722 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001723 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001724 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001725 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001726 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001727 genlmsg_end(msg, hdr);
1728 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001729
1730 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001731 genlmsg_cancel(msg, hdr);
1732 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001733}
1734
Johannes Berg86e8cf92013-06-19 10:57:22 +02001735static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1736 struct netlink_callback *cb,
1737 struct nl80211_dump_wiphy_state *state)
1738{
1739 struct nlattr **tb = nl80211_fam.attrbuf;
1740 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1741 tb, nl80211_fam.maxattr, nl80211_policy);
1742 /* ignore parse errors for backward compatibility */
1743 if (ret)
1744 return 0;
1745
1746 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1747 if (tb[NL80211_ATTR_WIPHY])
1748 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1749 if (tb[NL80211_ATTR_WDEV])
1750 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1751 if (tb[NL80211_ATTR_IFINDEX]) {
1752 struct net_device *netdev;
1753 struct cfg80211_registered_device *rdev;
1754 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1755
Ying Xue7f2b8562014-01-15 10:23:45 +08001756 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001757 if (!netdev)
1758 return -ENODEV;
1759 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001760 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001761 netdev->ieee80211_ptr->wiphy);
1762 state->filter_wiphy = rdev->wiphy_idx;
1763 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001764 }
1765
1766 return 0;
1767}
1768
Johannes Berg55682962007-09-20 13:09:35 -04001769static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1770{
Johannes Berg645e77d2013-03-01 14:03:49 +01001771 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001772 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001773 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001774
Johannes Berg5fe231e2013-05-08 21:45:15 +02001775 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001776 if (!state) {
1777 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001778 if (!state) {
1779 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001780 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001781 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001782 state->filter_wiphy = -1;
1783 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1784 if (ret) {
1785 kfree(state);
1786 rtnl_unlock();
1787 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001789 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001790 }
1791
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001792 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1793 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001794 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001795 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001796 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001797 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001798 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001799 continue;
1800 /* attempt to fit multiple wiphy data chunks into the skb */
1801 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001802 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1803 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001804 NETLINK_CB(cb->skb).portid,
1805 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001806 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001807 if (ret < 0) {
1808 /*
1809 * If sending the wiphy data didn't fit (ENOBUFS
1810 * or EMSGSIZE returned), this SKB is still
1811 * empty (so it's not too big because another
1812 * wiphy dataset is already in the skb) and
1813 * we've not tried to adjust the dump allocation
1814 * yet ... then adjust the alloc size to be
1815 * bigger, and return 1 but with the empty skb.
1816 * This results in an empty message being RX'ed
1817 * in userspace, but that is ignored.
1818 *
1819 * We can then retry with the larger buffer.
1820 */
1821 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001822 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001823 cb->min_dump_alloc < 4096) {
1824 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001825 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001826 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001827 return 1;
1828 }
1829 idx--;
1830 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001831 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001832 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001833 break;
Johannes Berg55682962007-09-20 13:09:35 -04001834 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001835 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001836
Johannes Berg86e8cf92013-06-19 10:57:22 +02001837 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001838
1839 return skb->len;
1840}
1841
Johannes Berg86e8cf92013-06-19 10:57:22 +02001842static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1843{
1844 kfree((void *)cb->args[0]);
1845 return 0;
1846}
1847
Johannes Berg55682962007-09-20 13:09:35 -04001848static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1849{
1850 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001851 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001852 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001853
Johannes Berg645e77d2013-03-01 14:03:49 +01001854 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001855 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001856 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001857
Johannes Berg3bb20552014-05-26 13:52:25 +02001858 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1859 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001860 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001861 nlmsg_free(msg);
1862 return -ENOBUFS;
1863 }
Johannes Berg55682962007-09-20 13:09:35 -04001864
Johannes Berg134e6372009-07-10 09:51:34 +00001865 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001866}
1867
Jouni Malinen31888482008-10-30 16:59:24 +02001868static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1869 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1870 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1871 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1872 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1873 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1874};
1875
1876static int parse_txq_params(struct nlattr *tb[],
1877 struct ieee80211_txq_params *txq_params)
1878{
Johannes Berga3304b02012-03-28 11:04:24 +02001879 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001880 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1881 !tb[NL80211_TXQ_ATTR_AIFS])
1882 return -EINVAL;
1883
Johannes Berga3304b02012-03-28 11:04:24 +02001884 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001885 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1886 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1887 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1888 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1889
Johannes Berga3304b02012-03-28 11:04:24 +02001890 if (txq_params->ac >= NL80211_NUM_ACS)
1891 return -EINVAL;
1892
Jouni Malinen31888482008-10-30 16:59:24 +02001893 return 0;
1894}
1895
Johannes Bergf444de02010-05-05 15:25:02 +02001896static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1897{
1898 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001899 * You can only set the channel explicitly for WDS interfaces,
1900 * all others have their channel managed via their respective
1901 * "establish a connection" command (connect, join, ...)
1902 *
1903 * For AP/GO and mesh mode, the channel can be set with the
1904 * channel userspace API, but is only stored and passed to the
1905 * low-level driver when the AP starts or the mesh is joined.
1906 * This is for backward compatibility, userspace can also give
1907 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001908 *
1909 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001910 * whatever else is going on, so they have their own special
1911 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001912 */
1913 return !wdev ||
1914 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001915 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001916 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1917 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001918}
1919
Johannes Berg683b6d32012-11-08 21:25:48 +01001920static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1921 struct genl_info *info,
1922 struct cfg80211_chan_def *chandef)
1923{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301924 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001925
1926 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1927 return -EINVAL;
1928
1929 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1930
1931 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001932 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1933 chandef->center_freq1 = control_freq;
1934 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001935
1936 /* Primary channel not allowed */
1937 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1938 return -EINVAL;
1939
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001940 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1941 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001942
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001943 chantype = nla_get_u32(
1944 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1945
1946 switch (chantype) {
1947 case NL80211_CHAN_NO_HT:
1948 case NL80211_CHAN_HT20:
1949 case NL80211_CHAN_HT40PLUS:
1950 case NL80211_CHAN_HT40MINUS:
1951 cfg80211_chandef_create(chandef, chandef->chan,
1952 chantype);
1953 break;
1954 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001955 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001956 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001957 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1958 chandef->width =
1959 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1960 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1961 chandef->center_freq1 =
1962 nla_get_u32(
1963 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1964 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1965 chandef->center_freq2 =
1966 nla_get_u32(
1967 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1968 }
1969
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001970 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001971 return -EINVAL;
1972
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001973 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1974 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001975 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001976
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001977 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1978 chandef->width == NL80211_CHAN_WIDTH_10) &&
1979 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1980 return -EINVAL;
1981
Johannes Berg683b6d32012-11-08 21:25:48 +01001982 return 0;
1983}
1984
Johannes Bergf444de02010-05-05 15:25:02 +02001985static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001986 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001987 struct genl_info *info)
1988{
Johannes Berg683b6d32012-11-08 21:25:48 +01001989 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001990 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001991 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001992 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001993
Jouni Malinene16821b2014-04-28 11:22:08 +03001994 if (dev)
1995 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001996 if (!nl80211_can_set_dev_channel(wdev))
1997 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001998 if (wdev)
1999 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02002000
Johannes Berg683b6d32012-11-08 21:25:48 +01002001 result = nl80211_parse_chandef(rdev, info, &chandef);
2002 if (result)
2003 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002004
Johannes Berge8c9bd52012-06-06 08:18:22 +02002005 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002006 case NL80211_IFTYPE_AP:
2007 case NL80211_IFTYPE_P2P_GO:
Ilan Peer174e0cd2014-02-23 09:13:01 +02002008 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002009 result = -EINVAL;
2010 break;
2011 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002012 if (wdev->beacon_interval) {
2013 if (!dev || !rdev->ops->set_ap_chanwidth ||
2014 !(rdev->wiphy.features &
2015 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2016 result = -EBUSY;
2017 break;
2018 }
2019
2020 /* Only allow dynamic channel width changes */
2021 if (chandef.chan != wdev->preset_chandef.chan) {
2022 result = -EBUSY;
2023 break;
2024 }
2025 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2026 if (result)
2027 break;
2028 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002029 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002030 result = 0;
2031 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002032 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002033 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002034 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002035 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002036 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002037 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002038 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002039 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002040 }
Johannes Bergf444de02010-05-05 15:25:02 +02002041
2042 return result;
2043}
2044
2045static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2046{
Johannes Berg4c476992010-10-04 21:36:35 +02002047 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2048 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002049
Jouni Malinene16821b2014-04-28 11:22:08 +03002050 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002051}
2052
Bill Jordane8347eb2010-10-01 13:54:28 -04002053static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2054{
Johannes Berg43b19952010-10-07 13:10:30 +02002055 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2056 struct net_device *dev = info->user_ptr[1];
2057 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002058 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002059
2060 if (!info->attrs[NL80211_ATTR_MAC])
2061 return -EINVAL;
2062
Johannes Berg43b19952010-10-07 13:10:30 +02002063 if (netif_running(dev))
2064 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002065
Johannes Berg43b19952010-10-07 13:10:30 +02002066 if (!rdev->ops->set_wds_peer)
2067 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002068
Johannes Berg43b19952010-10-07 13:10:30 +02002069 if (wdev->iftype != NL80211_IFTYPE_WDS)
2070 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002071
2072 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002073 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002074}
2075
2076
Johannes Berg55682962007-09-20 13:09:35 -04002077static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2078{
2079 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002080 struct net_device *netdev = NULL;
2081 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002082 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002083 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002084 u32 changed;
2085 u8 retry_short = 0, retry_long = 0;
2086 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002087 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002088
Johannes Berg5fe231e2013-05-08 21:45:15 +02002089 ASSERT_RTNL();
2090
Johannes Bergf444de02010-05-05 15:25:02 +02002091 /*
2092 * Try to find the wiphy and netdev. Normally this
2093 * function shouldn't need the netdev, but this is
2094 * done for backward compatibility -- previously
2095 * setting the channel was done per wiphy, but now
2096 * it is per netdev. Previous userland like hostapd
2097 * also passed a netdev to set_wiphy, so that it is
2098 * possible to let that go to the right netdev!
2099 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002100
Johannes Bergf444de02010-05-05 15:25:02 +02002101 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2102 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2103
Ying Xue7f2b8562014-01-15 10:23:45 +08002104 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002105 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002106 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002107 else
Johannes Bergf444de02010-05-05 15:25:02 +02002108 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002109 }
2110
Johannes Bergf444de02010-05-05 15:25:02 +02002111 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002112 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2113 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002114 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002115 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002116 wdev = NULL;
2117 netdev = NULL;
2118 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002119 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002120 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002121
2122 /*
2123 * end workaround code, by now the rdev is available
2124 * and locked, and wdev may or may not be NULL.
2125 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002126
2127 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002128 result = cfg80211_dev_rename(
2129 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002130
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002131 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002132 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002133
Jouni Malinen31888482008-10-30 16:59:24 +02002134 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2135 struct ieee80211_txq_params txq_params;
2136 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2137
Ying Xue7f2b8562014-01-15 10:23:45 +08002138 if (!rdev->ops->set_txq_params)
2139 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002140
Ying Xue7f2b8562014-01-15 10:23:45 +08002141 if (!netdev)
2142 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002143
Johannes Berg133a3ff2011-11-03 14:50:13 +01002144 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002145 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2146 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002147
Ying Xue7f2b8562014-01-15 10:23:45 +08002148 if (!netif_running(netdev))
2149 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002150
Jouni Malinen31888482008-10-30 16:59:24 +02002151 nla_for_each_nested(nl_txq_params,
2152 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2153 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002154 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2155 nla_data(nl_txq_params),
2156 nla_len(nl_txq_params),
2157 txq_params_policy);
2158 if (result)
2159 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002160 result = parse_txq_params(tb, &txq_params);
2161 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002162 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002163
Hila Gonene35e4d22012-06-27 17:19:42 +03002164 result = rdev_set_txq_params(rdev, netdev,
2165 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002166 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002167 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002168 }
2169 }
2170
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002171 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002172 result = __nl80211_set_channel(
2173 rdev,
2174 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2175 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002176 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002177 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002178 }
2179
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002180 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002181 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002182 enum nl80211_tx_power_setting type;
2183 int idx, mbm = 0;
2184
Johannes Bergc8442112012-10-24 10:17:18 +02002185 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2186 txp_wdev = NULL;
2187
Ying Xue7f2b8562014-01-15 10:23:45 +08002188 if (!rdev->ops->set_tx_power)
2189 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002190
2191 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2192 type = nla_get_u32(info->attrs[idx]);
2193
2194 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002195 (type != NL80211_TX_POWER_AUTOMATIC))
2196 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002197
2198 if (type != NL80211_TX_POWER_AUTOMATIC) {
2199 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2200 mbm = nla_get_u32(info->attrs[idx]);
2201 }
2202
Johannes Bergc8442112012-10-24 10:17:18 +02002203 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002204 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002205 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002206 }
2207
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002208 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2209 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2210 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002211 if ((!rdev->wiphy.available_antennas_tx &&
2212 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002213 !rdev->ops->set_antenna)
2214 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002215
2216 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2217 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2218
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002219 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002220 * available antenna masks, except for the "all" mask */
2221 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002222 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2223 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002224
Bruno Randolf7f531e02010-12-16 11:30:22 +09002225 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2226 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002227
Hila Gonene35e4d22012-06-27 17:19:42 +03002228 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002229 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002230 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002231 }
2232
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002233 changed = 0;
2234
2235 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2236 retry_short = nla_get_u8(
2237 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002238 if (retry_short == 0)
2239 return -EINVAL;
2240
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002241 changed |= WIPHY_PARAM_RETRY_SHORT;
2242 }
2243
2244 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2245 retry_long = nla_get_u8(
2246 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002247 if (retry_long == 0)
2248 return -EINVAL;
2249
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002250 changed |= WIPHY_PARAM_RETRY_LONG;
2251 }
2252
2253 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2254 frag_threshold = nla_get_u32(
2255 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002256 if (frag_threshold < 256)
2257 return -EINVAL;
2258
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002259 if (frag_threshold != (u32) -1) {
2260 /*
2261 * Fragments (apart from the last one) are required to
2262 * have even length. Make the fragmentation code
2263 * simpler by stripping LSB should someone try to use
2264 * odd threshold value.
2265 */
2266 frag_threshold &= ~0x1;
2267 }
2268 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2269 }
2270
2271 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2272 rts_threshold = nla_get_u32(
2273 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2274 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2275 }
2276
Lukáš Turek81077e82009-12-21 22:50:47 +01002277 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002278 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2279 return -EINVAL;
2280
Lukáš Turek81077e82009-12-21 22:50:47 +01002281 coverage_class = nla_get_u8(
2282 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2283 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2284 }
2285
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002286 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2287 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2288 return -EOPNOTSUPP;
2289
2290 changed |= WIPHY_PARAM_DYN_ACK;
2291 }
2292
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002293 if (changed) {
2294 u8 old_retry_short, old_retry_long;
2295 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002296 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002297
Ying Xue7f2b8562014-01-15 10:23:45 +08002298 if (!rdev->ops->set_wiphy_params)
2299 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002300
2301 old_retry_short = rdev->wiphy.retry_short;
2302 old_retry_long = rdev->wiphy.retry_long;
2303 old_frag_threshold = rdev->wiphy.frag_threshold;
2304 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002305 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002306
2307 if (changed & WIPHY_PARAM_RETRY_SHORT)
2308 rdev->wiphy.retry_short = retry_short;
2309 if (changed & WIPHY_PARAM_RETRY_LONG)
2310 rdev->wiphy.retry_long = retry_long;
2311 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2312 rdev->wiphy.frag_threshold = frag_threshold;
2313 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2314 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002315 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2316 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002317
Hila Gonene35e4d22012-06-27 17:19:42 +03002318 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002319 if (result) {
2320 rdev->wiphy.retry_short = old_retry_short;
2321 rdev->wiphy.retry_long = old_retry_long;
2322 rdev->wiphy.frag_threshold = old_frag_threshold;
2323 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002324 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002325 }
2326 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002327 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002328}
2329
Johannes Berg71bbc992012-06-15 15:30:18 +02002330static inline u64 wdev_id(struct wireless_dev *wdev)
2331{
2332 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002333 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002334}
Johannes Berg55682962007-09-20 13:09:35 -04002335
Johannes Berg683b6d32012-11-08 21:25:48 +01002336static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002337 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002338{
Johannes Berg601555c2014-11-27 17:26:56 +01002339 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2340 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002341
Johannes Berg683b6d32012-11-08 21:25:48 +01002342 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2343 chandef->chan->center_freq))
2344 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002345 switch (chandef->width) {
2346 case NL80211_CHAN_WIDTH_20_NOHT:
2347 case NL80211_CHAN_WIDTH_20:
2348 case NL80211_CHAN_WIDTH_40:
2349 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2350 cfg80211_get_chandef_type(chandef)))
2351 return -ENOBUFS;
2352 break;
2353 default:
2354 break;
2355 }
2356 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2357 return -ENOBUFS;
2358 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2359 return -ENOBUFS;
2360 if (chandef->center_freq2 &&
2361 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002362 return -ENOBUFS;
2363 return 0;
2364}
2365
Eric W. Biederman15e47302012-09-07 20:12:54 +00002366static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002367 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002368 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002369{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002370 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002371 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002372 void *hdr;
2373
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002374 if (removal)
2375 cmd = NL80211_CMD_DEL_INTERFACE;
2376
2377 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002378 if (!hdr)
2379 return -1;
2380
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002381 if (dev &&
2382 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002383 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002384 goto nla_put_failure;
2385
2386 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2387 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002388 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002389 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002390 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2391 rdev->devlist_generation ^
2392 (cfg80211_rdev_list_generation << 2)))
2393 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002394
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002395 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002396 int ret;
2397 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002398
Johannes Berg683b6d32012-11-08 21:25:48 +01002399 ret = rdev_get_channel(rdev, wdev, &chandef);
2400 if (ret == 0) {
2401 if (nl80211_send_chandef(msg, &chandef))
2402 goto nla_put_failure;
2403 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002404 }
2405
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002406 if (wdev->ssid_len) {
2407 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2408 goto nla_put_failure;
2409 }
2410
Johannes Berg053c0952015-01-16 22:09:00 +01002411 genlmsg_end(msg, hdr);
2412 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002413
2414 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002415 genlmsg_cancel(msg, hdr);
2416 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002417}
2418
2419static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2420{
2421 int wp_idx = 0;
2422 int if_idx = 0;
2423 int wp_start = cb->args[0];
2424 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002425 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002426 struct wireless_dev *wdev;
2427
Johannes Berg5fe231e2013-05-08 21:45:15 +02002428 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002429 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2430 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002431 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002432 if (wp_idx < wp_start) {
2433 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002434 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002435 }
Johannes Berg55682962007-09-20 13:09:35 -04002436 if_idx = 0;
2437
Johannes Berg89a54e42012-06-15 14:33:17 +02002438 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002439 if (if_idx < if_start) {
2440 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002441 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002442 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002443 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002444 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002445 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002446 goto out;
2447 }
2448 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002449 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002450
2451 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002452 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002453 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002454 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002455
2456 cb->args[0] = wp_idx;
2457 cb->args[1] = if_idx;
2458
2459 return skb->len;
2460}
2461
2462static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2463{
2464 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002466 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002467
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002469 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002470 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002471
Eric W. Biederman15e47302012-09-07 20:12:54 +00002472 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002473 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002474 nlmsg_free(msg);
2475 return -ENOBUFS;
2476 }
Johannes Berg55682962007-09-20 13:09:35 -04002477
Johannes Berg134e6372009-07-10 09:51:34 +00002478 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002479}
2480
Michael Wu66f7ac52008-01-31 19:48:22 +01002481static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2482 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2483 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2484 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2485 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2486 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002487 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002488};
2489
2490static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2491{
2492 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2493 int flag;
2494
2495 *mntrflags = 0;
2496
2497 if (!nla)
2498 return -EINVAL;
2499
2500 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2501 nla, mntr_flags_policy))
2502 return -EINVAL;
2503
2504 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2505 if (flags[flag])
2506 *mntrflags |= (1<<flag);
2507
2508 return 0;
2509}
2510
Johannes Berg9bc383d2009-11-19 11:55:19 +01002511static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002512 struct net_device *netdev, u8 use_4addr,
2513 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002514{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002515 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002516 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002517 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002518 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002519 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002520
2521 switch (iftype) {
2522 case NL80211_IFTYPE_AP_VLAN:
2523 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2524 return 0;
2525 break;
2526 case NL80211_IFTYPE_STATION:
2527 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2528 return 0;
2529 break;
2530 default:
2531 break;
2532 }
2533
2534 return -EOPNOTSUPP;
2535}
2536
Johannes Berg55682962007-09-20 13:09:35 -04002537static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2538{
Johannes Berg4c476992010-10-04 21:36:35 +02002539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002540 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002541 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002542 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002543 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002544 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002545 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002546
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002547 memset(&params, 0, sizeof(params));
2548
Johannes Berg04a773a2009-04-19 21:24:32 +02002549 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002550
Johannes Berg723b0382008-09-16 20:22:09 +02002551 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002552 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002553 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002554 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002555 if (ntype > NL80211_IFTYPE_MAX)
2556 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002557 }
2558
Johannes Berg92ffe052008-09-16 20:39:36 +02002559 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002560 struct wireless_dev *wdev = dev->ieee80211_ptr;
2561
Johannes Berg4c476992010-10-04 21:36:35 +02002562 if (ntype != NL80211_IFTYPE_MESH_POINT)
2563 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002564 if (netif_running(dev))
2565 return -EBUSY;
2566
2567 wdev_lock(wdev);
2568 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2569 IEEE80211_MAX_MESH_ID_LEN);
2570 wdev->mesh_id_up_len =
2571 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2572 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2573 wdev->mesh_id_up_len);
2574 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002575 }
2576
Felix Fietkau8b787642009-11-10 18:53:10 +01002577 if (info->attrs[NL80211_ATTR_4ADDR]) {
2578 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2579 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002580 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002581 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002582 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002583 } else {
2584 params.use_4addr = -1;
2585 }
2586
Johannes Berg92ffe052008-09-16 20:39:36 +02002587 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002588 if (ntype != NL80211_IFTYPE_MONITOR)
2589 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002590 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2591 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002592 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002593 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002594
2595 flags = &_flags;
2596 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002597 }
Johannes Berg3b858752009-03-12 09:55:09 +01002598
Luciano Coelho18003292013-08-29 13:26:57 +03002599 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002600 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2601 return -EOPNOTSUPP;
2602
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002603 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002604 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002605 else
2606 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002607
Johannes Berg9bc383d2009-11-19 11:55:19 +01002608 if (!err && params.use_4addr != -1)
2609 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2610
Johannes Berg55682962007-09-20 13:09:35 -04002611 return err;
2612}
2613
2614static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2615{
Johannes Berg4c476992010-10-04 21:36:35 +02002616 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002617 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002618 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002619 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002620 int err;
2621 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002622 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002623
Johannes Berg78f22b62014-03-24 17:57:27 +01002624 /* to avoid failing a new interface creation due to pending removal */
2625 cfg80211_destroy_ifaces(rdev);
2626
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002627 memset(&params, 0, sizeof(params));
2628
Johannes Berg55682962007-09-20 13:09:35 -04002629 if (!info->attrs[NL80211_ATTR_IFNAME])
2630 return -EINVAL;
2631
2632 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2633 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2634 if (type > NL80211_IFTYPE_MAX)
2635 return -EINVAL;
2636 }
2637
Johannes Berg79c97e92009-07-07 03:56:12 +02002638 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002639 !(rdev->wiphy.interface_modes & (1 << type)))
2640 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002641
Ben Greeare8f479b2014-10-22 12:23:05 -07002642 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2643 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2644 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002645 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2646 ETH_ALEN);
2647 if (!is_valid_ether_addr(params.macaddr))
2648 return -EADDRNOTAVAIL;
2649 }
2650
Johannes Berg9bc383d2009-11-19 11:55:19 +01002651 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002652 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002653 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002654 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002655 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002656 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002657
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002658 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2659 if (!msg)
2660 return -ENOMEM;
2661
Michael Wu66f7ac52008-01-31 19:48:22 +01002662 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2663 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2664 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002665
Luciano Coelho18003292013-08-29 13:26:57 +03002666 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002667 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2668 return -EOPNOTSUPP;
2669
Hila Gonene35e4d22012-06-27 17:19:42 +03002670 wdev = rdev_add_virtual_intf(rdev,
2671 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
2672 type, err ? NULL : &flags, &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002673 if (WARN_ON(!wdev)) {
2674 nlmsg_free(msg);
2675 return -EPROTO;
2676 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002677 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002678 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002679 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002680
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002681 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002682 wdev->owner_nlportid = info->snd_portid;
2683
Johannes Berg98104fde2012-06-16 00:19:54 +02002684 switch (type) {
2685 case NL80211_IFTYPE_MESH_POINT:
2686 if (!info->attrs[NL80211_ATTR_MESH_ID])
2687 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002688 wdev_lock(wdev);
2689 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2690 IEEE80211_MAX_MESH_ID_LEN);
2691 wdev->mesh_id_up_len =
2692 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2693 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2694 wdev->mesh_id_up_len);
2695 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002696 break;
2697 case NL80211_IFTYPE_P2P_DEVICE:
2698 /*
2699 * P2P Device doesn't have a netdev, so doesn't go
2700 * through the netdev notifier and must be added here
2701 */
2702 mutex_init(&wdev->mtx);
2703 INIT_LIST_HEAD(&wdev->event_list);
2704 spin_lock_init(&wdev->event_lock);
2705 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2706 spin_lock_init(&wdev->mgmt_registrations_lock);
2707
Johannes Berg98104fde2012-06-16 00:19:54 +02002708 wdev->identifier = ++rdev->wdev_id;
2709 list_add_rcu(&wdev->list, &rdev->wdev_list);
2710 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002711 break;
2712 default:
2713 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002714 }
2715
Eric W. Biederman15e47302012-09-07 20:12:54 +00002716 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002717 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002718 nlmsg_free(msg);
2719 return -ENOBUFS;
2720 }
2721
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002722 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2723 if (event) {
2724 if (nl80211_send_iface(event, 0, 0, 0,
2725 rdev, wdev, false) < 0) {
2726 nlmsg_free(event);
2727 goto out;
2728 }
2729
2730 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2731 event, 0, NL80211_MCGRP_CONFIG,
2732 GFP_KERNEL);
2733 }
2734
2735out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002736 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002737}
2738
2739static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2740{
Johannes Berg4c476992010-10-04 21:36:35 +02002741 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002742 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002743 struct sk_buff *msg;
2744 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002745
Johannes Berg4c476992010-10-04 21:36:35 +02002746 if (!rdev->ops->del_virtual_intf)
2747 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002748
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002749 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2750 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2751 nlmsg_free(msg);
2752 msg = NULL;
2753 }
2754
Johannes Berg84efbb82012-06-16 00:00:26 +02002755 /*
2756 * If we remove a wireless device without a netdev then clear
2757 * user_ptr[1] so that nl80211_post_doit won't dereference it
2758 * to check if it needs to do dev_put(). Otherwise it crashes
2759 * since the wdev has been freed, unlike with a netdev where
2760 * we need the dev_put() for the netdev to really be freed.
2761 */
2762 if (!wdev->netdev)
2763 info->user_ptr[1] = NULL;
2764
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002765 status = rdev_del_virtual_intf(rdev, wdev);
2766 if (status >= 0 && msg)
2767 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2768 msg, 0, NL80211_MCGRP_CONFIG,
2769 GFP_KERNEL);
2770 else
2771 nlmsg_free(msg);
2772
2773 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002774}
2775
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002776static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2777{
2778 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2779 struct net_device *dev = info->user_ptr[1];
2780 u16 noack_map;
2781
2782 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2783 return -EINVAL;
2784
2785 if (!rdev->ops->set_noack_map)
2786 return -EOPNOTSUPP;
2787
2788 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2789
Hila Gonene35e4d22012-06-27 17:19:42 +03002790 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002791}
2792
Johannes Berg41ade002007-12-19 02:03:29 +01002793struct get_key_cookie {
2794 struct sk_buff *msg;
2795 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002796 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002797};
2798
2799static void get_key_callback(void *c, struct key_params *params)
2800{
Johannes Bergb9454e82009-07-08 13:29:08 +02002801 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002802 struct get_key_cookie *cookie = c;
2803
David S. Miller9360ffd2012-03-29 04:41:26 -04002804 if ((params->key &&
2805 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2806 params->key_len, params->key)) ||
2807 (params->seq &&
2808 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2809 params->seq_len, params->seq)) ||
2810 (params->cipher &&
2811 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2812 params->cipher)))
2813 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002814
Johannes Bergb9454e82009-07-08 13:29:08 +02002815 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2816 if (!key)
2817 goto nla_put_failure;
2818
David S. Miller9360ffd2012-03-29 04:41:26 -04002819 if ((params->key &&
2820 nla_put(cookie->msg, NL80211_KEY_DATA,
2821 params->key_len, params->key)) ||
2822 (params->seq &&
2823 nla_put(cookie->msg, NL80211_KEY_SEQ,
2824 params->seq_len, params->seq)) ||
2825 (params->cipher &&
2826 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2827 params->cipher)))
2828 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002829
David S. Miller9360ffd2012-03-29 04:41:26 -04002830 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2831 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002832
2833 nla_nest_end(cookie->msg, key);
2834
Johannes Berg41ade002007-12-19 02:03:29 +01002835 return;
2836 nla_put_failure:
2837 cookie->error = 1;
2838}
2839
2840static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2841{
Johannes Berg4c476992010-10-04 21:36:35 +02002842 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002843 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002844 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002845 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002846 const u8 *mac_addr = NULL;
2847 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002848 struct get_key_cookie cookie = {
2849 .error = 0,
2850 };
2851 void *hdr;
2852 struct sk_buff *msg;
2853
2854 if (info->attrs[NL80211_ATTR_KEY_IDX])
2855 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2856
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002857 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002858 return -EINVAL;
2859
2860 if (info->attrs[NL80211_ATTR_MAC])
2861 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2862
Johannes Berge31b8212010-10-05 19:39:30 +02002863 pairwise = !!mac_addr;
2864 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2865 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2866 if (kt >= NUM_NL80211_KEYTYPES)
2867 return -EINVAL;
2868 if (kt != NL80211_KEYTYPE_GROUP &&
2869 kt != NL80211_KEYTYPE_PAIRWISE)
2870 return -EINVAL;
2871 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2872 }
2873
Johannes Berg4c476992010-10-04 21:36:35 +02002874 if (!rdev->ops->get_key)
2875 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002876
Johannes Berg0fa7b392015-01-23 11:10:12 +01002877 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2878 return -ENOENT;
2879
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002880 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002881 if (!msg)
2882 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002883
Eric W. Biederman15e47302012-09-07 20:12:54 +00002884 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002885 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002886 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002887 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002888
2889 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002890 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002891
David S. Miller9360ffd2012-03-29 04:41:26 -04002892 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2893 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2894 goto nla_put_failure;
2895 if (mac_addr &&
2896 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2897 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002898
Hila Gonene35e4d22012-06-27 17:19:42 +03002899 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2900 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002901
2902 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002903 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002904
2905 if (cookie.error)
2906 goto nla_put_failure;
2907
2908 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002909 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002910
2911 nla_put_failure:
2912 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002913 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002914 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002915 return err;
2916}
2917
2918static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2919{
Johannes Berg4c476992010-10-04 21:36:35 +02002920 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002921 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002922 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002923 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002924
Johannes Bergb9454e82009-07-08 13:29:08 +02002925 err = nl80211_parse_key(info, &key);
2926 if (err)
2927 return err;
2928
2929 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002930 return -EINVAL;
2931
Johannes Bergb9454e82009-07-08 13:29:08 +02002932 /* only support setting default key */
2933 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002934 return -EINVAL;
2935
Johannes Bergfffd0932009-07-08 14:22:54 +02002936 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002937
2938 if (key.def) {
2939 if (!rdev->ops->set_default_key) {
2940 err = -EOPNOTSUPP;
2941 goto out;
2942 }
2943
2944 err = nl80211_key_allowed(dev->ieee80211_ptr);
2945 if (err)
2946 goto out;
2947
Hila Gonene35e4d22012-06-27 17:19:42 +03002948 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002949 key.def_uni, key.def_multi);
2950
2951 if (err)
2952 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002953
Johannes Berg3d23e342009-09-29 23:27:28 +02002954#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002955 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002956#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002957 } else {
2958 if (key.def_uni || !key.def_multi) {
2959 err = -EINVAL;
2960 goto out;
2961 }
2962
2963 if (!rdev->ops->set_default_mgmt_key) {
2964 err = -EOPNOTSUPP;
2965 goto out;
2966 }
2967
2968 err = nl80211_key_allowed(dev->ieee80211_ptr);
2969 if (err)
2970 goto out;
2971
Hila Gonene35e4d22012-06-27 17:19:42 +03002972 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002973 if (err)
2974 goto out;
2975
2976#ifdef CONFIG_CFG80211_WEXT
2977 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2978#endif
2979 }
2980
2981 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002982 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002983
Johannes Berg41ade002007-12-19 02:03:29 +01002984 return err;
2985}
2986
2987static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2988{
Johannes Berg4c476992010-10-04 21:36:35 +02002989 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002990 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002991 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002992 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002993 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002994
Johannes Bergb9454e82009-07-08 13:29:08 +02002995 err = nl80211_parse_key(info, &key);
2996 if (err)
2997 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002998
Johannes Bergb9454e82009-07-08 13:29:08 +02002999 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003000 return -EINVAL;
3001
Johannes Berg41ade002007-12-19 02:03:29 +01003002 if (info->attrs[NL80211_ATTR_MAC])
3003 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3004
Johannes Berge31b8212010-10-05 19:39:30 +02003005 if (key.type == -1) {
3006 if (mac_addr)
3007 key.type = NL80211_KEYTYPE_PAIRWISE;
3008 else
3009 key.type = NL80211_KEYTYPE_GROUP;
3010 }
3011
3012 /* for now */
3013 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3014 key.type != NL80211_KEYTYPE_GROUP)
3015 return -EINVAL;
3016
Johannes Berg4c476992010-10-04 21:36:35 +02003017 if (!rdev->ops->add_key)
3018 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003019
Johannes Berge31b8212010-10-05 19:39:30 +02003020 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3021 key.type == NL80211_KEYTYPE_PAIRWISE,
3022 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003023 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003024
3025 wdev_lock(dev->ieee80211_ptr);
3026 err = nl80211_key_allowed(dev->ieee80211_ptr);
3027 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003028 err = rdev_add_key(rdev, dev, key.idx,
3029 key.type == NL80211_KEYTYPE_PAIRWISE,
3030 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003031 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003032
Johannes Berg41ade002007-12-19 02:03:29 +01003033 return err;
3034}
3035
3036static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3037{
Johannes Berg4c476992010-10-04 21:36:35 +02003038 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003039 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003040 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003041 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003042 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003043
Johannes Bergb9454e82009-07-08 13:29:08 +02003044 err = nl80211_parse_key(info, &key);
3045 if (err)
3046 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003047
3048 if (info->attrs[NL80211_ATTR_MAC])
3049 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3050
Johannes Berge31b8212010-10-05 19:39:30 +02003051 if (key.type == -1) {
3052 if (mac_addr)
3053 key.type = NL80211_KEYTYPE_PAIRWISE;
3054 else
3055 key.type = NL80211_KEYTYPE_GROUP;
3056 }
3057
3058 /* for now */
3059 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3060 key.type != NL80211_KEYTYPE_GROUP)
3061 return -EINVAL;
3062
Johannes Berg4c476992010-10-04 21:36:35 +02003063 if (!rdev->ops->del_key)
3064 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003065
Johannes Bergfffd0932009-07-08 14:22:54 +02003066 wdev_lock(dev->ieee80211_ptr);
3067 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003068
Johannes Berg0fa7b392015-01-23 11:10:12 +01003069 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003070 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3071 err = -ENOENT;
3072
Johannes Bergfffd0932009-07-08 14:22:54 +02003073 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003074 err = rdev_del_key(rdev, dev, key.idx,
3075 key.type == NL80211_KEYTYPE_PAIRWISE,
3076 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003077
Johannes Berg3d23e342009-09-29 23:27:28 +02003078#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003079 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003080 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003081 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003082 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003083 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3084 }
3085#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003086 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003087
Johannes Berg41ade002007-12-19 02:03:29 +01003088 return err;
3089}
3090
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303091/* This function returns an error or the number of nested attributes */
3092static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3093{
3094 struct nlattr *attr;
3095 int n_entries = 0, tmp;
3096
3097 nla_for_each_nested(attr, nl_attr, tmp) {
3098 if (nla_len(attr) != ETH_ALEN)
3099 return -EINVAL;
3100
3101 n_entries++;
3102 }
3103
3104 return n_entries;
3105}
3106
3107/*
3108 * This function parses ACL information and allocates memory for ACL data.
3109 * On successful return, the calling function is responsible to free the
3110 * ACL buffer returned by this function.
3111 */
3112static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3113 struct genl_info *info)
3114{
3115 enum nl80211_acl_policy acl_policy;
3116 struct nlattr *attr;
3117 struct cfg80211_acl_data *acl;
3118 int i = 0, n_entries, tmp;
3119
3120 if (!wiphy->max_acl_mac_addrs)
3121 return ERR_PTR(-EOPNOTSUPP);
3122
3123 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3124 return ERR_PTR(-EINVAL);
3125
3126 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3127 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3128 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3129 return ERR_PTR(-EINVAL);
3130
3131 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3132 return ERR_PTR(-EINVAL);
3133
3134 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3135 if (n_entries < 0)
3136 return ERR_PTR(n_entries);
3137
3138 if (n_entries > wiphy->max_acl_mac_addrs)
3139 return ERR_PTR(-ENOTSUPP);
3140
3141 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3142 GFP_KERNEL);
3143 if (!acl)
3144 return ERR_PTR(-ENOMEM);
3145
3146 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3147 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3148 i++;
3149 }
3150
3151 acl->n_acl_entries = n_entries;
3152 acl->acl_policy = acl_policy;
3153
3154 return acl;
3155}
3156
3157static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3158{
3159 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3160 struct net_device *dev = info->user_ptr[1];
3161 struct cfg80211_acl_data *acl;
3162 int err;
3163
3164 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3165 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3166 return -EOPNOTSUPP;
3167
3168 if (!dev->ieee80211_ptr->beacon_interval)
3169 return -EINVAL;
3170
3171 acl = parse_acl_data(&rdev->wiphy, info);
3172 if (IS_ERR(acl))
3173 return PTR_ERR(acl);
3174
3175 err = rdev_set_mac_acl(rdev, dev, acl);
3176
3177 kfree(acl);
3178
3179 return err;
3180}
3181
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003182static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003183 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003184{
Johannes Berg88600202012-02-13 15:17:18 +01003185 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003186
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003187 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3188 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3189 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3190 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003191 return -EINVAL;
3192
Johannes Berg88600202012-02-13 15:17:18 +01003193 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003194
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003195 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3196 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3197 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003198 if (!bcn->head_len)
3199 return -EINVAL;
3200 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003201 }
3202
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003203 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3204 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3205 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003206 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003207 }
3208
Johannes Berg4c476992010-10-04 21:36:35 +02003209 if (!haveinfo)
3210 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003211
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003212 if (attrs[NL80211_ATTR_IE]) {
3213 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3214 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003215 }
3216
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003217 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003218 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003219 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003220 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003221 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003222 }
3223
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003224 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003225 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003226 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003227 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003228 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003229 }
3230
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003231 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3232 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3233 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003234 }
3235
Johannes Berg88600202012-02-13 15:17:18 +01003236 return 0;
3237}
3238
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003239static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3240 struct cfg80211_ap_settings *params)
3241{
3242 struct wireless_dev *wdev;
3243 bool ret = false;
3244
Johannes Berg89a54e42012-06-15 14:33:17 +02003245 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003246 if (wdev->iftype != NL80211_IFTYPE_AP &&
3247 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3248 continue;
3249
Johannes Berg683b6d32012-11-08 21:25:48 +01003250 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003251 continue;
3252
Johannes Berg683b6d32012-11-08 21:25:48 +01003253 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003254 ret = true;
3255 break;
3256 }
3257
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003258 return ret;
3259}
3260
Jouni Malinene39e5b52012-09-30 19:29:39 +03003261static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3262 enum nl80211_auth_type auth_type,
3263 enum nl80211_commands cmd)
3264{
3265 if (auth_type > NL80211_AUTHTYPE_MAX)
3266 return false;
3267
3268 switch (cmd) {
3269 case NL80211_CMD_AUTHENTICATE:
3270 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3271 auth_type == NL80211_AUTHTYPE_SAE)
3272 return false;
3273 return true;
3274 case NL80211_CMD_CONNECT:
3275 case NL80211_CMD_START_AP:
3276 /* SAE not supported yet */
3277 if (auth_type == NL80211_AUTHTYPE_SAE)
3278 return false;
3279 return true;
3280 default:
3281 return false;
3282 }
3283}
3284
Johannes Berg88600202012-02-13 15:17:18 +01003285static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3286{
3287 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3288 struct net_device *dev = info->user_ptr[1];
3289 struct wireless_dev *wdev = dev->ieee80211_ptr;
3290 struct cfg80211_ap_settings params;
3291 int err;
3292
3293 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3294 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3295 return -EOPNOTSUPP;
3296
3297 if (!rdev->ops->start_ap)
3298 return -EOPNOTSUPP;
3299
3300 if (wdev->beacon_interval)
3301 return -EALREADY;
3302
3303 memset(&params, 0, sizeof(params));
3304
3305 /* these are required for START_AP */
3306 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3307 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3308 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3309 return -EINVAL;
3310
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003311 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003312 if (err)
3313 return err;
3314
3315 params.beacon_interval =
3316 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3317 params.dtim_period =
3318 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3319
3320 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3321 if (err)
3322 return err;
3323
3324 /*
3325 * In theory, some of these attributes should be required here
3326 * but since they were not used when the command was originally
3327 * added, keep them optional for old user space programs to let
3328 * them continue to work with drivers that do not need the
3329 * additional information -- drivers must check!
3330 */
3331 if (info->attrs[NL80211_ATTR_SSID]) {
3332 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3333 params.ssid_len =
3334 nla_len(info->attrs[NL80211_ATTR_SSID]);
3335 if (params.ssid_len == 0 ||
3336 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3337 return -EINVAL;
3338 }
3339
3340 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3341 params.hidden_ssid = nla_get_u32(
3342 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3343 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3344 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3345 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3346 return -EINVAL;
3347 }
3348
3349 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3350
3351 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3352 params.auth_type = nla_get_u32(
3353 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003354 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3355 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003356 return -EINVAL;
3357 } else
3358 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3359
3360 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3361 NL80211_MAX_NR_CIPHER_SUITES);
3362 if (err)
3363 return err;
3364
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303365 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3366 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3367 return -EOPNOTSUPP;
3368 params.inactivity_timeout = nla_get_u16(
3369 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3370 }
3371
Johannes Berg53cabad2012-11-14 15:17:28 +01003372 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3373 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3374 return -EINVAL;
3375 params.p2p_ctwindow =
3376 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3377 if (params.p2p_ctwindow > 127)
3378 return -EINVAL;
3379 if (params.p2p_ctwindow != 0 &&
3380 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3381 return -EINVAL;
3382 }
3383
3384 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3385 u8 tmp;
3386
3387 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3388 return -EINVAL;
3389 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3390 if (tmp > 1)
3391 return -EINVAL;
3392 params.p2p_opp_ps = tmp;
3393 if (params.p2p_opp_ps != 0 &&
3394 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3395 return -EINVAL;
3396 }
3397
Johannes Bergaa430da2012-05-16 23:50:18 +02003398 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003399 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3400 if (err)
3401 return err;
3402 } else if (wdev->preset_chandef.chan) {
3403 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003404 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003405 return -EINVAL;
3406
Ilan Peer174e0cd2014-02-23 09:13:01 +02003407 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
3408 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003409 return -EINVAL;
3410
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303411 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3412 params.acl = parse_acl_data(&rdev->wiphy, info);
3413 if (IS_ERR(params.acl))
3414 return PTR_ERR(params.acl);
3415 }
3416
Eliad Peller18998c32014-09-10 14:07:34 +03003417 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3418 params.smps_mode =
3419 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3420 switch (params.smps_mode) {
3421 case NL80211_SMPS_OFF:
3422 break;
3423 case NL80211_SMPS_STATIC:
3424 if (!(rdev->wiphy.features &
3425 NL80211_FEATURE_STATIC_SMPS))
3426 return -EINVAL;
3427 break;
3428 case NL80211_SMPS_DYNAMIC:
3429 if (!(rdev->wiphy.features &
3430 NL80211_FEATURE_DYNAMIC_SMPS))
3431 return -EINVAL;
3432 break;
3433 default:
3434 return -EINVAL;
3435 }
3436 } else {
3437 params.smps_mode = NL80211_SMPS_OFF;
3438 }
3439
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003440 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003441 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003442 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003443 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003444 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003445 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003446 wdev->ssid_len = params.ssid_len;
3447 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003448 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003449 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303450
3451 kfree(params.acl);
3452
Johannes Berg56d18932011-05-09 18:41:15 +02003453 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003454}
3455
Johannes Berg88600202012-02-13 15:17:18 +01003456static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3457{
3458 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3459 struct net_device *dev = info->user_ptr[1];
3460 struct wireless_dev *wdev = dev->ieee80211_ptr;
3461 struct cfg80211_beacon_data params;
3462 int err;
3463
3464 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3465 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3466 return -EOPNOTSUPP;
3467
3468 if (!rdev->ops->change_beacon)
3469 return -EOPNOTSUPP;
3470
3471 if (!wdev->beacon_interval)
3472 return -EINVAL;
3473
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003474 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003475 if (err)
3476 return err;
3477
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003478 wdev_lock(wdev);
3479 err = rdev_change_beacon(rdev, dev, &params);
3480 wdev_unlock(wdev);
3481
3482 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003483}
3484
3485static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003486{
Johannes Berg4c476992010-10-04 21:36:35 +02003487 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3488 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003489
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003490 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003491}
3492
Johannes Berg5727ef12007-12-19 02:03:34 +01003493static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3494 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3495 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3496 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003497 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003498 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003499 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003500};
3501
Johannes Bergeccb8e82009-05-11 21:57:56 +03003502static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003503 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003504 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003505{
3506 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003507 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003508 int flag;
3509
Johannes Bergeccb8e82009-05-11 21:57:56 +03003510 /*
3511 * Try parsing the new attribute first so userspace
3512 * can specify both for older kernels.
3513 */
3514 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3515 if (nla) {
3516 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003517
Johannes Bergeccb8e82009-05-11 21:57:56 +03003518 sta_flags = nla_data(nla);
3519 params->sta_flags_mask = sta_flags->mask;
3520 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003521 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003522 if ((params->sta_flags_mask |
3523 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3524 return -EINVAL;
3525 return 0;
3526 }
3527
3528 /* if present, parse the old attribute */
3529
3530 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003531 if (!nla)
3532 return 0;
3533
3534 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3535 nla, sta_flags_policy))
3536 return -EINVAL;
3537
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003538 /*
3539 * Only allow certain flags for interface types so that
3540 * other attributes are silently ignored. Remember that
3541 * this is backward compatibility code with old userspace
3542 * and shouldn't be hit in other cases anyway.
3543 */
3544 switch (iftype) {
3545 case NL80211_IFTYPE_AP:
3546 case NL80211_IFTYPE_AP_VLAN:
3547 case NL80211_IFTYPE_P2P_GO:
3548 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3549 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3550 BIT(NL80211_STA_FLAG_WME) |
3551 BIT(NL80211_STA_FLAG_MFP);
3552 break;
3553 case NL80211_IFTYPE_P2P_CLIENT:
3554 case NL80211_IFTYPE_STATION:
3555 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3556 BIT(NL80211_STA_FLAG_TDLS_PEER);
3557 break;
3558 case NL80211_IFTYPE_MESH_POINT:
3559 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3560 BIT(NL80211_STA_FLAG_MFP) |
3561 BIT(NL80211_STA_FLAG_AUTHORIZED);
3562 default:
3563 return -EINVAL;
3564 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003565
Johannes Berg3383b5a2012-05-10 20:14:43 +02003566 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3567 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003568 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003569
Johannes Berg3383b5a2012-05-10 20:14:43 +02003570 /* no longer support new API additions in old API */
3571 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3572 return -EINVAL;
3573 }
3574 }
3575
Johannes Berg5727ef12007-12-19 02:03:34 +01003576 return 0;
3577}
3578
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003579static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3580 int attr)
3581{
3582 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003583 u32 bitrate;
3584 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003585 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003586
3587 rate = nla_nest_start(msg, attr);
3588 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003589 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003590
3591 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3592 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003593 /* report 16-bit bitrate only if we can */
3594 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003595 if (bitrate > 0 &&
3596 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3597 return false;
3598 if (bitrate_compat > 0 &&
3599 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3600 return false;
3601
Johannes Bergb51f3be2015-01-15 16:14:02 +01003602 switch (info->bw) {
3603 case RATE_INFO_BW_5:
3604 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3605 break;
3606 case RATE_INFO_BW_10:
3607 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3608 break;
3609 default:
3610 WARN_ON(1);
3611 /* fall through */
3612 case RATE_INFO_BW_20:
3613 rate_flg = 0;
3614 break;
3615 case RATE_INFO_BW_40:
3616 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3617 break;
3618 case RATE_INFO_BW_80:
3619 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3620 break;
3621 case RATE_INFO_BW_160:
3622 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3623 break;
3624 }
3625
3626 if (rate_flg && nla_put_flag(msg, rate_flg))
3627 return false;
3628
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003629 if (info->flags & RATE_INFO_FLAGS_MCS) {
3630 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3631 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003632 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3633 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3634 return false;
3635 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3636 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3637 return false;
3638 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3639 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003640 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3641 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3642 return false;
3643 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003644
3645 nla_nest_end(msg, rate);
3646 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003647}
3648
Felix Fietkau119363c2013-04-22 16:29:30 +02003649static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3650 int id)
3651{
3652 void *attr;
3653 int i = 0;
3654
3655 if (!mask)
3656 return true;
3657
3658 attr = nla_nest_start(msg, id);
3659 if (!attr)
3660 return false;
3661
3662 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3663 if (!(mask & BIT(i)))
3664 continue;
3665
3666 if (nla_put_u8(msg, i, signal[i]))
3667 return false;
3668 }
3669
3670 nla_nest_end(msg, attr);
3671
3672 return true;
3673}
3674
Johannes Bergcf5ead82014-11-14 17:14:00 +01003675static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3676 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003677 struct cfg80211_registered_device *rdev,
3678 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003679 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003680{
3681 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003682 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003683
Johannes Bergcf5ead82014-11-14 17:14:00 +01003684 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003685 if (!hdr)
3686 return -1;
3687
David S. Miller9360ffd2012-03-29 04:41:26 -04003688 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3689 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3690 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3691 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003692
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003693 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3694 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003695 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003696
3697#define PUT_SINFO(attr, memb, type) do { \
3698 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3699 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3700 sinfo->memb)) \
3701 goto nla_put_failure; \
3702 } while (0)
3703
3704 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3705 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3706
3707 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3708 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003709 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003710 (u32)sinfo->rx_bytes))
3711 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003712
3713 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3714 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003715 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3716 (u32)sinfo->tx_bytes))
3717 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003718
3719 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3720 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3721 PUT_SINFO(LLID, llid, u16);
3722 PUT_SINFO(PLID, plid, u16);
3723 PUT_SINFO(PLINK_STATE, plink_state, u8);
3724
John W. Linville66266b32012-03-15 13:25:41 -04003725 switch (rdev->wiphy.signal_type) {
3726 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003727 PUT_SINFO(SIGNAL, signal, u8);
3728 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003729 break;
3730 default:
3731 break;
3732 }
Johannes Berg319090b2014-11-17 14:08:11 +01003733 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003734 if (!nl80211_put_signal(msg, sinfo->chains,
3735 sinfo->chain_signal,
3736 NL80211_STA_INFO_CHAIN_SIGNAL))
3737 goto nla_put_failure;
3738 }
Johannes Berg319090b2014-11-17 14:08:11 +01003739 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003740 if (!nl80211_put_signal(msg, sinfo->chains,
3741 sinfo->chain_signal_avg,
3742 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3743 goto nla_put_failure;
3744 }
Johannes Berg319090b2014-11-17 14:08:11 +01003745 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003746 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3747 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003748 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003749 }
Johannes Berg319090b2014-11-17 14:08:11 +01003750 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003751 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3752 NL80211_STA_INFO_RX_BITRATE))
3753 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003754 }
Johannes Berg319090b2014-11-17 14:08:11 +01003755
3756 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3757 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3758 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3759 PUT_SINFO(TX_FAILED, tx_failed, u32);
3760 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3761 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3762 PUT_SINFO(LOCAL_PM, local_pm, u32);
3763 PUT_SINFO(PEER_PM, peer_pm, u32);
3764 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3765
3766 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003767 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3768 if (!bss_param)
3769 goto nla_put_failure;
3770
David S. Miller9360ffd2012-03-29 04:41:26 -04003771 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3772 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3773 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3774 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3775 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3776 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3777 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3778 sinfo->bss_param.dtim_period) ||
3779 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3780 sinfo->bss_param.beacon_interval))
3781 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003782
3783 nla_nest_end(msg, bss_param);
3784 }
Johannes Berg319090b2014-11-17 14:08:11 +01003785 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003786 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3787 sizeof(struct nl80211_sta_flag_update),
3788 &sinfo->sta_flags))
3789 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003790
3791 PUT_SINFO(T_OFFSET, t_offset, u64);
3792 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003793 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3794 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003795
3796#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003797
3798 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3799 struct nlattr *tidsattr;
3800 int tid;
3801
3802 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3803 if (!tidsattr)
3804 goto nla_put_failure;
3805
3806 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3807 struct cfg80211_tid_stats *tidstats;
3808 struct nlattr *tidattr;
3809
3810 tidstats = &sinfo->pertid[tid];
3811
3812 if (!tidstats->filled)
3813 continue;
3814
3815 tidattr = nla_nest_start(msg, tid + 1);
3816 if (!tidattr)
3817 goto nla_put_failure;
3818
3819#define PUT_TIDVAL(attr, memb, type) do { \
3820 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3821 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3822 tidstats->memb)) \
3823 goto nla_put_failure; \
3824 } while (0)
3825
3826 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3827 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3828 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3829 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3830
3831#undef PUT_TIDVAL
3832 nla_nest_end(msg, tidattr);
3833 }
3834
3835 nla_nest_end(msg, tidsattr);
3836 }
3837
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003838 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003839
Johannes Berg319090b2014-11-17 14:08:11 +01003840 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003841 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3842 sinfo->assoc_req_ies))
3843 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003844
Johannes Berg053c0952015-01-16 22:09:00 +01003845 genlmsg_end(msg, hdr);
3846 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003847
3848 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003849 genlmsg_cancel(msg, hdr);
3850 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003851}
3852
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003853static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003854 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003855{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003856 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003857 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003858 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003859 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003860 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003861 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003862
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003863 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003864 if (err)
3865 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003866
Johannes Berg97990a02013-04-19 01:02:55 +02003867 if (!wdev->netdev) {
3868 err = -EINVAL;
3869 goto out_err;
3870 }
3871
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003872 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003873 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003874 goto out_err;
3875 }
3876
Johannes Bergbba95fe2008-07-29 13:22:51 +02003877 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003878 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003879 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003880 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003881 if (err == -ENOENT)
3882 break;
3883 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003884 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003885
Johannes Bergcf5ead82014-11-14 17:14:00 +01003886 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003887 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003888 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003889 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003890 &sinfo) < 0)
3891 goto out;
3892
3893 sta_idx++;
3894 }
3895
3896
3897 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003898 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003899 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003900 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003901 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003902
3903 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003904}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003905
Johannes Berg5727ef12007-12-19 02:03:34 +01003906static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3907{
Johannes Berg4c476992010-10-04 21:36:35 +02003908 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3909 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003910 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003911 struct sk_buff *msg;
3912 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003913 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003914
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003915 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003916
3917 if (!info->attrs[NL80211_ATTR_MAC])
3918 return -EINVAL;
3919
3920 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3921
Johannes Berg4c476992010-10-04 21:36:35 +02003922 if (!rdev->ops->get_station)
3923 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003924
Hila Gonene35e4d22012-06-27 17:19:42 +03003925 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003926 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003927 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003928
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003929 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003930 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003931 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003932
Johannes Bergcf5ead82014-11-14 17:14:00 +01003933 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3934 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003935 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003936 nlmsg_free(msg);
3937 return -ENOBUFS;
3938 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003939
Johannes Berg4c476992010-10-04 21:36:35 +02003940 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003941}
3942
Johannes Berg77ee7c82013-02-15 00:48:33 +01003943int cfg80211_check_station_change(struct wiphy *wiphy,
3944 struct station_parameters *params,
3945 enum cfg80211_station_type statype)
3946{
3947 if (params->listen_interval != -1)
3948 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003949 if (params->aid &&
3950 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003951 return -EINVAL;
3952
3953 /* When you run into this, adjust the code below for the new flag */
3954 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3955
3956 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003957 case CFG80211_STA_MESH_PEER_KERNEL:
3958 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003959 /*
3960 * No ignoring the TDLS flag here -- the userspace mesh
3961 * code doesn't have the bug of including TDLS in the
3962 * mask everywhere.
3963 */
3964 if (params->sta_flags_mask &
3965 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3966 BIT(NL80211_STA_FLAG_MFP) |
3967 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3968 return -EINVAL;
3969 break;
3970 case CFG80211_STA_TDLS_PEER_SETUP:
3971 case CFG80211_STA_TDLS_PEER_ACTIVE:
3972 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3973 return -EINVAL;
3974 /* ignore since it can't change */
3975 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3976 break;
3977 default:
3978 /* disallow mesh-specific things */
3979 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3980 return -EINVAL;
3981 if (params->local_pm)
3982 return -EINVAL;
3983 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3984 return -EINVAL;
3985 }
3986
3987 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3988 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3989 /* TDLS can't be set, ... */
3990 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3991 return -EINVAL;
3992 /*
3993 * ... but don't bother the driver with it. This works around
3994 * a hostapd/wpa_supplicant issue -- it always includes the
3995 * TLDS_PEER flag in the mask even for AP mode.
3996 */
3997 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3998 }
3999
4000 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
4001 /* reject other things that can't change */
4002 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4003 return -EINVAL;
4004 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4005 return -EINVAL;
4006 if (params->supported_rates)
4007 return -EINVAL;
4008 if (params->ext_capab || params->ht_capa || params->vht_capa)
4009 return -EINVAL;
4010 }
4011
4012 if (statype != CFG80211_STA_AP_CLIENT) {
4013 if (params->vlan)
4014 return -EINVAL;
4015 }
4016
4017 switch (statype) {
4018 case CFG80211_STA_AP_MLME_CLIENT:
4019 /* Use this only for authorizing/unauthorizing a station */
4020 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4021 return -EOPNOTSUPP;
4022 break;
4023 case CFG80211_STA_AP_CLIENT:
4024 /* accept only the listed bits */
4025 if (params->sta_flags_mask &
4026 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4027 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4028 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4029 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4030 BIT(NL80211_STA_FLAG_WME) |
4031 BIT(NL80211_STA_FLAG_MFP)))
4032 return -EINVAL;
4033
4034 /* but authenticated/associated only if driver handles it */
4035 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4036 params->sta_flags_mask &
4037 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4038 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4039 return -EINVAL;
4040 break;
4041 case CFG80211_STA_IBSS:
4042 case CFG80211_STA_AP_STA:
4043 /* reject any changes other than AUTHORIZED */
4044 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4045 return -EINVAL;
4046 break;
4047 case CFG80211_STA_TDLS_PEER_SETUP:
4048 /* reject any changes other than AUTHORIZED or WME */
4049 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4050 BIT(NL80211_STA_FLAG_WME)))
4051 return -EINVAL;
4052 /* force (at least) rates when authorizing */
4053 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4054 !params->supported_rates)
4055 return -EINVAL;
4056 break;
4057 case CFG80211_STA_TDLS_PEER_ACTIVE:
4058 /* reject any changes */
4059 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004060 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004061 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4062 return -EINVAL;
4063 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004064 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004065 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
4066 return -EINVAL;
4067 break;
4068 }
4069
4070 return 0;
4071}
4072EXPORT_SYMBOL(cfg80211_check_station_change);
4073
Johannes Berg5727ef12007-12-19 02:03:34 +01004074/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004075 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004076 */
Johannes Berg80b99892011-11-18 16:23:01 +01004077static struct net_device *get_vlan(struct genl_info *info,
4078 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004079{
Johannes Berg463d0182009-07-14 00:33:35 +02004080 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004081 struct net_device *v;
4082 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004083
Johannes Berg80b99892011-11-18 16:23:01 +01004084 if (!vlanattr)
4085 return NULL;
4086
4087 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4088 if (!v)
4089 return ERR_PTR(-ENODEV);
4090
4091 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4092 ret = -EINVAL;
4093 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004094 }
Johannes Berg80b99892011-11-18 16:23:01 +01004095
Johannes Berg77ee7c82013-02-15 00:48:33 +01004096 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4097 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4098 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4099 ret = -EINVAL;
4100 goto error;
4101 }
4102
Johannes Berg80b99892011-11-18 16:23:01 +01004103 if (!netif_running(v)) {
4104 ret = -ENETDOWN;
4105 goto error;
4106 }
4107
4108 return v;
4109 error:
4110 dev_put(v);
4111 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004112}
4113
Johannes Berg94e860f2014-01-20 23:58:15 +01004114static const struct nla_policy
4115nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004116 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4117 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4118};
4119
Johannes Bergff276692013-02-15 00:09:01 +01004120static int nl80211_parse_sta_wme(struct genl_info *info,
4121 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004122{
Jouni Malinendf881292013-02-14 21:10:54 +02004123 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4124 struct nlattr *nla;
4125 int err;
4126
Jouni Malinendf881292013-02-14 21:10:54 +02004127 /* parse WME attributes if present */
4128 if (!info->attrs[NL80211_ATTR_STA_WME])
4129 return 0;
4130
4131 nla = info->attrs[NL80211_ATTR_STA_WME];
4132 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4133 nl80211_sta_wme_policy);
4134 if (err)
4135 return err;
4136
4137 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4138 params->uapsd_queues = nla_get_u8(
4139 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4140 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4141 return -EINVAL;
4142
4143 if (tb[NL80211_STA_WME_MAX_SP])
4144 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4145
4146 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4147 return -EINVAL;
4148
4149 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4150
4151 return 0;
4152}
4153
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304154static int nl80211_parse_sta_channel_info(struct genl_info *info,
4155 struct station_parameters *params)
4156{
4157 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4158 params->supported_channels =
4159 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4160 params->supported_channels_len =
4161 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4162 /*
4163 * Need to include at least one (first channel, number of
4164 * channels) tuple for each subband, and must have proper
4165 * tuples for the rest of the data as well.
4166 */
4167 if (params->supported_channels_len < 2)
4168 return -EINVAL;
4169 if (params->supported_channels_len % 2)
4170 return -EINVAL;
4171 }
4172
4173 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4174 params->supported_oper_classes =
4175 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4176 params->supported_oper_classes_len =
4177 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4178 /*
4179 * The value of the Length field of the Supported Operating
4180 * Classes element is between 2 and 253.
4181 */
4182 if (params->supported_oper_classes_len < 2 ||
4183 params->supported_oper_classes_len > 253)
4184 return -EINVAL;
4185 }
4186 return 0;
4187}
4188
Johannes Bergff276692013-02-15 00:09:01 +01004189static int nl80211_set_station_tdls(struct genl_info *info,
4190 struct station_parameters *params)
4191{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304192 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004193 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004194 if (info->attrs[NL80211_ATTR_PEER_AID])
4195 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004196 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4197 params->ht_capa =
4198 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4199 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4200 params->vht_capa =
4201 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4202
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304203 err = nl80211_parse_sta_channel_info(info, params);
4204 if (err)
4205 return err;
4206
Johannes Bergff276692013-02-15 00:09:01 +01004207 return nl80211_parse_sta_wme(info, params);
4208}
4209
Johannes Berg5727ef12007-12-19 02:03:34 +01004210static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4211{
Johannes Berg4c476992010-10-04 21:36:35 +02004212 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004213 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004214 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004215 u8 *mac_addr;
4216 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004217
4218 memset(&params, 0, sizeof(params));
4219
4220 params.listen_interval = -1;
4221
Johannes Berg77ee7c82013-02-15 00:48:33 +01004222 if (!rdev->ops->change_station)
4223 return -EOPNOTSUPP;
4224
Johannes Berg5727ef12007-12-19 02:03:34 +01004225 if (info->attrs[NL80211_ATTR_STA_AID])
4226 return -EINVAL;
4227
4228 if (!info->attrs[NL80211_ATTR_MAC])
4229 return -EINVAL;
4230
4231 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4232
4233 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4234 params.supported_rates =
4235 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4236 params.supported_rates_len =
4237 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4238 }
4239
Jouni Malinen9d62a982013-02-14 21:10:13 +02004240 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4241 params.capability =
4242 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4243 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4244 }
4245
4246 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4247 params.ext_capab =
4248 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4249 params.ext_capab_len =
4250 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4251 }
4252
Jouni Malinendf881292013-02-14 21:10:54 +02004253 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004254 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004255
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004256 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004257 return -EINVAL;
4258
Johannes Bergf8bacc22013-02-14 23:27:01 +01004259 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004260 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004261 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4262 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4263 return -EINVAL;
4264 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004265
Johannes Bergf8bacc22013-02-14 23:27:01 +01004266 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004267 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004268 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4269 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4270 return -EINVAL;
4271 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4272 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004273
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004274 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4275 enum nl80211_mesh_power_mode pm = nla_get_u32(
4276 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4277
4278 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4279 pm > NL80211_MESH_POWER_MAX)
4280 return -EINVAL;
4281
4282 params.local_pm = pm;
4283 }
4284
Johannes Berg77ee7c82013-02-15 00:48:33 +01004285 /* Include parameters for TDLS peer (will check later) */
4286 err = nl80211_set_station_tdls(info, &params);
4287 if (err)
4288 return err;
4289
4290 params.vlan = get_vlan(info, rdev);
4291 if (IS_ERR(params.vlan))
4292 return PTR_ERR(params.vlan);
4293
Johannes Berga97f4422009-06-18 17:23:43 +02004294 switch (dev->ieee80211_ptr->iftype) {
4295 case NL80211_IFTYPE_AP:
4296 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004297 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004298 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004299 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004300 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004301 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004302 break;
4303 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004304 err = -EOPNOTSUPP;
4305 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004306 }
4307
Johannes Berg77ee7c82013-02-15 00:48:33 +01004308 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004309 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004310
Johannes Berg77ee7c82013-02-15 00:48:33 +01004311 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004312 if (params.vlan)
4313 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004314
Johannes Berg5727ef12007-12-19 02:03:34 +01004315 return err;
4316}
4317
4318static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4319{
Johannes Berg4c476992010-10-04 21:36:35 +02004320 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004321 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004322 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004323 struct station_parameters params;
4324 u8 *mac_addr = NULL;
4325
4326 memset(&params, 0, sizeof(params));
4327
Johannes Berg984c3112013-02-14 23:43:25 +01004328 if (!rdev->ops->add_station)
4329 return -EOPNOTSUPP;
4330
Johannes Berg5727ef12007-12-19 02:03:34 +01004331 if (!info->attrs[NL80211_ATTR_MAC])
4332 return -EINVAL;
4333
Johannes Berg5727ef12007-12-19 02:03:34 +01004334 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4335 return -EINVAL;
4336
4337 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4338 return -EINVAL;
4339
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004340 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4341 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004342 return -EINVAL;
4343
Johannes Berg5727ef12007-12-19 02:03:34 +01004344 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4345 params.supported_rates =
4346 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4347 params.supported_rates_len =
4348 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4349 params.listen_interval =
4350 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004351
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004352 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004353 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004354 else
4355 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004356 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4357 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004358
Jouni Malinen9d62a982013-02-14 21:10:13 +02004359 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4360 params.capability =
4361 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4362 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4363 }
4364
4365 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4366 params.ext_capab =
4367 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4368 params.ext_capab_len =
4369 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4370 }
4371
Jouni Malinen36aedc92008-08-25 11:58:58 +03004372 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4373 params.ht_capa =
4374 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004375
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004376 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4377 params.vht_capa =
4378 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4379
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004380 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4381 params.opmode_notif_used = true;
4382 params.opmode_notif =
4383 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4384 }
4385
Johannes Bergf8bacc22013-02-14 23:27:01 +01004386 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004387 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004388 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4389 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4390 return -EINVAL;
4391 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004392
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304393 err = nl80211_parse_sta_channel_info(info, &params);
4394 if (err)
4395 return err;
4396
Johannes Bergff276692013-02-15 00:09:01 +01004397 err = nl80211_parse_sta_wme(info, &params);
4398 if (err)
4399 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004400
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004401 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004402 return -EINVAL;
4403
Johannes Berg77ee7c82013-02-15 00:48:33 +01004404 /* When you run into this, adjust the code below for the new flag */
4405 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4406
Johannes Bergbdd90d52011-12-14 12:20:27 +01004407 switch (dev->ieee80211_ptr->iftype) {
4408 case NL80211_IFTYPE_AP:
4409 case NL80211_IFTYPE_AP_VLAN:
4410 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004411 /* ignore WME attributes if iface/sta is not capable */
4412 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4413 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4414 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004415
Johannes Bergbdd90d52011-12-14 12:20:27 +01004416 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004417 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4418 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004419 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004420 /* but don't bother the driver with it */
4421 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004422
Johannes Bergd582cff2012-10-26 17:53:44 +02004423 /* allow authenticated/associated only if driver handles it */
4424 if (!(rdev->wiphy.features &
4425 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4426 params.sta_flags_mask &
4427 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4428 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4429 return -EINVAL;
4430
Johannes Bergbdd90d52011-12-14 12:20:27 +01004431 /* must be last in here for error handling */
4432 params.vlan = get_vlan(info, rdev);
4433 if (IS_ERR(params.vlan))
4434 return PTR_ERR(params.vlan);
4435 break;
4436 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004437 /* ignore uAPSD data */
4438 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4439
Johannes Bergd582cff2012-10-26 17:53:44 +02004440 /* associated is disallowed */
4441 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4442 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004443 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004444 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4445 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004446 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004447 break;
4448 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004449 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004450 /* ignore uAPSD data */
4451 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4452
Johannes Berg77ee7c82013-02-15 00:48:33 +01004453 /* these are disallowed */
4454 if (params.sta_flags_mask &
4455 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4456 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004457 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004458 /* Only TDLS peers can be added */
4459 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4460 return -EINVAL;
4461 /* Can only add if TDLS ... */
4462 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4463 return -EOPNOTSUPP;
4464 /* ... with external setup is supported */
4465 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4466 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004467 /*
4468 * Older wpa_supplicant versions always mark the TDLS peer
4469 * as authorized, but it shouldn't yet be.
4470 */
4471 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004472 break;
4473 default:
4474 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004475 }
4476
Johannes Bergbdd90d52011-12-14 12:20:27 +01004477 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004478
Hila Gonene35e4d22012-06-27 17:19:42 +03004479 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004480
Johannes Berg5727ef12007-12-19 02:03:34 +01004481 if (params.vlan)
4482 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004483 return err;
4484}
4485
4486static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4487{
Johannes Berg4c476992010-10-04 21:36:35 +02004488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4489 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004490 struct station_del_parameters params;
4491
4492 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004493
4494 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004495 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004496
Johannes Berge80cf852009-05-11 14:43:13 +02004497 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004498 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004499 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004500 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4501 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004502
Johannes Berg4c476992010-10-04 21:36:35 +02004503 if (!rdev->ops->del_station)
4504 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004505
Jouni Malinen98856862014-10-20 13:20:45 +03004506 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4507 params.subtype =
4508 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4509 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4510 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4511 return -EINVAL;
4512 } else {
4513 /* Default to Deauthentication frame */
4514 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4515 }
4516
4517 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4518 params.reason_code =
4519 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4520 if (params.reason_code == 0)
4521 return -EINVAL; /* 0 is reserved */
4522 } else {
4523 /* Default to reason code 2 */
4524 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4525 }
4526
Jouni Malinen89c771e2014-10-10 20:52:40 +03004527 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004528}
4529
Eric W. Biederman15e47302012-09-07 20:12:54 +00004530static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004531 int flags, struct net_device *dev,
4532 u8 *dst, u8 *next_hop,
4533 struct mpath_info *pinfo)
4534{
4535 void *hdr;
4536 struct nlattr *pinfoattr;
4537
Henning Rogge1ef4c852014-11-04 16:14:58 +01004538 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004539 if (!hdr)
4540 return -1;
4541
David S. Miller9360ffd2012-03-29 04:41:26 -04004542 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4543 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4544 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4545 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4546 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004547
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004548 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4549 if (!pinfoattr)
4550 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004551 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4552 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4553 pinfo->frame_qlen))
4554 goto nla_put_failure;
4555 if (((pinfo->filled & MPATH_INFO_SN) &&
4556 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4557 ((pinfo->filled & MPATH_INFO_METRIC) &&
4558 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4559 pinfo->metric)) ||
4560 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4561 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4562 pinfo->exptime)) ||
4563 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4564 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4565 pinfo->flags)) ||
4566 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4567 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4568 pinfo->discovery_timeout)) ||
4569 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4570 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4571 pinfo->discovery_retries)))
4572 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004573
4574 nla_nest_end(msg, pinfoattr);
4575
Johannes Berg053c0952015-01-16 22:09:00 +01004576 genlmsg_end(msg, hdr);
4577 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004578
4579 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004580 genlmsg_cancel(msg, hdr);
4581 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004582}
4583
4584static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004585 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004586{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004587 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004588 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004589 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004590 u8 dst[ETH_ALEN];
4591 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004592 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004593 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004594
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004595 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004596 if (err)
4597 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004598
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004599 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004600 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004601 goto out_err;
4602 }
4603
Johannes Berg97990a02013-04-19 01:02:55 +02004604 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004605 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004606 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004607 }
4608
Johannes Bergbba95fe2008-07-29 13:22:51 +02004609 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004610 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004611 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004612 if (err == -ENOENT)
4613 break;
4614 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004615 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004616
Eric W. Biederman15e47302012-09-07 20:12:54 +00004617 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004618 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004619 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004620 &pinfo) < 0)
4621 goto out;
4622
4623 path_idx++;
4624 }
4625
4626
4627 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004628 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004629 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004630 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004631 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004632 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004633}
4634
4635static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4636{
Johannes Berg4c476992010-10-04 21:36:35 +02004637 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004638 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004639 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004640 struct mpath_info pinfo;
4641 struct sk_buff *msg;
4642 u8 *dst = NULL;
4643 u8 next_hop[ETH_ALEN];
4644
4645 memset(&pinfo, 0, sizeof(pinfo));
4646
4647 if (!info->attrs[NL80211_ATTR_MAC])
4648 return -EINVAL;
4649
4650 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4651
Johannes Berg4c476992010-10-04 21:36:35 +02004652 if (!rdev->ops->get_mpath)
4653 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004654
Johannes Berg4c476992010-10-04 21:36:35 +02004655 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4656 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004657
Hila Gonene35e4d22012-06-27 17:19:42 +03004658 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004659 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004660 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004661
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004662 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004663 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004664 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004665
Eric W. Biederman15e47302012-09-07 20:12:54 +00004666 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004667 dev, dst, next_hop, &pinfo) < 0) {
4668 nlmsg_free(msg);
4669 return -ENOBUFS;
4670 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004671
Johannes Berg4c476992010-10-04 21:36:35 +02004672 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004673}
4674
4675static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4676{
Johannes Berg4c476992010-10-04 21:36:35 +02004677 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4678 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004679 u8 *dst = NULL;
4680 u8 *next_hop = NULL;
4681
4682 if (!info->attrs[NL80211_ATTR_MAC])
4683 return -EINVAL;
4684
4685 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4686 return -EINVAL;
4687
4688 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4689 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4690
Johannes Berg4c476992010-10-04 21:36:35 +02004691 if (!rdev->ops->change_mpath)
4692 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004693
Johannes Berg4c476992010-10-04 21:36:35 +02004694 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4695 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004696
Hila Gonene35e4d22012-06-27 17:19:42 +03004697 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004698}
Johannes Berg4c476992010-10-04 21:36:35 +02004699
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004700static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4701{
Johannes Berg4c476992010-10-04 21:36:35 +02004702 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4703 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004704 u8 *dst = NULL;
4705 u8 *next_hop = NULL;
4706
4707 if (!info->attrs[NL80211_ATTR_MAC])
4708 return -EINVAL;
4709
4710 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4711 return -EINVAL;
4712
4713 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4714 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4715
Johannes Berg4c476992010-10-04 21:36:35 +02004716 if (!rdev->ops->add_mpath)
4717 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004718
Johannes Berg4c476992010-10-04 21:36:35 +02004719 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4720 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004721
Hila Gonene35e4d22012-06-27 17:19:42 +03004722 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004723}
4724
4725static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4726{
Johannes Berg4c476992010-10-04 21:36:35 +02004727 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4728 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004729 u8 *dst = NULL;
4730
4731 if (info->attrs[NL80211_ATTR_MAC])
4732 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4733
Johannes Berg4c476992010-10-04 21:36:35 +02004734 if (!rdev->ops->del_mpath)
4735 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004736
Hila Gonene35e4d22012-06-27 17:19:42 +03004737 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004738}
4739
Henning Rogge66be7d22014-09-12 08:58:49 +02004740static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4741{
4742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4743 int err;
4744 struct net_device *dev = info->user_ptr[1];
4745 struct mpath_info pinfo;
4746 struct sk_buff *msg;
4747 u8 *dst = NULL;
4748 u8 mpp[ETH_ALEN];
4749
4750 memset(&pinfo, 0, sizeof(pinfo));
4751
4752 if (!info->attrs[NL80211_ATTR_MAC])
4753 return -EINVAL;
4754
4755 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4756
4757 if (!rdev->ops->get_mpp)
4758 return -EOPNOTSUPP;
4759
4760 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4761 return -EOPNOTSUPP;
4762
4763 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4764 if (err)
4765 return err;
4766
4767 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4768 if (!msg)
4769 return -ENOMEM;
4770
4771 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4772 dev, dst, mpp, &pinfo) < 0) {
4773 nlmsg_free(msg);
4774 return -ENOBUFS;
4775 }
4776
4777 return genlmsg_reply(msg, info);
4778}
4779
4780static int nl80211_dump_mpp(struct sk_buff *skb,
4781 struct netlink_callback *cb)
4782{
4783 struct mpath_info pinfo;
4784 struct cfg80211_registered_device *rdev;
4785 struct wireless_dev *wdev;
4786 u8 dst[ETH_ALEN];
4787 u8 mpp[ETH_ALEN];
4788 int path_idx = cb->args[2];
4789 int err;
4790
4791 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4792 if (err)
4793 return err;
4794
4795 if (!rdev->ops->dump_mpp) {
4796 err = -EOPNOTSUPP;
4797 goto out_err;
4798 }
4799
4800 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4801 err = -EOPNOTSUPP;
4802 goto out_err;
4803 }
4804
4805 while (1) {
4806 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4807 mpp, &pinfo);
4808 if (err == -ENOENT)
4809 break;
4810 if (err)
4811 goto out_err;
4812
4813 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4814 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4815 wdev->netdev, dst, mpp,
4816 &pinfo) < 0)
4817 goto out;
4818
4819 path_idx++;
4820 }
4821
4822 out:
4823 cb->args[2] = path_idx;
4824 err = skb->len;
4825 out_err:
4826 nl80211_finish_wdev_dump(rdev);
4827 return err;
4828}
4829
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004830static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4831{
Johannes Berg4c476992010-10-04 21:36:35 +02004832 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4833 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004834 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004835 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004836 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004837
4838 memset(&params, 0, sizeof(params));
4839 /* default to not changing parameters */
4840 params.use_cts_prot = -1;
4841 params.use_short_preamble = -1;
4842 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004843 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004844 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004845 params.p2p_ctwindow = -1;
4846 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004847
4848 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4849 params.use_cts_prot =
4850 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4851 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4852 params.use_short_preamble =
4853 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4854 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4855 params.use_short_slot_time =
4856 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004857 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4858 params.basic_rates =
4859 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4860 params.basic_rates_len =
4861 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4862 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004863 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4864 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004865 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4866 params.ht_opmode =
4867 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004868
Johannes Berg53cabad2012-11-14 15:17:28 +01004869 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4870 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4871 return -EINVAL;
4872 params.p2p_ctwindow =
4873 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4874 if (params.p2p_ctwindow < 0)
4875 return -EINVAL;
4876 if (params.p2p_ctwindow != 0 &&
4877 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4878 return -EINVAL;
4879 }
4880
4881 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4882 u8 tmp;
4883
4884 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4885 return -EINVAL;
4886 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4887 if (tmp > 1)
4888 return -EINVAL;
4889 params.p2p_opp_ps = tmp;
4890 if (params.p2p_opp_ps &&
4891 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4892 return -EINVAL;
4893 }
4894
Johannes Berg4c476992010-10-04 21:36:35 +02004895 if (!rdev->ops->change_bss)
4896 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004897
Johannes Berg074ac8d2010-09-16 14:58:22 +02004898 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004899 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4900 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004901
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004902 wdev_lock(wdev);
4903 err = rdev_change_bss(rdev, dev, &params);
4904 wdev_unlock(wdev);
4905
4906 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004907}
4908
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004909static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004910 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4911 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4912 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4913 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4914 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4915 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004916 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004917};
4918
4919static int parse_reg_rule(struct nlattr *tb[],
4920 struct ieee80211_reg_rule *reg_rule)
4921{
4922 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4923 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4924
4925 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4926 return -EINVAL;
4927 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4928 return -EINVAL;
4929 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4930 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004931 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4932 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004933 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4934 return -EINVAL;
4935
4936 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4937
4938 freq_range->start_freq_khz =
4939 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4940 freq_range->end_freq_khz =
4941 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004942 freq_range->max_bandwidth_khz =
4943 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004944
4945 power_rule->max_eirp =
4946 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4947
4948 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4949 power_rule->max_antenna_gain =
4950 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4951
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004952 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4953 reg_rule->dfs_cac_ms =
4954 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4955
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004956 return 0;
4957}
4958
4959static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4960{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004961 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05004962 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004963 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05004964 u32 owner_nlportid;
4965
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004966
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004967 /*
4968 * You should only get this when cfg80211 hasn't yet initialized
4969 * completely when built-in to the kernel right between the time
4970 * window between nl80211_init() and regulatory_init(), if that is
4971 * even possible.
4972 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004973 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004974 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004975
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004976 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4977 user_reg_hint_type =
4978 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4979 else
4980 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4981
4982 switch (user_reg_hint_type) {
4983 case NL80211_USER_REG_HINT_USER:
4984 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004985 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4986 return -EINVAL;
4987
4988 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
4989 return regulatory_hint_user(data, user_reg_hint_type);
4990 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05004991 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
4992 owner_nlportid = info->snd_portid;
4993 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
4994 } else {
4995 owner_nlportid = 0;
4996 is_indoor = true;
4997 }
4998
4999 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005000 default:
5001 return -EINVAL;
5002 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005003}
5004
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005005static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005006 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005007{
Johannes Berg4c476992010-10-04 21:36:35 +02005008 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005009 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005010 struct wireless_dev *wdev = dev->ieee80211_ptr;
5011 struct mesh_config cur_params;
5012 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005013 void *hdr;
5014 struct nlattr *pinfoattr;
5015 struct sk_buff *msg;
5016
Johannes Berg29cbe682010-12-03 09:20:44 +01005017 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5018 return -EOPNOTSUPP;
5019
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005020 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005021 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005022
Johannes Berg29cbe682010-12-03 09:20:44 +01005023 wdev_lock(wdev);
5024 /* If not connected, get default parameters */
5025 if (!wdev->mesh_id_len)
5026 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5027 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005028 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005029 wdev_unlock(wdev);
5030
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005031 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005032 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005033
5034 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005035 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005036 if (!msg)
5037 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005038 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005039 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005040 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005041 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005042 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005043 if (!pinfoattr)
5044 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005045 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5046 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5047 cur_params.dot11MeshRetryTimeout) ||
5048 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5049 cur_params.dot11MeshConfirmTimeout) ||
5050 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5051 cur_params.dot11MeshHoldingTimeout) ||
5052 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5053 cur_params.dot11MeshMaxPeerLinks) ||
5054 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5055 cur_params.dot11MeshMaxRetries) ||
5056 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5057 cur_params.dot11MeshTTL) ||
5058 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5059 cur_params.element_ttl) ||
5060 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5061 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005062 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5063 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005064 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5065 cur_params.dot11MeshHWMPmaxPREQretries) ||
5066 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5067 cur_params.path_refresh_time) ||
5068 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5069 cur_params.min_discovery_timeout) ||
5070 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5071 cur_params.dot11MeshHWMPactivePathTimeout) ||
5072 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5073 cur_params.dot11MeshHWMPpreqMinInterval) ||
5074 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5075 cur_params.dot11MeshHWMPperrMinInterval) ||
5076 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5077 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5078 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5079 cur_params.dot11MeshHWMPRootMode) ||
5080 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5081 cur_params.dot11MeshHWMPRannInterval) ||
5082 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5083 cur_params.dot11MeshGateAnnouncementProtocol) ||
5084 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5085 cur_params.dot11MeshForwarding) ||
5086 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005087 cur_params.rssi_threshold) ||
5088 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005089 cur_params.ht_opmode) ||
5090 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5091 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5092 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005093 cur_params.dot11MeshHWMProotInterval) ||
5094 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005095 cur_params.dot11MeshHWMPconfirmationInterval) ||
5096 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5097 cur_params.power_mode) ||
5098 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005099 cur_params.dot11MeshAwakeWindowDuration) ||
5100 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5101 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005102 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005103 nla_nest_end(msg, pinfoattr);
5104 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005105 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005106
Johannes Berg3b858752009-03-12 09:55:09 +01005107 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005108 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005109 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005110 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005111 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005112}
5113
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005114static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005115 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5116 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5117 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5118 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5119 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5120 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005121 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005122 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005123 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005124 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5125 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5126 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5127 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5128 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005129 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005130 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005131 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005132 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005133 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005134 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005135 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5136 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005137 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5138 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005139 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005140 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5141 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005142 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005143};
5144
Javier Cardonac80d5452010-12-16 17:37:49 -08005145static const struct nla_policy
5146 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005147 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005148 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5149 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005150 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005151 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005152 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005153 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005154 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005155 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005156};
5157
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005158static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005159 struct mesh_config *cfg,
5160 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005161{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005162 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005163 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005164
Marco Porschea54fba2013-01-07 16:04:48 +01005165#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5166do { \
5167 if (tb[attr]) { \
5168 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5169 return -EINVAL; \
5170 cfg->param = fn(tb[attr]); \
5171 mask |= (1 << (attr - 1)); \
5172 } \
5173} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005174
5175
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005176 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005177 return -EINVAL;
5178 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005179 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005180 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005181 return -EINVAL;
5182
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005183 /* This makes sure that there aren't more than 32 mesh config
5184 * parameters (otherwise our bitfield scheme would not work.) */
5185 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5186
5187 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005188 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005189 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5190 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005191 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005192 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5193 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005194 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005195 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5196 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005197 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005198 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5199 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005200 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005201 mask, NL80211_MESHCONF_MAX_RETRIES,
5202 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005203 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005204 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005205 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005206 mask, NL80211_MESHCONF_ELEMENT_TTL,
5207 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005208 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005209 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5210 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005211 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5212 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005213 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5214 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005215 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005216 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5217 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005218 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005219 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5220 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005221 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005222 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5223 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005224 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5225 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005226 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5227 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005228 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005229 1, 65535, mask,
5230 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005231 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005233 1, 65535, mask,
5234 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005235 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005236 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005237 dot11MeshHWMPnetDiameterTraversalTime,
5238 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005239 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5240 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005241 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5242 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5243 nla_get_u8);
5244 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5245 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005246 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005247 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005248 dot11MeshGateAnnouncementProtocol, 0, 1,
5249 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005250 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005251 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005252 mask, NL80211_MESHCONF_FORWARDING,
5253 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005254 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005255 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005256 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005257 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005258 mask, NL80211_MESHCONF_HT_OPMODE,
5259 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005260 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005261 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005262 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5263 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005264 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005265 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5266 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005267 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005268 dot11MeshHWMPconfirmationInterval,
5269 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005270 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5271 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005272 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5273 NL80211_MESH_POWER_ACTIVE,
5274 NL80211_MESH_POWER_MAX,
5275 mask, NL80211_MESHCONF_POWER_MODE,
5276 nla_get_u32);
5277 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5278 0, 65535, mask,
5279 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005280 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005281 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5282 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005283 if (mask_out)
5284 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005285
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005286 return 0;
5287
5288#undef FILL_IN_MESH_PARAM_IF_SET
5289}
5290
Javier Cardonac80d5452010-12-16 17:37:49 -08005291static int nl80211_parse_mesh_setup(struct genl_info *info,
5292 struct mesh_setup *setup)
5293{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005294 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005295 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5296
5297 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5298 return -EINVAL;
5299 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5300 info->attrs[NL80211_ATTR_MESH_SETUP],
5301 nl80211_mesh_setup_params_policy))
5302 return -EINVAL;
5303
Javier Cardonad299a1f2012-03-31 11:31:33 -07005304 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5305 setup->sync_method =
5306 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5307 IEEE80211_SYNC_METHOD_VENDOR :
5308 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5309
Javier Cardonac80d5452010-12-16 17:37:49 -08005310 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5311 setup->path_sel_proto =
5312 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5313 IEEE80211_PATH_PROTOCOL_VENDOR :
5314 IEEE80211_PATH_PROTOCOL_HWMP;
5315
5316 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5317 setup->path_metric =
5318 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5319 IEEE80211_PATH_METRIC_VENDOR :
5320 IEEE80211_PATH_METRIC_AIRTIME;
5321
Javier Cardona581a8b02011-04-07 15:08:27 -07005322
5323 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005324 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005325 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005326 if (!is_valid_ie_attr(ieattr))
5327 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005328 setup->ie = nla_data(ieattr);
5329 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005330 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005331 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5332 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5333 return -EINVAL;
5334 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005335 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5336 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005337 if (setup->is_secure)
5338 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005339
Colleen Twitty6e16d902013-05-08 11:45:59 -07005340 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5341 if (!setup->user_mpm)
5342 return -EINVAL;
5343 setup->auth_id =
5344 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5345 }
5346
Javier Cardonac80d5452010-12-16 17:37:49 -08005347 return 0;
5348}
5349
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005350static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005351 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005352{
5353 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5354 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005355 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005356 struct mesh_config cfg;
5357 u32 mask;
5358 int err;
5359
Johannes Berg29cbe682010-12-03 09:20:44 +01005360 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5361 return -EOPNOTSUPP;
5362
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005363 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005364 return -EOPNOTSUPP;
5365
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005366 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005367 if (err)
5368 return err;
5369
Johannes Berg29cbe682010-12-03 09:20:44 +01005370 wdev_lock(wdev);
5371 if (!wdev->mesh_id_len)
5372 err = -ENOLINK;
5373
5374 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005375 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005376
5377 wdev_unlock(wdev);
5378
5379 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005380}
5381
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005382static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5383 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005384{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005385 struct nlattr *nl_reg_rules;
5386 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005387
Johannes Berg458f4f92012-12-06 15:47:38 +01005388 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5389 (regdom->dfs_region &&
5390 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005391 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005392
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005393 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5394 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005395 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005396
Johannes Berg458f4f92012-12-06 15:47:38 +01005397 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005398 struct nlattr *nl_reg_rule;
5399 const struct ieee80211_reg_rule *reg_rule;
5400 const struct ieee80211_freq_range *freq_range;
5401 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005402 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005403
Johannes Berg458f4f92012-12-06 15:47:38 +01005404 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005405 freq_range = &reg_rule->freq_range;
5406 power_rule = &reg_rule->power_rule;
5407
5408 nl_reg_rule = nla_nest_start(msg, i);
5409 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005410 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005411
Janusz Dziedzic97524822014-01-30 09:52:20 +01005412 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5413 if (!max_bandwidth_khz)
5414 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5415 reg_rule);
5416
David S. Miller9360ffd2012-03-29 04:41:26 -04005417 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5418 reg_rule->flags) ||
5419 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5420 freq_range->start_freq_khz) ||
5421 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5422 freq_range->end_freq_khz) ||
5423 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005424 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005425 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5426 power_rule->max_antenna_gain) ||
5427 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005428 power_rule->max_eirp) ||
5429 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5430 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005431 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005432
5433 nla_nest_end(msg, nl_reg_rule);
5434 }
5435
5436 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005437 return 0;
5438
5439nla_put_failure:
5440 return -EMSGSIZE;
5441}
5442
5443static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5444{
5445 const struct ieee80211_regdomain *regdom = NULL;
5446 struct cfg80211_registered_device *rdev;
5447 struct wiphy *wiphy = NULL;
5448 struct sk_buff *msg;
5449 void *hdr;
5450
5451 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5452 if (!msg)
5453 return -ENOBUFS;
5454
5455 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5456 NL80211_CMD_GET_REG);
5457 if (!hdr)
5458 goto put_failure;
5459
5460 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005461 bool self_managed;
5462
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005463 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5464 if (IS_ERR(rdev)) {
5465 nlmsg_free(msg);
5466 return PTR_ERR(rdev);
5467 }
5468
5469 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005470 self_managed = wiphy->regulatory_flags &
5471 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005472 regdom = get_wiphy_regdom(wiphy);
5473
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005474 /* a self-managed-reg device must have a private regdom */
5475 if (WARN_ON(!regdom && self_managed)) {
5476 nlmsg_free(msg);
5477 return -EINVAL;
5478 }
5479
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005480 if (regdom &&
5481 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5482 goto nla_put_failure;
5483 }
5484
5485 if (!wiphy && reg_last_request_cell_base() &&
5486 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5487 NL80211_USER_REG_HINT_CELL_BASE))
5488 goto nla_put_failure;
5489
5490 rcu_read_lock();
5491
5492 if (!regdom)
5493 regdom = rcu_dereference(cfg80211_regdomain);
5494
5495 if (nl80211_put_regdom(regdom, msg))
5496 goto nla_put_failure_rcu;
5497
5498 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005499
5500 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005501 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005502
Johannes Berg458f4f92012-12-06 15:47:38 +01005503nla_put_failure_rcu:
5504 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005505nla_put_failure:
5506 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005507put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005508 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005509 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005510}
5511
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005512static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5513 u32 seq, int flags, struct wiphy *wiphy,
5514 const struct ieee80211_regdomain *regdom)
5515{
5516 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5517 NL80211_CMD_GET_REG);
5518
5519 if (!hdr)
5520 return -1;
5521
5522 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5523
5524 if (nl80211_put_regdom(regdom, msg))
5525 goto nla_put_failure;
5526
5527 if (!wiphy && reg_last_request_cell_base() &&
5528 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5529 NL80211_USER_REG_HINT_CELL_BASE))
5530 goto nla_put_failure;
5531
5532 if (wiphy &&
5533 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5534 goto nla_put_failure;
5535
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005536 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5537 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5538 goto nla_put_failure;
5539
Johannes Berg053c0952015-01-16 22:09:00 +01005540 genlmsg_end(msg, hdr);
5541 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005542
5543nla_put_failure:
5544 genlmsg_cancel(msg, hdr);
5545 return -EMSGSIZE;
5546}
5547
5548static int nl80211_get_reg_dump(struct sk_buff *skb,
5549 struct netlink_callback *cb)
5550{
5551 const struct ieee80211_regdomain *regdom = NULL;
5552 struct cfg80211_registered_device *rdev;
5553 int err, reg_idx, start = cb->args[2];
5554
5555 rtnl_lock();
5556
5557 if (cfg80211_regdomain && start == 0) {
5558 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5559 NLM_F_MULTI, NULL,
5560 rtnl_dereference(cfg80211_regdomain));
5561 if (err < 0)
5562 goto out_err;
5563 }
5564
5565 /* the global regdom is idx 0 */
5566 reg_idx = 1;
5567 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5568 regdom = get_wiphy_regdom(&rdev->wiphy);
5569 if (!regdom)
5570 continue;
5571
5572 if (++reg_idx <= start)
5573 continue;
5574
5575 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5576 NLM_F_MULTI, &rdev->wiphy, regdom);
5577 if (err < 0) {
5578 reg_idx--;
5579 break;
5580 }
5581 }
5582
5583 cb->args[2] = reg_idx;
5584 err = skb->len;
5585out_err:
5586 rtnl_unlock();
5587 return err;
5588}
5589
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005590static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5591{
5592 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5593 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005594 char *alpha2;
5595 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005596 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005597 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005598 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005599
5600 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5601 return -EINVAL;
5602
5603 if (!info->attrs[NL80211_ATTR_REG_RULES])
5604 return -EINVAL;
5605
5606 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5607
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005608 if (info->attrs[NL80211_ATTR_DFS_REGION])
5609 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5610
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005611 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005612 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005613 num_rules++;
5614 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005615 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005616 }
5617
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005618 if (!reg_is_valid_request(alpha2))
5619 return -EINVAL;
5620
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005621 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005622 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005623
5624 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005625 if (!rd)
5626 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005627
5628 rd->n_reg_rules = num_rules;
5629 rd->alpha2[0] = alpha2[0];
5630 rd->alpha2[1] = alpha2[1];
5631
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005632 /*
5633 * Disable DFS master mode if the DFS region was
5634 * not supported or known on this kernel.
5635 */
5636 if (reg_supported_dfs_region(dfs_region))
5637 rd->dfs_region = dfs_region;
5638
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005639 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005640 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005641 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5642 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5643 reg_rule_policy);
5644 if (r)
5645 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005646 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5647 if (r)
5648 goto bad_reg;
5649
5650 rule_idx++;
5651
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005652 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5653 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005654 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005655 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005656 }
5657
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005658 r = set_regdom(rd);
Johannes Berg6913b492012-12-04 00:48:59 +01005659 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005660 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005661
Johannes Bergd2372b32008-10-24 20:32:20 +02005662 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005663 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005664 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005665}
5666
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005667static int validate_scan_freqs(struct nlattr *freqs)
5668{
5669 struct nlattr *attr1, *attr2;
5670 int n_channels = 0, tmp1, tmp2;
5671
5672 nla_for_each_nested(attr1, freqs, tmp1) {
5673 n_channels++;
5674 /*
5675 * Some hardware has a limited channel list for
5676 * scanning, and it is pretty much nonsensical
5677 * to scan for a channel twice, so disallow that
5678 * and don't require drivers to check that the
5679 * channel list they get isn't longer than what
5680 * they can scan, as long as they can scan all
5681 * the channels they registered at once.
5682 */
5683 nla_for_each_nested(attr2, freqs, tmp2)
5684 if (attr1 != attr2 &&
5685 nla_get_u32(attr1) == nla_get_u32(attr2))
5686 return 0;
5687 }
5688
5689 return n_channels;
5690}
5691
Johannes Bergad2b26a2014-06-12 21:39:05 +02005692static int nl80211_parse_random_mac(struct nlattr **attrs,
5693 u8 *mac_addr, u8 *mac_addr_mask)
5694{
5695 int i;
5696
5697 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
5698 memset(mac_addr, 0, ETH_ALEN);
5699 memset(mac_addr_mask, 0, ETH_ALEN);
5700 mac_addr[0] = 0x2;
5701 mac_addr_mask[0] = 0x3;
5702
5703 return 0;
5704 }
5705
5706 /* need both or none */
5707 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5708 return -EINVAL;
5709
5710 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5711 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5712
5713 /* don't allow or configure an mcast address */
5714 if (!is_multicast_ether_addr(mac_addr_mask) ||
5715 is_multicast_ether_addr(mac_addr))
5716 return -EINVAL;
5717
5718 /*
5719 * allow users to pass a MAC address that has bits set outside
5720 * of the mask, but don't bother drivers with having to deal
5721 * with such bits
5722 */
5723 for (i = 0; i < ETH_ALEN; i++)
5724 mac_addr[i] &= mac_addr_mask[i];
5725
5726 return 0;
5727}
5728
Johannes Berg2a519312009-02-10 21:25:55 +01005729static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5730{
Johannes Berg4c476992010-10-04 21:36:35 +02005731 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005732 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005733 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005734 struct nlattr *attr;
5735 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005736 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005737 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005738
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005739 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5740 return -EINVAL;
5741
Johannes Berg79c97e92009-07-07 03:56:12 +02005742 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005743
Johannes Berg4c476992010-10-04 21:36:35 +02005744 if (!rdev->ops->scan)
5745 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005746
Johannes Bergf9d15d12014-01-22 11:14:19 +02005747 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005748 err = -EBUSY;
5749 goto unlock;
5750 }
Johannes Berg2a519312009-02-10 21:25:55 +01005751
5752 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005753 n_channels = validate_scan_freqs(
5754 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005755 if (!n_channels) {
5756 err = -EINVAL;
5757 goto unlock;
5758 }
Johannes Berg2a519312009-02-10 21:25:55 +01005759 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005760 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005761 }
5762
5763 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5764 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5765 n_ssids++;
5766
Johannes Bergf9f47522013-03-19 15:04:07 +01005767 if (n_ssids > wiphy->max_scan_ssids) {
5768 err = -EINVAL;
5769 goto unlock;
5770 }
Johannes Berg2a519312009-02-10 21:25:55 +01005771
Jouni Malinen70692ad2009-02-16 19:39:13 +02005772 if (info->attrs[NL80211_ATTR_IE])
5773 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5774 else
5775 ie_len = 0;
5776
Johannes Bergf9f47522013-03-19 15:04:07 +01005777 if (ie_len > wiphy->max_scan_ie_len) {
5778 err = -EINVAL;
5779 goto unlock;
5780 }
Johannes Berg18a83652009-03-31 12:12:05 +02005781
Johannes Berg2a519312009-02-10 21:25:55 +01005782 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005783 + sizeof(*request->ssids) * n_ssids
5784 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005785 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005786 if (!request) {
5787 err = -ENOMEM;
5788 goto unlock;
5789 }
Johannes Berg2a519312009-02-10 21:25:55 +01005790
Johannes Berg2a519312009-02-10 21:25:55 +01005791 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005792 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005793 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005794 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005795 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005796 request->ie = (void *)(request->ssids + n_ssids);
5797 else
5798 request->ie = (void *)(request->channels + n_channels);
5799 }
Johannes Berg2a519312009-02-10 21:25:55 +01005800
Johannes Berg584991d2009-11-02 13:32:03 +01005801 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005802 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5803 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005804 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005805 struct ieee80211_channel *chan;
5806
5807 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5808
5809 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005810 err = -EINVAL;
5811 goto out_free;
5812 }
Johannes Berg584991d2009-11-02 13:32:03 +01005813
5814 /* ignore disabled channels */
5815 if (chan->flags & IEEE80211_CHAN_DISABLED)
5816 continue;
5817
5818 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005819 i++;
5820 }
5821 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005822 enum ieee80211_band band;
5823
Johannes Berg2a519312009-02-10 21:25:55 +01005824 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005825 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5826 int j;
5827 if (!wiphy->bands[band])
5828 continue;
5829 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005830 struct ieee80211_channel *chan;
5831
5832 chan = &wiphy->bands[band]->channels[j];
5833
5834 if (chan->flags & IEEE80211_CHAN_DISABLED)
5835 continue;
5836
5837 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005838 i++;
5839 }
5840 }
5841 }
5842
Johannes Berg584991d2009-11-02 13:32:03 +01005843 if (!i) {
5844 err = -EINVAL;
5845 goto out_free;
5846 }
5847
5848 request->n_channels = i;
5849
Johannes Berg2a519312009-02-10 21:25:55 +01005850 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005851 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005852 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005853 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005854 err = -EINVAL;
5855 goto out_free;
5856 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005857 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005858 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005859 i++;
5860 }
5861 }
5862
Jouni Malinen70692ad2009-02-16 19:39:13 +02005863 if (info->attrs[NL80211_ATTR_IE]) {
5864 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005865 memcpy((void *)request->ie,
5866 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005867 request->ie_len);
5868 }
5869
Johannes Berg34850ab2011-07-18 18:08:35 +02005870 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005871 if (wiphy->bands[i])
5872 request->rates[i] =
5873 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005874
5875 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5876 nla_for_each_nested(attr,
5877 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5878 tmp) {
5879 enum ieee80211_band band = nla_type(attr);
5880
Dan Carpenter84404622011-07-29 11:52:18 +03005881 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005882 err = -EINVAL;
5883 goto out_free;
5884 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005885
5886 if (!wiphy->bands[band])
5887 continue;
5888
Johannes Berg34850ab2011-07-18 18:08:35 +02005889 err = ieee80211_get_ratemask(wiphy->bands[band],
5890 nla_data(attr),
5891 nla_len(attr),
5892 &request->rates[band]);
5893 if (err)
5894 goto out_free;
5895 }
5896 }
5897
Sam Leffler46856bb2012-10-11 21:03:32 -07005898 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005899 request->flags = nla_get_u32(
5900 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005901 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5902 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005903 err = -EOPNOTSUPP;
5904 goto out_free;
5905 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005906
5907 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5908 if (!(wiphy->features &
5909 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5910 err = -EOPNOTSUPP;
5911 goto out_free;
5912 }
5913
5914 if (wdev->current_bss) {
5915 err = -EOPNOTSUPP;
5916 goto out_free;
5917 }
5918
5919 err = nl80211_parse_random_mac(info->attrs,
5920 request->mac_addr,
5921 request->mac_addr_mask);
5922 if (err)
5923 goto out_free;
5924 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005925 }
Sam Lefflered4737712012-10-11 21:03:31 -07005926
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305927 request->no_cck =
5928 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5929
Johannes Bergfd014282012-06-18 19:17:03 +02005930 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005931 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005932 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005933
Johannes Berg79c97e92009-07-07 03:56:12 +02005934 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005935 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005936
Johannes Berg463d0182009-07-14 00:33:35 +02005937 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005938 nl80211_send_scan_start(rdev, wdev);
5939 if (wdev->netdev)
5940 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005941 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005942 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005943 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005944 kfree(request);
5945 }
Johannes Berg3b858752009-03-12 09:55:09 +01005946
Johannes Bergf9f47522013-03-19 15:04:07 +01005947 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005948 return err;
5949}
5950
Luciano Coelho256da022014-11-10 16:13:46 +02005951static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005952nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005953 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005954{
5955 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005956 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005957 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005958 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005959 enum ieee80211_band band;
5960 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005961 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005962 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005963
Luciano Coelho256da022014-11-10 16:13:46 +02005964 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5965 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005966
Luciano Coelho256da022014-11-10 16:13:46 +02005967 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5968 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005969
Luciano Coelho256da022014-11-10 16:13:46 +02005970 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005971 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005972 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005973
Luciano Coelho256da022014-11-10 16:13:46 +02005974 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005975 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005976 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005977 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005978 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005979 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005980 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005981 }
5982
Luciano Coelho256da022014-11-10 16:13:46 +02005983 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5984 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005985 tmp)
5986 n_ssids++;
5987
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005988 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02005989 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005990
Johannes Bergea73cbc2014-01-24 10:53:53 +01005991 /*
5992 * First, count the number of 'real' matchsets. Due to an issue with
5993 * the old implementation, matchsets containing only the RSSI attribute
5994 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
5995 * RSSI for all matchsets, rather than their own matchset for reporting
5996 * all APs with a strong RSSI. This is needed to be compatible with
5997 * older userspace that treated a matchset with only the RSSI as the
5998 * global RSSI for all other matchsets - if there are other matchsets.
5999 */
Luciano Coelho256da022014-11-10 16:13:46 +02006000 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006001 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006002 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006003 tmp) {
6004 struct nlattr *rssi;
6005
6006 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6007 nla_data(attr), nla_len(attr),
6008 nl80211_match_policy);
6009 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006010 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006011 /* add other standalone attributes here */
6012 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6013 n_match_sets++;
6014 continue;
6015 }
6016 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6017 if (rssi)
6018 default_match_rssi = nla_get_s32(rssi);
6019 }
6020 }
6021
6022 /* However, if there's no other matchset, add the RSSI one */
6023 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6024 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006025
6026 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006027 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006028
Luciano Coelho256da022014-11-10 16:13:46 +02006029 if (attrs[NL80211_ATTR_IE])
6030 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006031 else
6032 ie_len = 0;
6033
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006034 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006035 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006036
Luciano Coelho807f8a82011-05-11 17:09:35 +03006037 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006038 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006039 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006040 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006041 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006042 if (!request)
6043 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006044
6045 if (n_ssids)
6046 request->ssids = (void *)&request->channels[n_channels];
6047 request->n_ssids = n_ssids;
6048 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006049 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006050 request->ie = (void *)(request->ssids + n_ssids);
6051 else
6052 request->ie = (void *)(request->channels + n_channels);
6053 }
6054
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006055 if (n_match_sets) {
6056 if (request->ie)
6057 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006058 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006059 request->match_sets =
6060 (void *)(request->ssids + n_ssids);
6061 else
6062 request->match_sets =
6063 (void *)(request->channels + n_channels);
6064 }
6065 request->n_match_sets = n_match_sets;
6066
Luciano Coelho807f8a82011-05-11 17:09:35 +03006067 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006068 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006069 /* user specified, bail out if channel not found */
6070 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006071 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006072 tmp) {
6073 struct ieee80211_channel *chan;
6074
6075 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6076
6077 if (!chan) {
6078 err = -EINVAL;
6079 goto out_free;
6080 }
6081
6082 /* ignore disabled channels */
6083 if (chan->flags & IEEE80211_CHAN_DISABLED)
6084 continue;
6085
6086 request->channels[i] = chan;
6087 i++;
6088 }
6089 } else {
6090 /* all channels */
6091 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6092 int j;
6093 if (!wiphy->bands[band])
6094 continue;
6095 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6096 struct ieee80211_channel *chan;
6097
6098 chan = &wiphy->bands[band]->channels[j];
6099
6100 if (chan->flags & IEEE80211_CHAN_DISABLED)
6101 continue;
6102
6103 request->channels[i] = chan;
6104 i++;
6105 }
6106 }
6107 }
6108
6109 if (!i) {
6110 err = -EINVAL;
6111 goto out_free;
6112 }
6113
6114 request->n_channels = i;
6115
6116 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006117 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006118 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006119 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006120 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006121 err = -EINVAL;
6122 goto out_free;
6123 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006124 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006125 memcpy(request->ssids[i].ssid, nla_data(attr),
6126 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006127 i++;
6128 }
6129 }
6130
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006131 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006132 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006133 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006134 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006135 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006136 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006137
Johannes Bergae811e22014-01-24 10:17:47 +01006138 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6139 nla_data(attr), nla_len(attr),
6140 nl80211_match_policy);
6141 if (err)
6142 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006143 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006144 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006145 if (WARN_ON(i >= n_match_sets)) {
6146 /* this indicates a programming error,
6147 * the loop above should have verified
6148 * things properly
6149 */
6150 err = -EINVAL;
6151 goto out_free;
6152 }
6153
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006154 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6155 err = -EINVAL;
6156 goto out_free;
6157 }
6158 memcpy(request->match_sets[i].ssid.ssid,
6159 nla_data(ssid), nla_len(ssid));
6160 request->match_sets[i].ssid.ssid_len =
6161 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006162 /* special attribute - old implemenation w/a */
6163 request->match_sets[i].rssi_thold =
6164 default_match_rssi;
6165 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6166 if (rssi)
6167 request->match_sets[i].rssi_thold =
6168 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006169 }
6170 i++;
6171 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006172
6173 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006174 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006175 request->match_sets[0].rssi_thold = default_match_rssi;
6176
6177 request->min_rssi_thold = INT_MAX;
6178 for (i = 0; i < n_match_sets; i++)
6179 request->min_rssi_thold =
6180 min(request->match_sets[i].rssi_thold,
6181 request->min_rssi_thold);
6182 } else {
6183 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006184 }
6185
Johannes Berg9900e482014-02-04 21:01:25 +01006186 if (ie_len) {
6187 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006188 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006189 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006190 request->ie_len);
6191 }
6192
Luciano Coelho256da022014-11-10 16:13:46 +02006193 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006194 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006195 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006196 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6197 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006198 err = -EOPNOTSUPP;
6199 goto out_free;
6200 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006201
6202 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6203 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6204
6205 if (!wdev) /* must be net-detect */
6206 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6207
6208 if (!(wiphy->features & flg)) {
6209 err = -EOPNOTSUPP;
6210 goto out_free;
6211 }
6212
6213 if (wdev && wdev->current_bss) {
6214 err = -EOPNOTSUPP;
6215 goto out_free;
6216 }
6217
6218 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6219 request->mac_addr_mask);
6220 if (err)
6221 goto out_free;
6222 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006223 }
Sam Lefflered4737712012-10-11 21:03:31 -07006224
Luciano Coelho9c748932015-01-16 16:04:09 +02006225 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6226 request->delay =
6227 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6228
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006229 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006230 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006231
Luciano Coelho256da022014-11-10 16:13:46 +02006232 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006233
6234out_free:
6235 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006236 return ERR_PTR(err);
6237}
6238
6239static int nl80211_start_sched_scan(struct sk_buff *skb,
6240 struct genl_info *info)
6241{
6242 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6243 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006244 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006245 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006246 int err;
6247
6248 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6249 !rdev->ops->sched_scan_start)
6250 return -EOPNOTSUPP;
6251
6252 if (rdev->sched_scan_req)
6253 return -EINPROGRESS;
6254
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006255 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6256 info->attrs);
6257
6258 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006259 if (err)
6260 goto out_err;
6261
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006262 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006263 if (err)
6264 goto out_free;
6265
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006266 sched_scan_req->dev = dev;
6267 sched_scan_req->wiphy = &rdev->wiphy;
6268
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006269 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6270 sched_scan_req->owner_nlportid = info->snd_portid;
6271
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006272 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006273
6274 nl80211_send_sched_scan(rdev, dev,
6275 NL80211_CMD_START_SCHED_SCAN);
6276 return 0;
6277
6278out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006279 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006280out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006281 return err;
6282}
6283
6284static int nl80211_stop_sched_scan(struct sk_buff *skb,
6285 struct genl_info *info)
6286{
6287 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6288
6289 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6290 !rdev->ops->sched_scan_stop)
6291 return -EOPNOTSUPP;
6292
Johannes Berg5fe231e2013-05-08 21:45:15 +02006293 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006294}
6295
Simon Wunderlich04f39042013-02-08 18:16:19 +01006296static int nl80211_start_radar_detection(struct sk_buff *skb,
6297 struct genl_info *info)
6298{
6299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6300 struct net_device *dev = info->user_ptr[1];
6301 struct wireless_dev *wdev = dev->ieee80211_ptr;
6302 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006303 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006304 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006305 int err;
6306
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006307 dfs_region = reg_get_dfs_region(wdev->wiphy);
6308 if (dfs_region == NL80211_DFS_UNSET)
6309 return -EINVAL;
6310
Simon Wunderlich04f39042013-02-08 18:16:19 +01006311 err = nl80211_parse_chandef(rdev, info, &chandef);
6312 if (err)
6313 return err;
6314
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006315 if (netif_carrier_ok(dev))
6316 return -EBUSY;
6317
Simon Wunderlich04f39042013-02-08 18:16:19 +01006318 if (wdev->cac_started)
6319 return -EBUSY;
6320
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006321 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006322 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006323 if (err < 0)
6324 return err;
6325
6326 if (err == 0)
6327 return -EINVAL;
6328
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006329 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006330 return -EINVAL;
6331
6332 if (!rdev->ops->start_radar_detection)
6333 return -EOPNOTSUPP;
6334
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006335 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6336 if (WARN_ON(!cac_time_ms))
6337 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6338
6339 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6340 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006341 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006342 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006343 wdev->cac_started = true;
6344 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006345 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006346 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006347 return err;
6348}
6349
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006350static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6351{
6352 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6353 struct net_device *dev = info->user_ptr[1];
6354 struct wireless_dev *wdev = dev->ieee80211_ptr;
6355 struct cfg80211_csa_settings params;
6356 /* csa_attrs is defined static to avoid waste of stack size - this
6357 * function is called under RTNL lock, so this should not be a problem.
6358 */
6359 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006360 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006361 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006362 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006363 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006364
6365 if (!rdev->ops->channel_switch ||
6366 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6367 return -EOPNOTSUPP;
6368
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006369 switch (dev->ieee80211_ptr->iftype) {
6370 case NL80211_IFTYPE_AP:
6371 case NL80211_IFTYPE_P2P_GO:
6372 need_new_beacon = true;
6373
6374 /* useless if AP is not running */
6375 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006376 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006377 break;
6378 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006379 if (!wdev->ssid_len)
6380 return -ENOTCONN;
6381 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006382 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006383 if (!wdev->mesh_id_len)
6384 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006385 break;
6386 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006387 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006388 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006389
6390 memset(&params, 0, sizeof(params));
6391
6392 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6393 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6394 return -EINVAL;
6395
6396 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006397 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006398 return -EINVAL;
6399
Luciano Coelho252e07c2014-10-08 09:48:34 +03006400 /* Even though the attribute is u32, the specification says
6401 * u8, so let's make sure we don't overflow.
6402 */
6403 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6404 if (cs_count > 255)
6405 return -EINVAL;
6406
6407 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006408
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006409 if (!need_new_beacon)
6410 goto skip_beacons;
6411
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006412 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6413 if (err)
6414 return err;
6415
6416 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6417 info->attrs[NL80211_ATTR_CSA_IES],
6418 nl80211_policy);
6419 if (err)
6420 return err;
6421
6422 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6423 if (err)
6424 return err;
6425
6426 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6427 return -EINVAL;
6428
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006429 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6430 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006431 return -EINVAL;
6432
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006433 params.n_counter_offsets_beacon = len / sizeof(u16);
6434 if (rdev->wiphy.max_num_csa_counters &&
6435 (params.n_counter_offsets_beacon >
6436 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006437 return -EINVAL;
6438
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006439 params.counter_offsets_beacon =
6440 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6441
6442 /* sanity checks - counters should fit and be the same */
6443 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6444 u16 offset = params.counter_offsets_beacon[i];
6445
6446 if (offset >= params.beacon_csa.tail_len)
6447 return -EINVAL;
6448
6449 if (params.beacon_csa.tail[offset] != params.count)
6450 return -EINVAL;
6451 }
6452
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006453 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006454 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6455 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006456 return -EINVAL;
6457
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006458 params.n_counter_offsets_presp = len / sizeof(u16);
6459 if (rdev->wiphy.max_num_csa_counters &&
6460 (params.n_counter_offsets_beacon >
6461 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006462 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006463
6464 params.counter_offsets_presp =
6465 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6466
6467 /* sanity checks - counters should fit and be the same */
6468 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6469 u16 offset = params.counter_offsets_presp[i];
6470
6471 if (offset >= params.beacon_csa.probe_resp_len)
6472 return -EINVAL;
6473
6474 if (params.beacon_csa.probe_resp[offset] !=
6475 params.count)
6476 return -EINVAL;
6477 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006478 }
6479
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006480skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006481 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6482 if (err)
6483 return err;
6484
Ilan Peer174e0cd2014-02-23 09:13:01 +02006485 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &params.chandef,
6486 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006487 return -EINVAL;
6488
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006489 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6490 &params.chandef,
6491 wdev->iftype);
6492 if (err < 0)
6493 return err;
6494
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006495 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006496 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006497
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006498 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6499 params.block_tx = true;
6500
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006501 wdev_lock(wdev);
6502 err = rdev_channel_switch(rdev, dev, &params);
6503 wdev_unlock(wdev);
6504
6505 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006506}
6507
Johannes Berg9720bb32011-06-21 09:45:33 +02006508static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6509 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006510 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006511 struct wireless_dev *wdev,
6512 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006513{
Johannes Berg48ab9052009-07-10 18:42:31 +02006514 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006515 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006516 void *hdr;
6517 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006518
6519 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006520
Eric W. Biederman15e47302012-09-07 20:12:54 +00006521 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006522 NL80211_CMD_NEW_SCAN_RESULTS);
6523 if (!hdr)
6524 return -1;
6525
Johannes Berg9720bb32011-06-21 09:45:33 +02006526 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6527
Johannes Berg97990a02013-04-19 01:02:55 +02006528 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6529 goto nla_put_failure;
6530 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006531 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6532 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006533 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6534 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006535
6536 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6537 if (!bss)
6538 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006539 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006540 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006541 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006542
6543 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006544 /* indicate whether we have probe response data or not */
6545 if (rcu_access_pointer(res->proberesp_ies) &&
6546 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6547 goto fail_unlock_rcu;
6548
6549 /* this pointer prefers to be pointed to probe response data
6550 * but is always valid
6551 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006552 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006553 if (ies) {
6554 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6555 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006556 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6557 ies->len, ies->data))
6558 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006559 }
Johannes Berg0e227082014-08-12 20:34:30 +02006560
6561 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006562 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006563 if (ies && ies->from_beacon) {
6564 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006565 goto fail_unlock_rcu;
6566 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6567 ies->len, ies->data))
6568 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006569 }
6570 rcu_read_unlock();
6571
David S. Miller9360ffd2012-03-29 04:41:26 -04006572 if (res->beacon_interval &&
6573 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6574 goto nla_put_failure;
6575 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6576 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006577 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006578 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6579 jiffies_to_msecs(jiffies - intbss->ts)))
6580 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006581
Johannes Berg77965c92009-02-18 18:45:06 +01006582 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006583 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006584 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6585 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006586 break;
6587 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006588 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6589 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006590 break;
6591 default:
6592 break;
6593 }
6594
Johannes Berg48ab9052009-07-10 18:42:31 +02006595 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006596 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006597 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006598 if (intbss == wdev->current_bss &&
6599 nla_put_u32(msg, NL80211_BSS_STATUS,
6600 NL80211_BSS_STATUS_ASSOCIATED))
6601 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006602 break;
6603 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006604 if (intbss == wdev->current_bss &&
6605 nla_put_u32(msg, NL80211_BSS_STATUS,
6606 NL80211_BSS_STATUS_IBSS_JOINED))
6607 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006608 break;
6609 default:
6610 break;
6611 }
6612
Johannes Berg2a519312009-02-10 21:25:55 +01006613 nla_nest_end(msg, bss);
6614
Johannes Berg053c0952015-01-16 22:09:00 +01006615 genlmsg_end(msg, hdr);
6616 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006617
Johannes Berg8cef2c92013-02-05 16:54:31 +01006618 fail_unlock_rcu:
6619 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006620 nla_put_failure:
6621 genlmsg_cancel(msg, hdr);
6622 return -EMSGSIZE;
6623}
6624
Johannes Berg97990a02013-04-19 01:02:55 +02006625static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006626{
Johannes Berg48ab9052009-07-10 18:42:31 +02006627 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006628 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006629 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006630 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006631 int err;
6632
Johannes Berg97990a02013-04-19 01:02:55 +02006633 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006634 if (err)
6635 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006636
Johannes Berg48ab9052009-07-10 18:42:31 +02006637 wdev_lock(wdev);
6638 spin_lock_bh(&rdev->bss_lock);
6639 cfg80211_bss_expire(rdev);
6640
Johannes Berg9720bb32011-06-21 09:45:33 +02006641 cb->seq = rdev->bss_generation;
6642
Johannes Berg48ab9052009-07-10 18:42:31 +02006643 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006644 if (++idx <= start)
6645 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006646 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006647 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006648 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006649 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006650 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006651 }
6652 }
6653
Johannes Berg48ab9052009-07-10 18:42:31 +02006654 spin_unlock_bh(&rdev->bss_lock);
6655 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006656
Johannes Berg97990a02013-04-19 01:02:55 +02006657 cb->args[2] = idx;
6658 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006659
Johannes Berg67748892010-10-04 21:14:06 +02006660 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006661}
6662
Eric W. Biederman15e47302012-09-07 20:12:54 +00006663static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006664 int flags, struct net_device *dev,
6665 bool allow_radio_stats,
6666 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006667{
6668 void *hdr;
6669 struct nlattr *infoattr;
6670
Johannes Berg11f78ac2014-11-14 16:43:50 +01006671 /* skip radio stats if userspace didn't request them */
6672 if (!survey->channel && !allow_radio_stats)
6673 return 0;
6674
Eric W. Biederman15e47302012-09-07 20:12:54 +00006675 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006676 NL80211_CMD_NEW_SURVEY_RESULTS);
6677 if (!hdr)
6678 return -ENOMEM;
6679
David S. Miller9360ffd2012-03-29 04:41:26 -04006680 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6681 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006682
6683 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6684 if (!infoattr)
6685 goto nla_put_failure;
6686
Johannes Berg11f78ac2014-11-14 16:43:50 +01006687 if (survey->channel &&
6688 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006689 survey->channel->center_freq))
6690 goto nla_put_failure;
6691
6692 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6693 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6694 goto nla_put_failure;
6695 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6696 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6697 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006698 if ((survey->filled & SURVEY_INFO_TIME) &&
6699 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6700 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006701 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006702 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6703 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6704 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006705 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006706 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6707 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6708 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006709 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006710 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6711 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6712 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006713 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006714 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6715 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6716 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006717 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006718 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6719 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6720 survey->time_scan))
6721 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006722
6723 nla_nest_end(msg, infoattr);
6724
Johannes Berg053c0952015-01-16 22:09:00 +01006725 genlmsg_end(msg, hdr);
6726 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006727
6728 nla_put_failure:
6729 genlmsg_cancel(msg, hdr);
6730 return -EMSGSIZE;
6731}
6732
Johannes Berg11f78ac2014-11-14 16:43:50 +01006733static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006734{
6735 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006736 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006737 struct wireless_dev *wdev;
6738 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006739 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006740 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006741
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006742 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006743 if (res)
6744 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006745
Johannes Berg11f78ac2014-11-14 16:43:50 +01006746 /* prepare_wdev_dump parsed the attributes */
6747 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6748
Johannes Berg97990a02013-04-19 01:02:55 +02006749 if (!wdev->netdev) {
6750 res = -EINVAL;
6751 goto out_err;
6752 }
6753
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006754 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006755 res = -EOPNOTSUPP;
6756 goto out_err;
6757 }
6758
6759 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006760 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006761 if (res == -ENOENT)
6762 break;
6763 if (res)
6764 goto out_err;
6765
Johannes Berg11f78ac2014-11-14 16:43:50 +01006766 /* don't send disabled channels, but do send non-channel data */
6767 if (survey.channel &&
6768 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006769 survey_idx++;
6770 continue;
6771 }
6772
Holger Schurig61fa7132009-11-11 12:25:40 +01006773 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006774 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006775 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006776 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006777 goto out;
6778 survey_idx++;
6779 }
6780
6781 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006782 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006783 res = skb->len;
6784 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006785 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006786 return res;
6787}
6788
Samuel Ortizb23aa672009-07-01 21:26:54 +02006789static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6790{
6791 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6792 NL80211_WPA_VERSION_2));
6793}
6794
Jouni Malinen636a5d32009-03-19 13:39:22 +02006795static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6796{
Johannes Berg4c476992010-10-04 21:36:35 +02006797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6798 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006799 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006800 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6801 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006802 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006803 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006804 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006805
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006806 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6807 return -EINVAL;
6808
6809 if (!info->attrs[NL80211_ATTR_MAC])
6810 return -EINVAL;
6811
Jouni Malinen17780922009-03-27 20:52:47 +02006812 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6813 return -EINVAL;
6814
Johannes Berg19957bb2009-07-02 17:20:43 +02006815 if (!info->attrs[NL80211_ATTR_SSID])
6816 return -EINVAL;
6817
6818 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6819 return -EINVAL;
6820
Johannes Bergfffd0932009-07-08 14:22:54 +02006821 err = nl80211_parse_key(info, &key);
6822 if (err)
6823 return err;
6824
6825 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006826 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6827 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006828 if (!key.p.key || !key.p.key_len)
6829 return -EINVAL;
6830 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6831 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6832 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6833 key.p.key_len != WLAN_KEY_LEN_WEP104))
6834 return -EINVAL;
6835 if (key.idx > 4)
6836 return -EINVAL;
6837 } else {
6838 key.p.key_len = 0;
6839 key.p.key = NULL;
6840 }
6841
Johannes Bergafea0b72010-08-10 09:46:42 +02006842 if (key.idx >= 0) {
6843 int i;
6844 bool ok = false;
6845 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6846 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6847 ok = true;
6848 break;
6849 }
6850 }
Johannes Berg4c476992010-10-04 21:36:35 +02006851 if (!ok)
6852 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006853 }
6854
Johannes Berg4c476992010-10-04 21:36:35 +02006855 if (!rdev->ops->auth)
6856 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006857
Johannes Berg074ac8d2010-09-16 14:58:22 +02006858 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006859 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6860 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006861
Johannes Berg19957bb2009-07-02 17:20:43 +02006862 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006863 chan = nl80211_get_valid_chan(&rdev->wiphy,
6864 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6865 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006866 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006867
Johannes Berg19957bb2009-07-02 17:20:43 +02006868 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6869 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6870
6871 if (info->attrs[NL80211_ATTR_IE]) {
6872 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6873 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6874 }
6875
6876 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006877 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006878 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006879
Jouni Malinene39e5b52012-09-30 19:29:39 +03006880 if (auth_type == NL80211_AUTHTYPE_SAE &&
6881 !info->attrs[NL80211_ATTR_SAE_DATA])
6882 return -EINVAL;
6883
6884 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6885 if (auth_type != NL80211_AUTHTYPE_SAE)
6886 return -EINVAL;
6887 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6888 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6889 /* need to include at least Auth Transaction and Status Code */
6890 if (sae_data_len < 4)
6891 return -EINVAL;
6892 }
6893
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006894 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6895
Johannes Berg95de8172012-01-20 13:55:25 +01006896 /*
6897 * Since we no longer track auth state, ignore
6898 * requests to only change local state.
6899 */
6900 if (local_state_change)
6901 return 0;
6902
Johannes Berg91bf9b22013-05-15 17:44:01 +02006903 wdev_lock(dev->ieee80211_ptr);
6904 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6905 ssid, ssid_len, ie, ie_len,
6906 key.p.key, key.p.key_len, key.idx,
6907 sae_data, sae_data_len);
6908 wdev_unlock(dev->ieee80211_ptr);
6909 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006910}
6911
Johannes Bergc0692b82010-08-27 14:26:53 +03006912static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6913 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006914 struct cfg80211_crypto_settings *settings,
6915 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006916{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006917 memset(settings, 0, sizeof(*settings));
6918
Samuel Ortizb23aa672009-07-01 21:26:54 +02006919 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6920
Johannes Bergc0692b82010-08-27 14:26:53 +03006921 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6922 u16 proto;
6923 proto = nla_get_u16(
6924 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6925 settings->control_port_ethertype = cpu_to_be16(proto);
6926 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6927 proto != ETH_P_PAE)
6928 return -EINVAL;
6929 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6930 settings->control_port_no_encrypt = true;
6931 } else
6932 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6933
Samuel Ortizb23aa672009-07-01 21:26:54 +02006934 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6935 void *data;
6936 int len, i;
6937
6938 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6939 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6940 settings->n_ciphers_pairwise = len / sizeof(u32);
6941
6942 if (len % sizeof(u32))
6943 return -EINVAL;
6944
Johannes Berg3dc27d22009-07-02 21:36:37 +02006945 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006946 return -EINVAL;
6947
6948 memcpy(settings->ciphers_pairwise, data, len);
6949
6950 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006951 if (!cfg80211_supported_cipher_suite(
6952 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006953 settings->ciphers_pairwise[i]))
6954 return -EINVAL;
6955 }
6956
6957 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6958 settings->cipher_group =
6959 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006960 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6961 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006962 return -EINVAL;
6963 }
6964
6965 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6966 settings->wpa_versions =
6967 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6968 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6969 return -EINVAL;
6970 }
6971
6972 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6973 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006974 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006975
6976 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6977 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6978 settings->n_akm_suites = len / sizeof(u32);
6979
6980 if (len % sizeof(u32))
6981 return -EINVAL;
6982
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006983 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6984 return -EINVAL;
6985
Samuel Ortizb23aa672009-07-01 21:26:54 +02006986 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006987 }
6988
6989 return 0;
6990}
6991
Jouni Malinen636a5d32009-03-19 13:39:22 +02006992static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
6993{
Johannes Berg4c476992010-10-04 21:36:35 +02006994 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6995 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02006996 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01006997 struct cfg80211_assoc_request req = {};
6998 const u8 *bssid, *ssid;
6999 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007000
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007001 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7002 return -EINVAL;
7003
7004 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007005 !info->attrs[NL80211_ATTR_SSID] ||
7006 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007007 return -EINVAL;
7008
Johannes Berg4c476992010-10-04 21:36:35 +02007009 if (!rdev->ops->assoc)
7010 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007011
Johannes Berg074ac8d2010-09-16 14:58:22 +02007012 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007013 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7014 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007015
Johannes Berg19957bb2009-07-02 17:20:43 +02007016 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007017
Jouni Malinen664834d2014-01-15 00:01:44 +02007018 chan = nl80211_get_valid_chan(&rdev->wiphy,
7019 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7020 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007021 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007022
Johannes Berg19957bb2009-07-02 17:20:43 +02007023 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7024 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007025
7026 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007027 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7028 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007029 }
7030
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007031 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007032 enum nl80211_mfp mfp =
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007033 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007034 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007035 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007036 else if (mfp != NL80211_MFP_NO)
7037 return -EINVAL;
Jouni Malinendc6382ce2009-05-06 22:09:37 +03007038 }
7039
Johannes Berg3e5d7642009-07-07 14:37:26 +02007040 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007041 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007042
Ben Greear7e7c8922011-11-18 11:31:59 -08007043 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007044 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007045
7046 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007047 memcpy(&req.ht_capa_mask,
7048 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7049 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007050
7051 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007052 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007053 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007054 memcpy(&req.ht_capa,
7055 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7056 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007057 }
7058
Johannes Bergee2aca32013-02-21 17:36:01 +01007059 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007060 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007061
7062 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007063 memcpy(&req.vht_capa_mask,
7064 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7065 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007066
7067 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007068 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007069 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007070 memcpy(&req.vht_capa,
7071 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7072 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007073 }
7074
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007075 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7076 if (!(rdev->wiphy.features &
7077 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7078 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7079 return -EINVAL;
7080 req.flags |= ASSOC_REQ_USE_RRM;
7081 }
7082
Johannes Bergf62fab72013-02-21 20:09:09 +01007083 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007084 if (!err) {
7085 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007086 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7087 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007088 wdev_unlock(dev->ieee80211_ptr);
7089 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007090
Jouni Malinen636a5d32009-03-19 13:39:22 +02007091 return err;
7092}
7093
7094static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7095{
Johannes Berg4c476992010-10-04 21:36:35 +02007096 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7097 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007098 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007099 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007100 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007101 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007102
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007103 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7104 return -EINVAL;
7105
7106 if (!info->attrs[NL80211_ATTR_MAC])
7107 return -EINVAL;
7108
7109 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7110 return -EINVAL;
7111
Johannes Berg4c476992010-10-04 21:36:35 +02007112 if (!rdev->ops->deauth)
7113 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007114
Johannes Berg074ac8d2010-09-16 14:58:22 +02007115 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007116 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7117 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007118
Johannes Berg19957bb2009-07-02 17:20:43 +02007119 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007120
Johannes Berg19957bb2009-07-02 17:20:43 +02007121 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7122 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007123 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007124 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007125 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007126
7127 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007128 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7129 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007130 }
7131
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007132 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7133
Johannes Berg91bf9b22013-05-15 17:44:01 +02007134 wdev_lock(dev->ieee80211_ptr);
7135 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7136 local_state_change);
7137 wdev_unlock(dev->ieee80211_ptr);
7138 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007139}
7140
7141static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7142{
Johannes Berg4c476992010-10-04 21:36:35 +02007143 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7144 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007145 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007146 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007147 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007148 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007149
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007150 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7151 return -EINVAL;
7152
7153 if (!info->attrs[NL80211_ATTR_MAC])
7154 return -EINVAL;
7155
7156 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7157 return -EINVAL;
7158
Johannes Berg4c476992010-10-04 21:36:35 +02007159 if (!rdev->ops->disassoc)
7160 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007161
Johannes Berg074ac8d2010-09-16 14:58:22 +02007162 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007163 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7164 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007165
Johannes Berg19957bb2009-07-02 17:20:43 +02007166 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007167
Johannes Berg19957bb2009-07-02 17:20:43 +02007168 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7169 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007170 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007171 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007172 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007173
7174 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007175 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7176 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007177 }
7178
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007179 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7180
Johannes Berg91bf9b22013-05-15 17:44:01 +02007181 wdev_lock(dev->ieee80211_ptr);
7182 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7183 local_state_change);
7184 wdev_unlock(dev->ieee80211_ptr);
7185 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007186}
7187
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007188static bool
7189nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7190 int mcast_rate[IEEE80211_NUM_BANDS],
7191 int rateval)
7192{
7193 struct wiphy *wiphy = &rdev->wiphy;
7194 bool found = false;
7195 int band, i;
7196
7197 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7198 struct ieee80211_supported_band *sband;
7199
7200 sband = wiphy->bands[band];
7201 if (!sband)
7202 continue;
7203
7204 for (i = 0; i < sband->n_bitrates; i++) {
7205 if (sband->bitrates[i].bitrate == rateval) {
7206 mcast_rate[band] = i + 1;
7207 found = true;
7208 break;
7209 }
7210 }
7211 }
7212
7213 return found;
7214}
7215
Johannes Berg04a773a2009-04-19 21:24:32 +02007216static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7217{
Johannes Berg4c476992010-10-04 21:36:35 +02007218 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7219 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007220 struct cfg80211_ibss_params ibss;
7221 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007222 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007223 int err;
7224
Johannes Berg8e30bc52009-04-22 17:45:38 +02007225 memset(&ibss, 0, sizeof(ibss));
7226
Johannes Berg04a773a2009-04-19 21:24:32 +02007227 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7228 return -EINVAL;
7229
Johannes Berg683b6d32012-11-08 21:25:48 +01007230 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007231 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7232 return -EINVAL;
7233
Johannes Berg8e30bc52009-04-22 17:45:38 +02007234 ibss.beacon_interval = 100;
7235
7236 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7237 ibss.beacon_interval =
7238 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7239 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7240 return -EINVAL;
7241 }
7242
Johannes Berg4c476992010-10-04 21:36:35 +02007243 if (!rdev->ops->join_ibss)
7244 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007245
Johannes Berg4c476992010-10-04 21:36:35 +02007246 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7247 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007248
Johannes Berg79c97e92009-07-07 03:56:12 +02007249 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007250
Johannes Berg39193492011-09-16 13:45:25 +02007251 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007252 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007253
7254 if (!is_valid_ether_addr(ibss.bssid))
7255 return -EINVAL;
7256 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007257 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7258 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7259
7260 if (info->attrs[NL80211_ATTR_IE]) {
7261 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7262 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7263 }
7264
Johannes Berg683b6d32012-11-08 21:25:48 +01007265 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7266 if (err)
7267 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007268
Ilan Peer174e0cd2014-02-23 09:13:01 +02007269 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7270 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007271 return -EINVAL;
7272
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007273 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007274 case NL80211_CHAN_WIDTH_5:
7275 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007276 case NL80211_CHAN_WIDTH_20_NOHT:
7277 break;
7278 case NL80211_CHAN_WIDTH_20:
7279 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007280 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7281 return -EINVAL;
7282 break;
7283 case NL80211_CHAN_WIDTH_80:
7284 case NL80211_CHAN_WIDTH_80P80:
7285 case NL80211_CHAN_WIDTH_160:
7286 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7287 return -EINVAL;
7288 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7289 NL80211_EXT_FEATURE_VHT_IBSS))
7290 return -EINVAL;
7291 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007292 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007293 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007294 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007295
Johannes Berg04a773a2009-04-19 21:24:32 +02007296 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007297 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007298
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007299 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7300 u8 *rates =
7301 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7302 int n_rates =
7303 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7304 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007305 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007306
Johannes Berg34850ab2011-07-18 18:08:35 +02007307 err = ieee80211_get_ratemask(sband, rates, n_rates,
7308 &ibss.basic_rates);
7309 if (err)
7310 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007311 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007312
Simon Wunderlich803768f2013-06-28 10:39:58 +02007313 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7314 memcpy(&ibss.ht_capa_mask,
7315 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7316 sizeof(ibss.ht_capa_mask));
7317
7318 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7319 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7320 return -EINVAL;
7321 memcpy(&ibss.ht_capa,
7322 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7323 sizeof(ibss.ht_capa));
7324 }
7325
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007326 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7327 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7328 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7329 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007330
Johannes Berg4c476992010-10-04 21:36:35 +02007331 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307332 bool no_ht = false;
7333
Johannes Berg4c476992010-10-04 21:36:35 +02007334 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307335 info->attrs[NL80211_ATTR_KEYS],
7336 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007337 if (IS_ERR(connkeys))
7338 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307339
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007340 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7341 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307342 kfree(connkeys);
7343 return -EINVAL;
7344 }
Johannes Berg4c476992010-10-04 21:36:35 +02007345 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007346
Antonio Quartulli267335d2012-01-31 20:25:47 +01007347 ibss.control_port =
7348 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7349
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007350 ibss.userspace_handles_dfs =
7351 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7352
Johannes Berg4c476992010-10-04 21:36:35 +02007353 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007354 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007355 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007356 return err;
7357}
7358
7359static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7360{
Johannes Berg4c476992010-10-04 21:36:35 +02007361 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7362 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007363
Johannes Berg4c476992010-10-04 21:36:35 +02007364 if (!rdev->ops->leave_ibss)
7365 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007366
Johannes Berg4c476992010-10-04 21:36:35 +02007367 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7368 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007369
Johannes Berg4c476992010-10-04 21:36:35 +02007370 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007371}
7372
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007373static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7374{
7375 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7376 struct net_device *dev = info->user_ptr[1];
7377 int mcast_rate[IEEE80211_NUM_BANDS];
7378 u32 nla_rate;
7379 int err;
7380
7381 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7382 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7383 return -EOPNOTSUPP;
7384
7385 if (!rdev->ops->set_mcast_rate)
7386 return -EOPNOTSUPP;
7387
7388 memset(mcast_rate, 0, sizeof(mcast_rate));
7389
7390 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7391 return -EINVAL;
7392
7393 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7394 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7395 return -EINVAL;
7396
7397 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7398
7399 return err;
7400}
7401
Johannes Bergad7e7182013-11-13 13:37:47 +01007402static struct sk_buff *
7403__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007404 struct wireless_dev *wdev, int approxlen,
7405 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007406 enum nl80211_attrs attr,
7407 const struct nl80211_vendor_cmd_info *info,
7408 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007409{
7410 struct sk_buff *skb;
7411 void *hdr;
7412 struct nlattr *data;
7413
7414 skb = nlmsg_new(approxlen + 100, gfp);
7415 if (!skb)
7416 return NULL;
7417
7418 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7419 if (!hdr) {
7420 kfree_skb(skb);
7421 return NULL;
7422 }
7423
7424 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7425 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007426
7427 if (info) {
7428 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7429 info->vendor_id))
7430 goto nla_put_failure;
7431 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7432 info->subcmd))
7433 goto nla_put_failure;
7434 }
7435
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007436 if (wdev) {
7437 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7438 wdev_id(wdev)))
7439 goto nla_put_failure;
7440 if (wdev->netdev &&
7441 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7442 wdev->netdev->ifindex))
7443 goto nla_put_failure;
7444 }
7445
Johannes Bergad7e7182013-11-13 13:37:47 +01007446 data = nla_nest_start(skb, attr);
7447
7448 ((void **)skb->cb)[0] = rdev;
7449 ((void **)skb->cb)[1] = hdr;
7450 ((void **)skb->cb)[2] = data;
7451
7452 return skb;
7453
7454 nla_put_failure:
7455 kfree_skb(skb);
7456 return NULL;
7457}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007458
Johannes Berge03ad6e2014-01-01 17:22:30 +01007459struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007460 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007461 enum nl80211_commands cmd,
7462 enum nl80211_attrs attr,
7463 int vendor_event_idx,
7464 int approxlen, gfp_t gfp)
7465{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007466 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007467 const struct nl80211_vendor_cmd_info *info;
7468
7469 switch (cmd) {
7470 case NL80211_CMD_TESTMODE:
7471 if (WARN_ON(vendor_event_idx != -1))
7472 return NULL;
7473 info = NULL;
7474 break;
7475 case NL80211_CMD_VENDOR:
7476 if (WARN_ON(vendor_event_idx < 0 ||
7477 vendor_event_idx >= wiphy->n_vendor_events))
7478 return NULL;
7479 info = &wiphy->vendor_events[vendor_event_idx];
7480 break;
7481 default:
7482 WARN_ON(1);
7483 return NULL;
7484 }
7485
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007486 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007487 cmd, attr, info, gfp);
7488}
7489EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7490
7491void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7492{
7493 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7494 void *hdr = ((void **)skb->cb)[1];
7495 struct nlattr *data = ((void **)skb->cb)[2];
7496 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7497
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007498 /* clear CB data for netlink core to own from now on */
7499 memset(skb->cb, 0, sizeof(skb->cb));
7500
Johannes Berge03ad6e2014-01-01 17:22:30 +01007501 nla_nest_end(skb, data);
7502 genlmsg_end(skb, hdr);
7503
7504 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7505 mcgrp = NL80211_MCGRP_VENDOR;
7506
7507 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7508 mcgrp, gfp);
7509}
7510EXPORT_SYMBOL(__cfg80211_send_event_skb);
7511
Johannes Bergaff89a92009-07-01 21:26:51 +02007512#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007513static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7514{
Johannes Berg4c476992010-10-04 21:36:35 +02007515 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007516 struct wireless_dev *wdev =
7517 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007518 int err;
7519
David Spinadelfc73f112013-07-31 18:04:15 +03007520 if (!rdev->ops->testmode_cmd)
7521 return -EOPNOTSUPP;
7522
7523 if (IS_ERR(wdev)) {
7524 err = PTR_ERR(wdev);
7525 if (err != -EINVAL)
7526 return err;
7527 wdev = NULL;
7528 } else if (wdev->wiphy != &rdev->wiphy) {
7529 return -EINVAL;
7530 }
7531
Johannes Bergaff89a92009-07-01 21:26:51 +02007532 if (!info->attrs[NL80211_ATTR_TESTDATA])
7533 return -EINVAL;
7534
Johannes Bergad7e7182013-11-13 13:37:47 +01007535 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007536 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007537 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7538 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007539 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007540
Johannes Bergaff89a92009-07-01 21:26:51 +02007541 return err;
7542}
7543
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007544static int nl80211_testmode_dump(struct sk_buff *skb,
7545 struct netlink_callback *cb)
7546{
Johannes Berg00918d32011-12-13 17:22:05 +01007547 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007548 int err;
7549 long phy_idx;
7550 void *data = NULL;
7551 int data_len = 0;
7552
Johannes Berg5fe231e2013-05-08 21:45:15 +02007553 rtnl_lock();
7554
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007555 if (cb->args[0]) {
7556 /*
7557 * 0 is a valid index, but not valid for args[0],
7558 * so we need to offset by 1.
7559 */
7560 phy_idx = cb->args[0] - 1;
7561 } else {
7562 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7563 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7564 nl80211_policy);
7565 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007566 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007567
Johannes Berg2bd7e352012-06-15 14:23:16 +02007568 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7569 nl80211_fam.attrbuf);
7570 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007571 err = PTR_ERR(rdev);
7572 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007573 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007574 phy_idx = rdev->wiphy_idx;
7575 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007576
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007577 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7578 cb->args[1] =
7579 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7580 }
7581
7582 if (cb->args[1]) {
7583 data = nla_data((void *)cb->args[1]);
7584 data_len = nla_len((void *)cb->args[1]);
7585 }
7586
Johannes Berg00918d32011-12-13 17:22:05 +01007587 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7588 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007589 err = -ENOENT;
7590 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007591 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007592
Johannes Berg00918d32011-12-13 17:22:05 +01007593 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007594 err = -EOPNOTSUPP;
7595 goto out_err;
7596 }
7597
7598 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007599 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007600 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7601 NL80211_CMD_TESTMODE);
7602 struct nlattr *tmdata;
7603
Dan Carpentercb35fba2013-08-14 14:50:01 +03007604 if (!hdr)
7605 break;
7606
David S. Miller9360ffd2012-03-29 04:41:26 -04007607 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007608 genlmsg_cancel(skb, hdr);
7609 break;
7610 }
7611
7612 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7613 if (!tmdata) {
7614 genlmsg_cancel(skb, hdr);
7615 break;
7616 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007617 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007618 nla_nest_end(skb, tmdata);
7619
7620 if (err == -ENOBUFS || err == -ENOENT) {
7621 genlmsg_cancel(skb, hdr);
7622 break;
7623 } else if (err) {
7624 genlmsg_cancel(skb, hdr);
7625 goto out_err;
7626 }
7627
7628 genlmsg_end(skb, hdr);
7629 }
7630
7631 err = skb->len;
7632 /* see above */
7633 cb->args[0] = phy_idx + 1;
7634 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007635 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007636 return err;
7637}
Johannes Bergaff89a92009-07-01 21:26:51 +02007638#endif
7639
Samuel Ortizb23aa672009-07-01 21:26:54 +02007640static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7641{
Johannes Berg4c476992010-10-04 21:36:35 +02007642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7643 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007644 struct cfg80211_connect_params connect;
7645 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007646 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007647 int err;
7648
7649 memset(&connect, 0, sizeof(connect));
7650
7651 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7652 return -EINVAL;
7653
7654 if (!info->attrs[NL80211_ATTR_SSID] ||
7655 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7656 return -EINVAL;
7657
7658 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7659 connect.auth_type =
7660 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007661 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7662 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007663 return -EINVAL;
7664 } else
7665 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7666
7667 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7668
Johannes Bergc0692b82010-08-27 14:26:53 +03007669 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007670 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007671 if (err)
7672 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007673
Johannes Berg074ac8d2010-09-16 14:58:22 +02007674 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007675 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7676 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007677
Johannes Berg79c97e92009-07-07 03:56:12 +02007678 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007679
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307680 connect.bg_scan_period = -1;
7681 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7682 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7683 connect.bg_scan_period =
7684 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7685 }
7686
Samuel Ortizb23aa672009-07-01 21:26:54 +02007687 if (info->attrs[NL80211_ATTR_MAC])
7688 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007689 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7690 connect.bssid_hint =
7691 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007692 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7693 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7694
7695 if (info->attrs[NL80211_ATTR_IE]) {
7696 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7697 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7698 }
7699
Jouni Malinencee00a92013-01-15 17:15:57 +02007700 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7701 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7702 if (connect.mfp != NL80211_MFP_REQUIRED &&
7703 connect.mfp != NL80211_MFP_NO)
7704 return -EINVAL;
7705 } else {
7706 connect.mfp = NL80211_MFP_NO;
7707 }
7708
Samuel Ortizb23aa672009-07-01 21:26:54 +02007709 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007710 connect.channel = nl80211_get_valid_chan(
7711 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7712 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007713 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007714 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007715 connect.channel_hint = nl80211_get_valid_chan(
7716 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7717 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007718 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007719 }
7720
Johannes Bergfffd0932009-07-08 14:22:54 +02007721 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7722 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307723 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007724 if (IS_ERR(connkeys))
7725 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007726 }
7727
Ben Greear7e7c8922011-11-18 11:31:59 -08007728 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7729 connect.flags |= ASSOC_REQ_DISABLE_HT;
7730
7731 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7732 memcpy(&connect.ht_capa_mask,
7733 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7734 sizeof(connect.ht_capa_mask));
7735
7736 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007737 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007738 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007739 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007740 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007741 memcpy(&connect.ht_capa,
7742 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7743 sizeof(connect.ht_capa));
7744 }
7745
Johannes Bergee2aca32013-02-21 17:36:01 +01007746 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7747 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7748
7749 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7750 memcpy(&connect.vht_capa_mask,
7751 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7752 sizeof(connect.vht_capa_mask));
7753
7754 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7755 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007756 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007757 return -EINVAL;
7758 }
7759 memcpy(&connect.vht_capa,
7760 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7761 sizeof(connect.vht_capa));
7762 }
7763
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007764 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7765 if (!(rdev->wiphy.features &
7766 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7767 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7768 return -EINVAL;
7769 connect.flags |= ASSOC_REQ_USE_RRM;
7770 }
7771
Johannes Berg83739b02013-05-15 17:44:01 +02007772 wdev_lock(dev->ieee80211_ptr);
7773 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7774 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007775 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007776 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007777 return err;
7778}
7779
7780static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7781{
Johannes Berg4c476992010-10-04 21:36:35 +02007782 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7783 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007784 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007785 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007786
7787 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7788 reason = WLAN_REASON_DEAUTH_LEAVING;
7789 else
7790 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7791
7792 if (reason == 0)
7793 return -EINVAL;
7794
Johannes Berg074ac8d2010-09-16 14:58:22 +02007795 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007796 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7797 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007798
Johannes Berg83739b02013-05-15 17:44:01 +02007799 wdev_lock(dev->ieee80211_ptr);
7800 ret = cfg80211_disconnect(rdev, dev, reason, true);
7801 wdev_unlock(dev->ieee80211_ptr);
7802 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007803}
7804
Johannes Berg463d0182009-07-14 00:33:35 +02007805static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7806{
Johannes Berg4c476992010-10-04 21:36:35 +02007807 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007808 struct net *net;
7809 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007810
Vadim Kochan4b681c82015-01-12 16:34:05 +02007811 if (info->attrs[NL80211_ATTR_PID]) {
7812 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7813
7814 net = get_net_ns_by_pid(pid);
7815 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7816 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7817
7818 net = get_net_ns_by_fd(fd);
7819 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007820 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007821 }
Johannes Berg463d0182009-07-14 00:33:35 +02007822
Johannes Berg4c476992010-10-04 21:36:35 +02007823 if (IS_ERR(net))
7824 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007825
7826 err = 0;
7827
7828 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007829 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7830 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007831
Johannes Berg463d0182009-07-14 00:33:35 +02007832 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007833 return err;
7834}
7835
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007836static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7837{
Johannes Berg4c476992010-10-04 21:36:35 +02007838 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007839 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7840 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007841 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007842 struct cfg80211_pmksa pmksa;
7843
7844 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7845
7846 if (!info->attrs[NL80211_ATTR_MAC])
7847 return -EINVAL;
7848
7849 if (!info->attrs[NL80211_ATTR_PMKID])
7850 return -EINVAL;
7851
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007852 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7853 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7854
Johannes Berg074ac8d2010-09-16 14:58:22 +02007855 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007856 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7857 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007858
7859 switch (info->genlhdr->cmd) {
7860 case NL80211_CMD_SET_PMKSA:
7861 rdev_ops = rdev->ops->set_pmksa;
7862 break;
7863 case NL80211_CMD_DEL_PMKSA:
7864 rdev_ops = rdev->ops->del_pmksa;
7865 break;
7866 default:
7867 WARN_ON(1);
7868 break;
7869 }
7870
Johannes Berg4c476992010-10-04 21:36:35 +02007871 if (!rdev_ops)
7872 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007873
Johannes Berg4c476992010-10-04 21:36:35 +02007874 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007875}
7876
7877static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7878{
Johannes Berg4c476992010-10-04 21:36:35 +02007879 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7880 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007881
Johannes Berg074ac8d2010-09-16 14:58:22 +02007882 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007883 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7884 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007885
Johannes Berg4c476992010-10-04 21:36:35 +02007886 if (!rdev->ops->flush_pmksa)
7887 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007888
Hila Gonene35e4d22012-06-27 17:19:42 +03007889 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007890}
7891
Arik Nemtsov109086c2011-09-28 14:12:50 +03007892static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7893{
7894 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7895 struct net_device *dev = info->user_ptr[1];
7896 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307897 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007898 u16 status_code;
7899 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007900 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007901
7902 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7903 !rdev->ops->tdls_mgmt)
7904 return -EOPNOTSUPP;
7905
7906 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7907 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7908 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7909 !info->attrs[NL80211_ATTR_IE] ||
7910 !info->attrs[NL80211_ATTR_MAC])
7911 return -EINVAL;
7912
7913 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7914 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7915 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7916 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007917 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307918 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7919 peer_capability =
7920 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007921
Hila Gonene35e4d22012-06-27 17:19:42 +03007922 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307923 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007924 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007925 nla_data(info->attrs[NL80211_ATTR_IE]),
7926 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007927}
7928
7929static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7930{
7931 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7932 struct net_device *dev = info->user_ptr[1];
7933 enum nl80211_tdls_operation operation;
7934 u8 *peer;
7935
7936 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7937 !rdev->ops->tdls_oper)
7938 return -EOPNOTSUPP;
7939
7940 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7941 !info->attrs[NL80211_ATTR_MAC])
7942 return -EINVAL;
7943
7944 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7945 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7946
Hila Gonene35e4d22012-06-27 17:19:42 +03007947 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007948}
7949
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007950static int nl80211_remain_on_channel(struct sk_buff *skb,
7951 struct genl_info *info)
7952{
Johannes Berg4c476992010-10-04 21:36:35 +02007953 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007954 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007955 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007956 struct sk_buff *msg;
7957 void *hdr;
7958 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007959 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007960 int err;
7961
7962 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7963 !info->attrs[NL80211_ATTR_DURATION])
7964 return -EINVAL;
7965
7966 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7967
Johannes Berg7c4ef712011-11-18 15:33:48 +01007968 if (!rdev->ops->remain_on_channel ||
7969 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007970 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007971
Johannes Bergebf348f2012-06-01 12:50:54 +02007972 /*
7973 * We should be on that channel for at least a minimum amount of
7974 * time (10ms) but no longer than the driver supports.
7975 */
7976 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7977 duration > rdev->wiphy.max_remain_on_channel_duration)
7978 return -EINVAL;
7979
Johannes Berg683b6d32012-11-08 21:25:48 +01007980 err = nl80211_parse_chandef(rdev, info, &chandef);
7981 if (err)
7982 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007983
7984 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007985 if (!msg)
7986 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007987
Eric W. Biederman15e47302012-09-07 20:12:54 +00007988 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007989 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03007990 if (!hdr) {
7991 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007992 goto free_msg;
7993 }
7994
Johannes Berg683b6d32012-11-08 21:25:48 +01007995 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
7996 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007997
7998 if (err)
7999 goto free_msg;
8000
David S. Miller9360ffd2012-03-29 04:41:26 -04008001 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8002 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008003
8004 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008005
8006 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008007
8008 nla_put_failure:
8009 err = -ENOBUFS;
8010 free_msg:
8011 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008012 return err;
8013}
8014
8015static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8016 struct genl_info *info)
8017{
Johannes Berg4c476992010-10-04 21:36:35 +02008018 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008019 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008020 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008021
8022 if (!info->attrs[NL80211_ATTR_COOKIE])
8023 return -EINVAL;
8024
Johannes Berg4c476992010-10-04 21:36:35 +02008025 if (!rdev->ops->cancel_remain_on_channel)
8026 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008027
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008028 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8029
Hila Gonene35e4d22012-06-27 17:19:42 +03008030 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008031}
8032
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008033static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8034 u8 *rates, u8 rates_len)
8035{
8036 u8 i;
8037 u32 mask = 0;
8038
8039 for (i = 0; i < rates_len; i++) {
8040 int rate = (rates[i] & 0x7f) * 5;
8041 int ridx;
8042 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8043 struct ieee80211_rate *srate =
8044 &sband->bitrates[ridx];
8045 if (rate == srate->bitrate) {
8046 mask |= 1 << ridx;
8047 break;
8048 }
8049 }
8050 if (ridx == sband->n_bitrates)
8051 return 0; /* rate not found */
8052 }
8053
8054 return mask;
8055}
8056
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008057static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8058 u8 *rates, u8 rates_len,
8059 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8060{
8061 u8 i;
8062
8063 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8064
8065 for (i = 0; i < rates_len; i++) {
8066 int ridx, rbit;
8067
8068 ridx = rates[i] / 8;
8069 rbit = BIT(rates[i] % 8);
8070
8071 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008072 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008073 return false;
8074
8075 /* check availability */
8076 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8077 mcs[ridx] |= rbit;
8078 else
8079 return false;
8080 }
8081
8082 return true;
8083}
8084
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008085static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8086{
8087 u16 mcs_mask = 0;
8088
8089 switch (vht_mcs_map) {
8090 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8091 break;
8092 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8093 mcs_mask = 0x00FF;
8094 break;
8095 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8096 mcs_mask = 0x01FF;
8097 break;
8098 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8099 mcs_mask = 0x03FF;
8100 break;
8101 default:
8102 break;
8103 }
8104
8105 return mcs_mask;
8106}
8107
8108static void vht_build_mcs_mask(u16 vht_mcs_map,
8109 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8110{
8111 u8 nss;
8112
8113 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8114 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8115 vht_mcs_map >>= 2;
8116 }
8117}
8118
8119static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8120 struct nl80211_txrate_vht *txrate,
8121 u16 mcs[NL80211_VHT_NSS_MAX])
8122{
8123 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8124 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8125 u8 i;
8126
8127 if (!sband->vht_cap.vht_supported)
8128 return false;
8129
8130 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8131
8132 /* Build vht_mcs_mask from VHT capabilities */
8133 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8134
8135 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8136 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8137 mcs[i] = txrate->mcs[i];
8138 else
8139 return false;
8140 }
8141
8142 return true;
8143}
8144
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008145static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008146 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8147 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008148 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8149 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008150 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008151 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008152};
8153
8154static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8155 struct genl_info *info)
8156{
8157 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008158 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008159 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008160 int rem, i;
8161 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008162 struct nlattr *tx_rates;
8163 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008164 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008165
Johannes Berg4c476992010-10-04 21:36:35 +02008166 if (!rdev->ops->set_bitrate_mask)
8167 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008168
8169 memset(&mask, 0, sizeof(mask));
8170 /* Default to all rates enabled */
8171 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8172 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008173
8174 if (!sband)
8175 continue;
8176
8177 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008178 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008179 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008180 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008181
8182 if (!sband->vht_cap.vht_supported)
8183 continue;
8184
8185 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8186 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008187 }
8188
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008189 /* if no rates are given set it back to the defaults */
8190 if (!info->attrs[NL80211_ATTR_TX_RATES])
8191 goto out;
8192
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008193 /*
8194 * The nested attribute uses enum nl80211_band as the index. This maps
8195 * directly to the enum ieee80211_band values used in cfg80211.
8196 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008197 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008198 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008199 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008200 int err;
8201
Johannes Berg4c476992010-10-04 21:36:35 +02008202 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8203 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008204 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008205 if (sband == NULL)
8206 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008207 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8208 nla_len(tx_rates), nl80211_txattr_policy);
8209 if (err)
8210 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008211 if (tb[NL80211_TXRATE_LEGACY]) {
8212 mask.control[band].legacy = rateset_to_mask(
8213 sband,
8214 nla_data(tb[NL80211_TXRATE_LEGACY]),
8215 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308216 if ((mask.control[band].legacy == 0) &&
8217 nla_len(tb[NL80211_TXRATE_LEGACY]))
8218 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008219 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008220 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008221 if (!ht_rateset_to_mask(
8222 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008223 nla_data(tb[NL80211_TXRATE_HT]),
8224 nla_len(tb[NL80211_TXRATE_HT]),
8225 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008226 return -EINVAL;
8227 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008228 if (tb[NL80211_TXRATE_VHT]) {
8229 if (!vht_set_mcs_mask(
8230 sband,
8231 nla_data(tb[NL80211_TXRATE_VHT]),
8232 mask.control[band].vht_mcs))
8233 return -EINVAL;
8234 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008235 if (tb[NL80211_TXRATE_GI]) {
8236 mask.control[band].gi =
8237 nla_get_u8(tb[NL80211_TXRATE_GI]);
8238 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8239 return -EINVAL;
8240 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008241
8242 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008243 /* don't allow empty legacy rates if HT or VHT
8244 * are not even supported.
8245 */
8246 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8247 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008248 return -EINVAL;
8249
8250 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008251 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008252 goto out;
8253
8254 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8255 if (mask.control[band].vht_mcs[i])
8256 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008257
8258 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008259 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008260 }
8261 }
8262
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008263out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008264 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008265}
8266
Johannes Berg2e161f72010-08-12 15:38:38 +02008267static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008268{
Johannes Berg4c476992010-10-04 21:36:35 +02008269 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008270 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008271 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008272
8273 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8274 return -EINVAL;
8275
Johannes Berg2e161f72010-08-12 15:38:38 +02008276 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8277 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008278
Johannes Berg71bbc992012-06-15 15:30:18 +02008279 switch (wdev->iftype) {
8280 case NL80211_IFTYPE_STATION:
8281 case NL80211_IFTYPE_ADHOC:
8282 case NL80211_IFTYPE_P2P_CLIENT:
8283 case NL80211_IFTYPE_AP:
8284 case NL80211_IFTYPE_AP_VLAN:
8285 case NL80211_IFTYPE_MESH_POINT:
8286 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008287 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008288 break;
8289 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008290 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008291 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008292
8293 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008294 if (!rdev->ops->mgmt_tx)
8295 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008296
Eric W. Biederman15e47302012-09-07 20:12:54 +00008297 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008298 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8299 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008300}
8301
Johannes Berg2e161f72010-08-12 15:38:38 +02008302static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008303{
Johannes Berg4c476992010-10-04 21:36:35 +02008304 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008305 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008306 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008307 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008308 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008309 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008310 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008311 struct cfg80211_mgmt_tx_params params = {
8312 .dont_wait_for_ack =
8313 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8314 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008315
Johannes Berg683b6d32012-11-08 21:25:48 +01008316 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008317 return -EINVAL;
8318
Johannes Berg4c476992010-10-04 21:36:35 +02008319 if (!rdev->ops->mgmt_tx)
8320 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008321
Johannes Berg71bbc992012-06-15 15:30:18 +02008322 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008323 case NL80211_IFTYPE_P2P_DEVICE:
8324 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8325 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008326 case NL80211_IFTYPE_STATION:
8327 case NL80211_IFTYPE_ADHOC:
8328 case NL80211_IFTYPE_P2P_CLIENT:
8329 case NL80211_IFTYPE_AP:
8330 case NL80211_IFTYPE_AP_VLAN:
8331 case NL80211_IFTYPE_MESH_POINT:
8332 case NL80211_IFTYPE_P2P_GO:
8333 break;
8334 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008335 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008336 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008337
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008338 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008339 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008340 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008341 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008342
8343 /*
8344 * We should wait on the channel for at least a minimum amount
8345 * of time (10ms) but no longer than the driver supports.
8346 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008347 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8348 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008349 return -EINVAL;
8350
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008351 }
8352
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008353 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008354
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008355 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008356 return -EINVAL;
8357
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008358 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308359
Antonio Quartulliea141b752013-06-11 14:20:03 +02008360 /* get the channel if any has been specified, otherwise pass NULL to
8361 * the driver. The latter will use the current one
8362 */
8363 chandef.chan = NULL;
8364 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8365 err = nl80211_parse_chandef(rdev, info, &chandef);
8366 if (err)
8367 return err;
8368 }
8369
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008370 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008371 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008372
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008373 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8374 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8375
8376 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8377 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8378 int i;
8379
8380 if (len % sizeof(u16))
8381 return -EINVAL;
8382
8383 params.n_csa_offsets = len / sizeof(u16);
8384 params.csa_offsets =
8385 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8386
8387 /* check that all the offsets fit the frame */
8388 for (i = 0; i < params.n_csa_offsets; i++) {
8389 if (params.csa_offsets[i] >= params.len)
8390 return -EINVAL;
8391 }
8392 }
8393
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008394 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008395 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8396 if (!msg)
8397 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008398
Eric W. Biederman15e47302012-09-07 20:12:54 +00008399 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008400 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008401 if (!hdr) {
8402 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008403 goto free_msg;
8404 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008405 }
Johannes Berge247bd902011-11-04 11:18:21 +01008406
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008407 params.chan = chandef.chan;
8408 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008409 if (err)
8410 goto free_msg;
8411
Johannes Berge247bd902011-11-04 11:18:21 +01008412 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008413 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8414 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008415
Johannes Berge247bd902011-11-04 11:18:21 +01008416 genlmsg_end(msg, hdr);
8417 return genlmsg_reply(msg, info);
8418 }
8419
8420 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008421
8422 nla_put_failure:
8423 err = -ENOBUFS;
8424 free_msg:
8425 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008426 return err;
8427}
8428
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008429static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8430{
8431 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008432 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008433 u64 cookie;
8434
8435 if (!info->attrs[NL80211_ATTR_COOKIE])
8436 return -EINVAL;
8437
8438 if (!rdev->ops->mgmt_tx_cancel_wait)
8439 return -EOPNOTSUPP;
8440
Johannes Berg71bbc992012-06-15 15:30:18 +02008441 switch (wdev->iftype) {
8442 case NL80211_IFTYPE_STATION:
8443 case NL80211_IFTYPE_ADHOC:
8444 case NL80211_IFTYPE_P2P_CLIENT:
8445 case NL80211_IFTYPE_AP:
8446 case NL80211_IFTYPE_AP_VLAN:
8447 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008448 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008449 break;
8450 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008451 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008452 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008453
8454 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8455
Hila Gonene35e4d22012-06-27 17:19:42 +03008456 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008457}
8458
Kalle Valoffb9eb32010-02-17 17:58:10 +02008459static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8460{
Johannes Berg4c476992010-10-04 21:36:35 +02008461 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008462 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008463 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008464 u8 ps_state;
8465 bool state;
8466 int err;
8467
Johannes Berg4c476992010-10-04 21:36:35 +02008468 if (!info->attrs[NL80211_ATTR_PS_STATE])
8469 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008470
8471 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8472
Johannes Berg4c476992010-10-04 21:36:35 +02008473 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8474 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008475
8476 wdev = dev->ieee80211_ptr;
8477
Johannes Berg4c476992010-10-04 21:36:35 +02008478 if (!rdev->ops->set_power_mgmt)
8479 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008480
8481 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8482
8483 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008484 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008485
Hila Gonene35e4d22012-06-27 17:19:42 +03008486 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008487 if (!err)
8488 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008489 return err;
8490}
8491
8492static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8493{
Johannes Berg4c476992010-10-04 21:36:35 +02008494 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008495 enum nl80211_ps_state ps_state;
8496 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008497 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008498 struct sk_buff *msg;
8499 void *hdr;
8500 int err;
8501
Kalle Valoffb9eb32010-02-17 17:58:10 +02008502 wdev = dev->ieee80211_ptr;
8503
Johannes Berg4c476992010-10-04 21:36:35 +02008504 if (!rdev->ops->set_power_mgmt)
8505 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008506
8507 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008508 if (!msg)
8509 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008510
Eric W. Biederman15e47302012-09-07 20:12:54 +00008511 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008512 NL80211_CMD_GET_POWER_SAVE);
8513 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008514 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008515 goto free_msg;
8516 }
8517
8518 if (wdev->ps)
8519 ps_state = NL80211_PS_ENABLED;
8520 else
8521 ps_state = NL80211_PS_DISABLED;
8522
David S. Miller9360ffd2012-03-29 04:41:26 -04008523 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8524 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008525
8526 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008527 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008528
Johannes Berg4c476992010-10-04 21:36:35 +02008529 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008530 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008531 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008532 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008533 return err;
8534}
8535
Johannes Berg94e860f2014-01-20 23:58:15 +01008536static const struct nla_policy
8537nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008538 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8539 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8540 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008541 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8542 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8543 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008544};
8545
Thomas Pedersen84f10702012-07-12 16:17:33 -07008546static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008547 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008548{
8549 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008550 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008551 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008552
Johannes Bergd9d8b012012-11-26 12:51:52 +01008553 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008554 return -EINVAL;
8555
Thomas Pedersen84f10702012-07-12 16:17:33 -07008556 if (!rdev->ops->set_cqm_txe_config)
8557 return -EOPNOTSUPP;
8558
8559 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8560 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8561 return -EOPNOTSUPP;
8562
Hila Gonene35e4d22012-06-27 17:19:42 +03008563 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008564}
8565
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008566static int nl80211_set_cqm_rssi(struct genl_info *info,
8567 s32 threshold, u32 hysteresis)
8568{
Johannes Berg4c476992010-10-04 21:36:35 +02008569 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008570 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008571 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008572
8573 if (threshold > 0)
8574 return -EINVAL;
8575
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008576 /* disabling - hysteresis should also be zero then */
8577 if (threshold == 0)
8578 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008579
Johannes Berg4c476992010-10-04 21:36:35 +02008580 if (!rdev->ops->set_cqm_rssi_config)
8581 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008582
Johannes Berg074ac8d2010-09-16 14:58:22 +02008583 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008584 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8585 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008586
Hila Gonene35e4d22012-06-27 17:19:42 +03008587 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008588}
8589
8590static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8591{
8592 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8593 struct nlattr *cqm;
8594 int err;
8595
8596 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008597 if (!cqm)
8598 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008599
8600 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8601 nl80211_attr_cqm_policy);
8602 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008603 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008604
8605 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8606 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008607 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8608 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008609
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008610 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8611 }
8612
8613 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8614 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8615 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8616 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8617 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8618 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8619
8620 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8621 }
8622
8623 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008624}
8625
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008626static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8627{
8628 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8629 struct net_device *dev = info->user_ptr[1];
8630 struct ocb_setup setup = {};
8631 int err;
8632
8633 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8634 if (err)
8635 return err;
8636
8637 return cfg80211_join_ocb(rdev, dev, &setup);
8638}
8639
8640static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8641{
8642 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8643 struct net_device *dev = info->user_ptr[1];
8644
8645 return cfg80211_leave_ocb(rdev, dev);
8646}
8647
Johannes Berg29cbe682010-12-03 09:20:44 +01008648static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8649{
8650 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8651 struct net_device *dev = info->user_ptr[1];
8652 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008653 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008654 int err;
8655
8656 /* start with default */
8657 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008658 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008659
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008660 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008661 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008662 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008663 if (err)
8664 return err;
8665 }
8666
8667 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8668 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8669 return -EINVAL;
8670
Javier Cardonac80d5452010-12-16 17:37:49 -08008671 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8672 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8673
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008674 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8675 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8676 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8677 return -EINVAL;
8678
Marco Porsch9bdbf042013-01-07 16:04:51 +01008679 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8680 setup.beacon_interval =
8681 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8682 if (setup.beacon_interval < 10 ||
8683 setup.beacon_interval > 10000)
8684 return -EINVAL;
8685 }
8686
8687 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8688 setup.dtim_period =
8689 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8690 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8691 return -EINVAL;
8692 }
8693
Javier Cardonac80d5452010-12-16 17:37:49 -08008694 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8695 /* parse additional setup parameters if given */
8696 err = nl80211_parse_mesh_setup(info, &setup);
8697 if (err)
8698 return err;
8699 }
8700
Thomas Pedersend37bb182013-03-04 13:06:13 -08008701 if (setup.user_mpm)
8702 cfg.auto_open_plinks = false;
8703
Johannes Bergcc1d2802012-05-16 23:50:20 +02008704 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008705 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8706 if (err)
8707 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008708 } else {
8709 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008710 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008711 }
8712
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008713 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8714 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8715 int n_rates =
8716 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8717 struct ieee80211_supported_band *sband;
8718
8719 if (!setup.chandef.chan)
8720 return -EINVAL;
8721
8722 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8723
8724 err = ieee80211_get_ratemask(sband, rates, n_rates,
8725 &setup.basic_rates);
8726 if (err)
8727 return err;
8728 }
8729
Javier Cardonac80d5452010-12-16 17:37:49 -08008730 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008731}
8732
8733static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8734{
8735 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8736 struct net_device *dev = info->user_ptr[1];
8737
8738 return cfg80211_leave_mesh(rdev, dev);
8739}
8740
Johannes Bergdfb89c52012-06-27 09:23:48 +02008741#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008742static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8743 struct cfg80211_registered_device *rdev)
8744{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008745 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008746 struct nlattr *nl_pats, *nl_pat;
8747 int i, pat_len;
8748
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008749 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008750 return 0;
8751
8752 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8753 if (!nl_pats)
8754 return -ENOBUFS;
8755
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008756 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008757 nl_pat = nla_nest_start(msg, i + 1);
8758 if (!nl_pat)
8759 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008760 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008761 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008762 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008763 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8764 wowlan->patterns[i].pattern) ||
8765 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008766 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008767 return -ENOBUFS;
8768 nla_nest_end(msg, nl_pat);
8769 }
8770 nla_nest_end(msg, nl_pats);
8771
8772 return 0;
8773}
8774
Johannes Berg2a0e0472013-01-23 22:57:40 +01008775static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8776 struct cfg80211_wowlan_tcp *tcp)
8777{
8778 struct nlattr *nl_tcp;
8779
8780 if (!tcp)
8781 return 0;
8782
8783 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8784 if (!nl_tcp)
8785 return -ENOBUFS;
8786
8787 if (nla_put_be32(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8788 nla_put_be32(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
8789 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8790 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8791 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8792 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8793 tcp->payload_len, tcp->payload) ||
8794 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8795 tcp->data_interval) ||
8796 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8797 tcp->wake_len, tcp->wake_data) ||
8798 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8799 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8800 return -ENOBUFS;
8801
8802 if (tcp->payload_seq.len &&
8803 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8804 sizeof(tcp->payload_seq), &tcp->payload_seq))
8805 return -ENOBUFS;
8806
8807 if (tcp->payload_tok.len &&
8808 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8809 sizeof(tcp->payload_tok) + tcp->tokens_size,
8810 &tcp->payload_tok))
8811 return -ENOBUFS;
8812
Johannes Berge248ad32013-05-16 10:24:28 +02008813 nla_nest_end(msg, nl_tcp);
8814
Johannes Berg2a0e0472013-01-23 22:57:40 +01008815 return 0;
8816}
8817
Luciano Coelho75453cc2015-01-09 14:06:37 +02008818static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8819 struct cfg80211_sched_scan_request *req)
8820{
8821 struct nlattr *nd, *freqs, *matches, *match;
8822 int i;
8823
8824 if (!req)
8825 return 0;
8826
8827 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
8828 if (!nd)
8829 return -ENOBUFS;
8830
8831 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval))
8832 return -ENOBUFS;
8833
8834 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8835 if (!freqs)
8836 return -ENOBUFS;
8837
8838 for (i = 0; i < req->n_channels; i++)
8839 nla_put_u32(msg, i, req->channels[i]->center_freq);
8840
8841 nla_nest_end(msg, freqs);
8842
8843 if (req->n_match_sets) {
8844 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
8845 for (i = 0; i < req->n_match_sets; i++) {
8846 match = nla_nest_start(msg, i);
8847 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
8848 req->match_sets[i].ssid.ssid_len,
8849 req->match_sets[i].ssid.ssid);
8850 nla_nest_end(msg, match);
8851 }
8852 nla_nest_end(msg, matches);
8853 }
8854
8855 nla_nest_end(msg, nd);
8856
8857 return 0;
8858}
8859
Johannes Bergff1b6e62011-05-04 15:37:28 +02008860static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8861{
8862 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8863 struct sk_buff *msg;
8864 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008865 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008866
Johannes Berg964dc9e2013-06-03 17:25:34 +02008867 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008868 return -EOPNOTSUPP;
8869
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008870 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008871 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008872 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8873 rdev->wiphy.wowlan_config->tcp->payload_len +
8874 rdev->wiphy.wowlan_config->tcp->wake_len +
8875 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008876 }
8877
8878 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008879 if (!msg)
8880 return -ENOMEM;
8881
Eric W. Biederman15e47302012-09-07 20:12:54 +00008882 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008883 NL80211_CMD_GET_WOWLAN);
8884 if (!hdr)
8885 goto nla_put_failure;
8886
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008887 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008888 struct nlattr *nl_wowlan;
8889
8890 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8891 if (!nl_wowlan)
8892 goto nla_put_failure;
8893
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008894 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008895 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008896 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008897 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008898 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008899 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008900 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008901 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008902 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008903 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008904 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008905 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008906 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008907 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8908 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008909
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008910 if (nl80211_send_wowlan_patterns(msg, rdev))
8911 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008912
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008913 if (nl80211_send_wowlan_tcp(msg,
8914 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008915 goto nla_put_failure;
8916
Luciano Coelho75453cc2015-01-09 14:06:37 +02008917 if (nl80211_send_wowlan_nd(
8918 msg,
8919 rdev->wiphy.wowlan_config->nd_config))
8920 goto nla_put_failure;
8921
Johannes Bergff1b6e62011-05-04 15:37:28 +02008922 nla_nest_end(msg, nl_wowlan);
8923 }
8924
8925 genlmsg_end(msg, hdr);
8926 return genlmsg_reply(msg, info);
8927
8928nla_put_failure:
8929 nlmsg_free(msg);
8930 return -ENOBUFS;
8931}
8932
Johannes Berg2a0e0472013-01-23 22:57:40 +01008933static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8934 struct nlattr *attr,
8935 struct cfg80211_wowlan *trig)
8936{
8937 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8938 struct cfg80211_wowlan_tcp *cfg;
8939 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8940 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8941 u32 size;
8942 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8943 int err, port;
8944
Johannes Berg964dc9e2013-06-03 17:25:34 +02008945 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008946 return -EINVAL;
8947
8948 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8949 nla_data(attr), nla_len(attr),
8950 nl80211_wowlan_tcp_policy);
8951 if (err)
8952 return err;
8953
8954 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8955 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8956 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8957 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8958 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8959 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8960 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8961 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8962 return -EINVAL;
8963
8964 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008965 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008966 return -EINVAL;
8967
8968 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008969 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008970 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008971 return -EINVAL;
8972
8973 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008974 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008975 return -EINVAL;
8976
8977 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8978 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8979 return -EINVAL;
8980
8981 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8982 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8983
8984 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8985 tokens_size = tokln - sizeof(*tok);
8986
8987 if (!tok->len || tokens_size % tok->len)
8988 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008989 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008990 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008991 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008992 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008993 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008994 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02008995 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008996 return -EINVAL;
8997 if (tok->offset + tok->len > data_size)
8998 return -EINVAL;
8999 }
9000
9001 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9002 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009003 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009004 return -EINVAL;
9005 if (seq->len == 0 || seq->len > 4)
9006 return -EINVAL;
9007 if (seq->len + seq->offset > data_size)
9008 return -EINVAL;
9009 }
9010
9011 size = sizeof(*cfg);
9012 size += data_size;
9013 size += wake_size + wake_mask_size;
9014 size += tokens_size;
9015
9016 cfg = kzalloc(size, GFP_KERNEL);
9017 if (!cfg)
9018 return -ENOMEM;
9019 cfg->src = nla_get_be32(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9020 cfg->dst = nla_get_be32(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
9021 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9022 ETH_ALEN);
9023 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9024 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9025 else
9026 port = 0;
9027#ifdef CONFIG_INET
9028 /* allocate a socket and port for it and use it */
9029 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9030 IPPROTO_TCP, &cfg->sock, 1);
9031 if (err) {
9032 kfree(cfg);
9033 return err;
9034 }
9035 if (inet_csk_get_port(cfg->sock->sk, port)) {
9036 sock_release(cfg->sock);
9037 kfree(cfg);
9038 return -EADDRINUSE;
9039 }
9040 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9041#else
9042 if (!port) {
9043 kfree(cfg);
9044 return -EINVAL;
9045 }
9046 cfg->src_port = port;
9047#endif
9048
9049 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9050 cfg->payload_len = data_size;
9051 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9052 memcpy((void *)cfg->payload,
9053 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9054 data_size);
9055 if (seq)
9056 cfg->payload_seq = *seq;
9057 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9058 cfg->wake_len = wake_size;
9059 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9060 memcpy((void *)cfg->wake_data,
9061 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9062 wake_size);
9063 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9064 data_size + wake_size;
9065 memcpy((void *)cfg->wake_mask,
9066 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9067 wake_mask_size);
9068 if (tok) {
9069 cfg->tokens_size = tokens_size;
9070 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9071 }
9072
9073 trig->tcp = cfg;
9074
9075 return 0;
9076}
9077
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009078static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9079 const struct wiphy_wowlan_support *wowlan,
9080 struct nlattr *attr,
9081 struct cfg80211_wowlan *trig)
9082{
9083 struct nlattr **tb;
9084 int err;
9085
9086 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9087 if (!tb)
9088 return -ENOMEM;
9089
9090 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9091 err = -EOPNOTSUPP;
9092 goto out;
9093 }
9094
9095 err = nla_parse(tb, NL80211_ATTR_MAX,
9096 nla_data(attr), nla_len(attr),
9097 nl80211_policy);
9098 if (err)
9099 goto out;
9100
Johannes Bergad2b26a2014-06-12 21:39:05 +02009101 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009102 err = PTR_ERR_OR_ZERO(trig->nd_config);
9103 if (err)
9104 trig->nd_config = NULL;
9105
9106out:
9107 kfree(tb);
9108 return err;
9109}
9110
Johannes Bergff1b6e62011-05-04 15:37:28 +02009111static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9112{
9113 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9114 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009115 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009116 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009117 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009118 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009119 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009120 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009121
Johannes Berg964dc9e2013-06-03 17:25:34 +02009122 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009123 return -EOPNOTSUPP;
9124
Johannes Bergae33bd82012-07-12 16:25:02 +02009125 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9126 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009127 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009128 goto set_wakeup;
9129 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009130
9131 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9132 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9133 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9134 nl80211_wowlan_policy);
9135 if (err)
9136 return err;
9137
9138 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9139 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9140 return -EINVAL;
9141 new_triggers.any = true;
9142 }
9143
9144 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9145 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9146 return -EINVAL;
9147 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009148 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009149 }
9150
9151 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9152 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9153 return -EINVAL;
9154 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009155 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009156 }
9157
Johannes Berg77dbbb12011-07-13 10:48:55 +02009158 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9159 return -EINVAL;
9160
9161 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9162 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9163 return -EINVAL;
9164 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009165 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009166 }
9167
9168 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9169 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9170 return -EINVAL;
9171 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009172 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009173 }
9174
9175 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9176 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9177 return -EINVAL;
9178 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009179 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009180 }
9181
9182 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9183 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9184 return -EINVAL;
9185 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009186 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009187 }
9188
Johannes Bergff1b6e62011-05-04 15:37:28 +02009189 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9190 struct nlattr *pat;
9191 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009192 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009193 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009194
Johannes Berg98fc4382015-03-01 09:10:13 +02009195 regular = true;
9196
Johannes Bergff1b6e62011-05-04 15:37:28 +02009197 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9198 rem)
9199 n_patterns++;
9200 if (n_patterns > wowlan->n_patterns)
9201 return -EINVAL;
9202
9203 new_triggers.patterns = kcalloc(n_patterns,
9204 sizeof(new_triggers.patterns[0]),
9205 GFP_KERNEL);
9206 if (!new_triggers.patterns)
9207 return -ENOMEM;
9208
9209 new_triggers.n_patterns = n_patterns;
9210 i = 0;
9211
9212 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9213 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009214 u8 *mask_pat;
9215
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009216 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9217 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009218 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009219 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9220 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009221 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009222 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009223 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009224 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009225 goto error;
9226 if (pat_len > wowlan->pattern_max_len ||
9227 pat_len < wowlan->pattern_min_len)
9228 goto error;
9229
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009230 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009231 pkt_offset = 0;
9232 else
9233 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009234 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009235 if (pkt_offset > wowlan->max_pkt_offset)
9236 goto error;
9237 new_triggers.patterns[i].pkt_offset = pkt_offset;
9238
Johannes Berg922bd802014-05-19 17:59:50 +02009239 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9240 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009241 err = -ENOMEM;
9242 goto error;
9243 }
Johannes Berg922bd802014-05-19 17:59:50 +02009244 new_triggers.patterns[i].mask = mask_pat;
9245 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009246 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009247 mask_pat += mask_len;
9248 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009249 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009250 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009251 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009252 pat_len);
9253 i++;
9254 }
9255 }
9256
Johannes Berg2a0e0472013-01-23 22:57:40 +01009257 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009258 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009259 err = nl80211_parse_wowlan_tcp(
9260 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9261 &new_triggers);
9262 if (err)
9263 goto error;
9264 }
9265
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009266 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009267 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009268 err = nl80211_parse_wowlan_nd(
9269 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9270 &new_triggers);
9271 if (err)
9272 goto error;
9273 }
9274
Johannes Berg98fc4382015-03-01 09:10:13 +02009275 /* The 'any' trigger means the device continues operating more or less
9276 * as in its normal operation mode and wakes up the host on most of the
9277 * normal interrupts (like packet RX, ...)
9278 * It therefore makes little sense to combine with the more constrained
9279 * wakeup trigger modes.
9280 */
9281 if (new_triggers.any && regular) {
9282 err = -EINVAL;
9283 goto error;
9284 }
9285
Johannes Bergae33bd82012-07-12 16:25:02 +02009286 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9287 if (!ntrig) {
9288 err = -ENOMEM;
9289 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009290 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009291 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009292 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009293
Johannes Bergae33bd82012-07-12 16:25:02 +02009294 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009295 if (rdev->ops->set_wakeup &&
9296 prev_enabled != !!rdev->wiphy.wowlan_config)
9297 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009298
Johannes Bergff1b6e62011-05-04 15:37:28 +02009299 return 0;
9300 error:
9301 for (i = 0; i < new_triggers.n_patterns; i++)
9302 kfree(new_triggers.patterns[i].mask);
9303 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009304 if (new_triggers.tcp && new_triggers.tcp->sock)
9305 sock_release(new_triggers.tcp->sock);
9306 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009307 return err;
9308}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009309#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009310
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009311static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9312 struct cfg80211_registered_device *rdev)
9313{
9314 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9315 int i, j, pat_len;
9316 struct cfg80211_coalesce_rules *rule;
9317
9318 if (!rdev->coalesce->n_rules)
9319 return 0;
9320
9321 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9322 if (!nl_rules)
9323 return -ENOBUFS;
9324
9325 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9326 nl_rule = nla_nest_start(msg, i + 1);
9327 if (!nl_rule)
9328 return -ENOBUFS;
9329
9330 rule = &rdev->coalesce->rules[i];
9331 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9332 rule->delay))
9333 return -ENOBUFS;
9334
9335 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9336 rule->condition))
9337 return -ENOBUFS;
9338
9339 nl_pats = nla_nest_start(msg,
9340 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9341 if (!nl_pats)
9342 return -ENOBUFS;
9343
9344 for (j = 0; j < rule->n_patterns; j++) {
9345 nl_pat = nla_nest_start(msg, j + 1);
9346 if (!nl_pat)
9347 return -ENOBUFS;
9348 pat_len = rule->patterns[j].pattern_len;
9349 if (nla_put(msg, NL80211_PKTPAT_MASK,
9350 DIV_ROUND_UP(pat_len, 8),
9351 rule->patterns[j].mask) ||
9352 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9353 rule->patterns[j].pattern) ||
9354 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9355 rule->patterns[j].pkt_offset))
9356 return -ENOBUFS;
9357 nla_nest_end(msg, nl_pat);
9358 }
9359 nla_nest_end(msg, nl_pats);
9360 nla_nest_end(msg, nl_rule);
9361 }
9362 nla_nest_end(msg, nl_rules);
9363
9364 return 0;
9365}
9366
9367static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9368{
9369 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9370 struct sk_buff *msg;
9371 void *hdr;
9372
9373 if (!rdev->wiphy.coalesce)
9374 return -EOPNOTSUPP;
9375
9376 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9377 if (!msg)
9378 return -ENOMEM;
9379
9380 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9381 NL80211_CMD_GET_COALESCE);
9382 if (!hdr)
9383 goto nla_put_failure;
9384
9385 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9386 goto nla_put_failure;
9387
9388 genlmsg_end(msg, hdr);
9389 return genlmsg_reply(msg, info);
9390
9391nla_put_failure:
9392 nlmsg_free(msg);
9393 return -ENOBUFS;
9394}
9395
9396void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9397{
9398 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9399 int i, j;
9400 struct cfg80211_coalesce_rules *rule;
9401
9402 if (!coalesce)
9403 return;
9404
9405 for (i = 0; i < coalesce->n_rules; i++) {
9406 rule = &coalesce->rules[i];
9407 for (j = 0; j < rule->n_patterns; j++)
9408 kfree(rule->patterns[j].mask);
9409 kfree(rule->patterns);
9410 }
9411 kfree(coalesce->rules);
9412 kfree(coalesce);
9413 rdev->coalesce = NULL;
9414}
9415
9416static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9417 struct nlattr *rule,
9418 struct cfg80211_coalesce_rules *new_rule)
9419{
9420 int err, i;
9421 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9422 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9423 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9424 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9425
9426 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9427 nla_len(rule), nl80211_coalesce_policy);
9428 if (err)
9429 return err;
9430
9431 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9432 new_rule->delay =
9433 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9434 if (new_rule->delay > coalesce->max_delay)
9435 return -EINVAL;
9436
9437 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9438 new_rule->condition =
9439 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9440 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9441 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9442 return -EINVAL;
9443
9444 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9445 return -EINVAL;
9446
9447 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9448 rem)
9449 n_patterns++;
9450 if (n_patterns > coalesce->n_patterns)
9451 return -EINVAL;
9452
9453 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9454 GFP_KERNEL);
9455 if (!new_rule->patterns)
9456 return -ENOMEM;
9457
9458 new_rule->n_patterns = n_patterns;
9459 i = 0;
9460
9461 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9462 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009463 u8 *mask_pat;
9464
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009465 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9466 nla_len(pat), NULL);
9467 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9468 !pat_tb[NL80211_PKTPAT_PATTERN])
9469 return -EINVAL;
9470 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9471 mask_len = DIV_ROUND_UP(pat_len, 8);
9472 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9473 return -EINVAL;
9474 if (pat_len > coalesce->pattern_max_len ||
9475 pat_len < coalesce->pattern_min_len)
9476 return -EINVAL;
9477
9478 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9479 pkt_offset = 0;
9480 else
9481 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9482 if (pkt_offset > coalesce->max_pkt_offset)
9483 return -EINVAL;
9484 new_rule->patterns[i].pkt_offset = pkt_offset;
9485
Johannes Berg922bd802014-05-19 17:59:50 +02009486 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9487 if (!mask_pat)
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009488 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009489
9490 new_rule->patterns[i].mask = mask_pat;
9491 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9492 mask_len);
9493
9494 mask_pat += mask_len;
9495 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009496 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009497 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9498 pat_len);
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -07009499 i++;
9500 }
9501
9502 return 0;
9503}
9504
9505static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9506{
9507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9508 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9509 struct cfg80211_coalesce new_coalesce = {};
9510 struct cfg80211_coalesce *n_coalesce;
9511 int err, rem_rule, n_rules = 0, i, j;
9512 struct nlattr *rule;
9513 struct cfg80211_coalesce_rules *tmp_rule;
9514
9515 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9516 return -EOPNOTSUPP;
9517
9518 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9519 cfg80211_rdev_free_coalesce(rdev);
9520 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9521 return 0;
9522 }
9523
9524 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9525 rem_rule)
9526 n_rules++;
9527 if (n_rules > coalesce->n_rules)
9528 return -EINVAL;
9529
9530 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9531 GFP_KERNEL);
9532 if (!new_coalesce.rules)
9533 return -ENOMEM;
9534
9535 new_coalesce.n_rules = n_rules;
9536 i = 0;
9537
9538 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9539 rem_rule) {
9540 err = nl80211_parse_coalesce_rule(rdev, rule,
9541 &new_coalesce.rules[i]);
9542 if (err)
9543 goto error;
9544
9545 i++;
9546 }
9547
9548 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9549 if (err)
9550 goto error;
9551
9552 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9553 if (!n_coalesce) {
9554 err = -ENOMEM;
9555 goto error;
9556 }
9557 cfg80211_rdev_free_coalesce(rdev);
9558 rdev->coalesce = n_coalesce;
9559
9560 return 0;
9561error:
9562 for (i = 0; i < new_coalesce.n_rules; i++) {
9563 tmp_rule = &new_coalesce.rules[i];
9564 for (j = 0; j < tmp_rule->n_patterns; j++)
9565 kfree(tmp_rule->patterns[j].mask);
9566 kfree(tmp_rule->patterns);
9567 }
9568 kfree(new_coalesce.rules);
9569
9570 return err;
9571}
9572
Johannes Berge5497d72011-07-05 16:35:40 +02009573static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9574{
9575 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9576 struct net_device *dev = info->user_ptr[1];
9577 struct wireless_dev *wdev = dev->ieee80211_ptr;
9578 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9579 struct cfg80211_gtk_rekey_data rekey_data;
9580 int err;
9581
9582 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9583 return -EINVAL;
9584
9585 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9586 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9587 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9588 nl80211_rekey_policy);
9589 if (err)
9590 return err;
9591
9592 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9593 return -ERANGE;
9594 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9595 return -ERANGE;
9596 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9597 return -ERANGE;
9598
Johannes Berg78f686c2014-09-10 22:28:06 +03009599 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9600 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9601 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009602
9603 wdev_lock(wdev);
9604 if (!wdev->current_bss) {
9605 err = -ENOTCONN;
9606 goto out;
9607 }
9608
9609 if (!rdev->ops->set_rekey_data) {
9610 err = -EOPNOTSUPP;
9611 goto out;
9612 }
9613
Hila Gonene35e4d22012-06-27 17:19:42 +03009614 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009615 out:
9616 wdev_unlock(wdev);
9617 return err;
9618}
9619
Johannes Berg28946da2011-11-04 11:18:12 +01009620static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9621 struct genl_info *info)
9622{
9623 struct net_device *dev = info->user_ptr[1];
9624 struct wireless_dev *wdev = dev->ieee80211_ptr;
9625
9626 if (wdev->iftype != NL80211_IFTYPE_AP &&
9627 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9628 return -EINVAL;
9629
Eric W. Biederman15e47302012-09-07 20:12:54 +00009630 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009631 return -EBUSY;
9632
Eric W. Biederman15e47302012-09-07 20:12:54 +00009633 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009634 return 0;
9635}
9636
Johannes Berg7f6cf312011-11-04 11:18:15 +01009637static int nl80211_probe_client(struct sk_buff *skb,
9638 struct genl_info *info)
9639{
9640 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9641 struct net_device *dev = info->user_ptr[1];
9642 struct wireless_dev *wdev = dev->ieee80211_ptr;
9643 struct sk_buff *msg;
9644 void *hdr;
9645 const u8 *addr;
9646 u64 cookie;
9647 int err;
9648
9649 if (wdev->iftype != NL80211_IFTYPE_AP &&
9650 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9651 return -EOPNOTSUPP;
9652
9653 if (!info->attrs[NL80211_ATTR_MAC])
9654 return -EINVAL;
9655
9656 if (!rdev->ops->probe_client)
9657 return -EOPNOTSUPP;
9658
9659 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9660 if (!msg)
9661 return -ENOMEM;
9662
Eric W. Biederman15e47302012-09-07 20:12:54 +00009663 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009664 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009665 if (!hdr) {
9666 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009667 goto free_msg;
9668 }
9669
9670 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9671
Hila Gonene35e4d22012-06-27 17:19:42 +03009672 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009673 if (err)
9674 goto free_msg;
9675
David S. Miller9360ffd2012-03-29 04:41:26 -04009676 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9677 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009678
9679 genlmsg_end(msg, hdr);
9680
9681 return genlmsg_reply(msg, info);
9682
9683 nla_put_failure:
9684 err = -ENOBUFS;
9685 free_msg:
9686 nlmsg_free(msg);
9687 return err;
9688}
9689
Johannes Berg5e760232011-11-04 11:18:17 +01009690static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9691{
9692 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009693 struct cfg80211_beacon_registration *reg, *nreg;
9694 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009695
9696 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9697 return -EOPNOTSUPP;
9698
Ben Greear37c73b52012-10-26 14:49:25 -07009699 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9700 if (!nreg)
9701 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009702
Ben Greear37c73b52012-10-26 14:49:25 -07009703 /* First, check if already registered. */
9704 spin_lock_bh(&rdev->beacon_registrations_lock);
9705 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9706 if (reg->nlportid == info->snd_portid) {
9707 rv = -EALREADY;
9708 goto out_err;
9709 }
9710 }
9711 /* Add it to the list */
9712 nreg->nlportid = info->snd_portid;
9713 list_add(&nreg->list, &rdev->beacon_registrations);
9714
9715 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009716
9717 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009718out_err:
9719 spin_unlock_bh(&rdev->beacon_registrations_lock);
9720 kfree(nreg);
9721 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009722}
9723
Johannes Berg98104fde2012-06-16 00:19:54 +02009724static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9725{
9726 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9727 struct wireless_dev *wdev = info->user_ptr[1];
9728 int err;
9729
9730 if (!rdev->ops->start_p2p_device)
9731 return -EOPNOTSUPP;
9732
9733 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9734 return -EOPNOTSUPP;
9735
9736 if (wdev->p2p_started)
9737 return 0;
9738
Luciano Coelhob6a55012014-02-27 11:07:21 +02009739 if (rfkill_blocked(rdev->rfkill))
9740 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009741
Johannes Bergeeb126e2012-10-23 15:16:50 +02009742 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009743 if (err)
9744 return err;
9745
9746 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009747 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009748
9749 return 0;
9750}
9751
9752static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9753{
9754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9755 struct wireless_dev *wdev = info->user_ptr[1];
9756
9757 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9758 return -EOPNOTSUPP;
9759
9760 if (!rdev->ops->stop_p2p_device)
9761 return -EOPNOTSUPP;
9762
Johannes Bergf9f47522013-03-19 15:04:07 +01009763 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009764
9765 return 0;
9766}
9767
Johannes Berg3713b4e2013-02-14 16:19:38 +01009768static int nl80211_get_protocol_features(struct sk_buff *skb,
9769 struct genl_info *info)
9770{
9771 void *hdr;
9772 struct sk_buff *msg;
9773
9774 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9775 if (!msg)
9776 return -ENOMEM;
9777
9778 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9779 NL80211_CMD_GET_PROTOCOL_FEATURES);
9780 if (!hdr)
9781 goto nla_put_failure;
9782
9783 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9784 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9785 goto nla_put_failure;
9786
9787 genlmsg_end(msg, hdr);
9788 return genlmsg_reply(msg, info);
9789
9790 nla_put_failure:
9791 kfree_skb(msg);
9792 return -ENOBUFS;
9793}
9794
Jouni Malinen355199e2013-02-27 17:14:27 +02009795static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9796{
9797 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9798 struct cfg80211_update_ft_ies_params ft_params;
9799 struct net_device *dev = info->user_ptr[1];
9800
9801 if (!rdev->ops->update_ft_ies)
9802 return -EOPNOTSUPP;
9803
9804 if (!info->attrs[NL80211_ATTR_MDID] ||
9805 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9806 return -EINVAL;
9807
9808 memset(&ft_params, 0, sizeof(ft_params));
9809 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9810 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9811 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9812
9813 return rdev_update_ft_ies(rdev, dev, &ft_params);
9814}
9815
Arend van Spriel5de17982013-04-18 15:49:00 +02009816static int nl80211_crit_protocol_start(struct sk_buff *skb,
9817 struct genl_info *info)
9818{
9819 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9820 struct wireless_dev *wdev = info->user_ptr[1];
9821 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9822 u16 duration;
9823 int ret;
9824
9825 if (!rdev->ops->crit_proto_start)
9826 return -EOPNOTSUPP;
9827
9828 if (WARN_ON(!rdev->ops->crit_proto_stop))
9829 return -EINVAL;
9830
9831 if (rdev->crit_proto_nlportid)
9832 return -EBUSY;
9833
9834 /* determine protocol if provided */
9835 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9836 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9837
9838 if (proto >= NUM_NL80211_CRIT_PROTO)
9839 return -EINVAL;
9840
9841 /* timeout must be provided */
9842 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9843 return -EINVAL;
9844
9845 duration =
9846 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9847
9848 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9849 return -ERANGE;
9850
9851 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9852 if (!ret)
9853 rdev->crit_proto_nlportid = info->snd_portid;
9854
9855 return ret;
9856}
9857
9858static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9859 struct genl_info *info)
9860{
9861 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9862 struct wireless_dev *wdev = info->user_ptr[1];
9863
9864 if (!rdev->ops->crit_proto_stop)
9865 return -EOPNOTSUPP;
9866
9867 if (rdev->crit_proto_nlportid) {
9868 rdev->crit_proto_nlportid = 0;
9869 rdev_crit_proto_stop(rdev, wdev);
9870 }
9871 return 0;
9872}
9873
Johannes Bergad7e7182013-11-13 13:37:47 +01009874static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9875{
9876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9877 struct wireless_dev *wdev =
9878 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9879 int i, err;
9880 u32 vid, subcmd;
9881
9882 if (!rdev->wiphy.vendor_commands)
9883 return -EOPNOTSUPP;
9884
9885 if (IS_ERR(wdev)) {
9886 err = PTR_ERR(wdev);
9887 if (err != -EINVAL)
9888 return err;
9889 wdev = NULL;
9890 } else if (wdev->wiphy != &rdev->wiphy) {
9891 return -EINVAL;
9892 }
9893
9894 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9895 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9896 return -EINVAL;
9897
9898 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9899 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9900 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9901 const struct wiphy_vendor_command *vcmd;
9902 void *data = NULL;
9903 int len = 0;
9904
9905 vcmd = &rdev->wiphy.vendor_commands[i];
9906
9907 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9908 continue;
9909
9910 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9911 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9912 if (!wdev)
9913 return -EINVAL;
9914 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9915 !wdev->netdev)
9916 return -EINVAL;
9917
9918 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9919 if (wdev->netdev &&
9920 !netif_running(wdev->netdev))
9921 return -ENETDOWN;
9922 if (!wdev->netdev && !wdev->p2p_started)
9923 return -ENETDOWN;
9924 }
9925 } else {
9926 wdev = NULL;
9927 }
9928
9929 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9930 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9931 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9932 }
9933
9934 rdev->cur_cmd_info = info;
9935 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9936 data, len);
9937 rdev->cur_cmd_info = NULL;
9938 return err;
9939 }
9940
9941 return -EOPNOTSUPP;
9942}
9943
9944struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9945 enum nl80211_commands cmd,
9946 enum nl80211_attrs attr,
9947 int approxlen)
9948{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009949 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009950
9951 if (WARN_ON(!rdev->cur_cmd_info))
9952 return NULL;
9953
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009954 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +01009955 rdev->cur_cmd_info->snd_portid,
9956 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009957 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009958}
9959EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9960
9961int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9962{
9963 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9964 void *hdr = ((void **)skb->cb)[1];
9965 struct nlattr *data = ((void **)skb->cb)[2];
9966
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009967 /* clear CB data for netlink core to own from now on */
9968 memset(skb->cb, 0, sizeof(skb->cb));
9969
Johannes Bergad7e7182013-11-13 13:37:47 +01009970 if (WARN_ON(!rdev->cur_cmd_info)) {
9971 kfree_skb(skb);
9972 return -EINVAL;
9973 }
9974
9975 nla_nest_end(skb, data);
9976 genlmsg_end(skb, hdr);
9977 return genlmsg_reply(skb, rdev->cur_cmd_info);
9978}
9979EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9980
9981
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009982static int nl80211_set_qos_map(struct sk_buff *skb,
9983 struct genl_info *info)
9984{
9985 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9986 struct cfg80211_qos_map *qos_map = NULL;
9987 struct net_device *dev = info->user_ptr[1];
9988 u8 *pos, len, num_des, des_len, des;
9989 int ret;
9990
9991 if (!rdev->ops->set_qos_map)
9992 return -EOPNOTSUPP;
9993
9994 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
9995 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
9996 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
9997
9998 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
9999 len > IEEE80211_QOS_MAP_LEN_MAX)
10000 return -EINVAL;
10001
10002 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10003 if (!qos_map)
10004 return -ENOMEM;
10005
10006 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10007 if (num_des) {
10008 des_len = num_des *
10009 sizeof(struct cfg80211_dscp_exception);
10010 memcpy(qos_map->dscp_exception, pos, des_len);
10011 qos_map->num_des = num_des;
10012 for (des = 0; des < num_des; des++) {
10013 if (qos_map->dscp_exception[des].up > 7) {
10014 kfree(qos_map);
10015 return -EINVAL;
10016 }
10017 }
10018 pos += des_len;
10019 }
10020 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10021 }
10022
10023 wdev_lock(dev->ieee80211_ptr);
10024 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10025 if (!ret)
10026 ret = rdev_set_qos_map(rdev, dev, qos_map);
10027 wdev_unlock(dev->ieee80211_ptr);
10028
10029 kfree(qos_map);
10030 return ret;
10031}
10032
Johannes Berg960d01a2014-09-09 22:55:35 +030010033static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10034{
10035 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10036 struct net_device *dev = info->user_ptr[1];
10037 struct wireless_dev *wdev = dev->ieee80211_ptr;
10038 const u8 *peer;
10039 u8 tsid, up;
10040 u16 admitted_time = 0;
10041 int err;
10042
Johannes Berg723e73a2014-10-22 09:25:06 +020010043 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010044 return -EOPNOTSUPP;
10045
10046 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10047 !info->attrs[NL80211_ATTR_USER_PRIO])
10048 return -EINVAL;
10049
10050 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10051 if (tsid >= IEEE80211_NUM_TIDS)
10052 return -EINVAL;
10053
10054 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10055 if (up >= IEEE80211_NUM_UPS)
10056 return -EINVAL;
10057
10058 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010059 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010060 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010061 * need more attributes for that (e.g. BA session requirement);
10062 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010063 */
10064 return -EINVAL;
10065 }
10066
10067 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10068
10069 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10070 admitted_time =
10071 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10072 if (!admitted_time)
10073 return -EINVAL;
10074 }
10075
10076 wdev_lock(wdev);
10077 switch (wdev->iftype) {
10078 case NL80211_IFTYPE_STATION:
10079 case NL80211_IFTYPE_P2P_CLIENT:
10080 if (wdev->current_bss)
10081 break;
10082 err = -ENOTCONN;
10083 goto out;
10084 default:
10085 err = -EOPNOTSUPP;
10086 goto out;
10087 }
10088
10089 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10090
10091 out:
10092 wdev_unlock(wdev);
10093 return err;
10094}
10095
10096static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10097{
10098 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10099 struct net_device *dev = info->user_ptr[1];
10100 struct wireless_dev *wdev = dev->ieee80211_ptr;
10101 const u8 *peer;
10102 u8 tsid;
10103 int err;
10104
10105 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10106 return -EINVAL;
10107
10108 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10109 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10110
10111 wdev_lock(wdev);
10112 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10113 wdev_unlock(wdev);
10114
10115 return err;
10116}
10117
Arik Nemtsov1057d352014-11-19 12:54:26 +020010118static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10119 struct genl_info *info)
10120{
10121 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10122 struct net_device *dev = info->user_ptr[1];
10123 struct wireless_dev *wdev = dev->ieee80211_ptr;
10124 struct cfg80211_chan_def chandef = {};
10125 const u8 *addr;
10126 u8 oper_class;
10127 int err;
10128
10129 if (!rdev->ops->tdls_channel_switch ||
10130 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10131 return -EOPNOTSUPP;
10132
10133 switch (dev->ieee80211_ptr->iftype) {
10134 case NL80211_IFTYPE_STATION:
10135 case NL80211_IFTYPE_P2P_CLIENT:
10136 break;
10137 default:
10138 return -EOPNOTSUPP;
10139 }
10140
10141 if (!info->attrs[NL80211_ATTR_MAC] ||
10142 !info->attrs[NL80211_ATTR_OPER_CLASS])
10143 return -EINVAL;
10144
10145 err = nl80211_parse_chandef(rdev, info, &chandef);
10146 if (err)
10147 return err;
10148
10149 /*
10150 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10151 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10152 * specification is not defined for them.
10153 */
10154 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10155 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10156 chandef.width != NL80211_CHAN_WIDTH_20)
10157 return -EINVAL;
10158
10159 /* we will be active on the TDLS link */
10160 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &chandef, wdev->iftype))
10161 return -EINVAL;
10162
10163 /* don't allow switching to DFS channels */
10164 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10165 return -EINVAL;
10166
10167 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10168 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10169
10170 wdev_lock(wdev);
10171 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10172 wdev_unlock(wdev);
10173
10174 return err;
10175}
10176
10177static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10178 struct genl_info *info)
10179{
10180 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10181 struct net_device *dev = info->user_ptr[1];
10182 struct wireless_dev *wdev = dev->ieee80211_ptr;
10183 const u8 *addr;
10184
10185 if (!rdev->ops->tdls_channel_switch ||
10186 !rdev->ops->tdls_cancel_channel_switch ||
10187 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10188 return -EOPNOTSUPP;
10189
10190 switch (dev->ieee80211_ptr->iftype) {
10191 case NL80211_IFTYPE_STATION:
10192 case NL80211_IFTYPE_P2P_CLIENT:
10193 break;
10194 default:
10195 return -EOPNOTSUPP;
10196 }
10197
10198 if (!info->attrs[NL80211_ATTR_MAC])
10199 return -EINVAL;
10200
10201 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10202
10203 wdev_lock(wdev);
10204 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10205 wdev_unlock(wdev);
10206
10207 return 0;
10208}
10209
Johannes Berg4c476992010-10-04 21:36:35 +020010210#define NL80211_FLAG_NEED_WIPHY 0x01
10211#define NL80211_FLAG_NEED_NETDEV 0x02
10212#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010213#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10214#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10215 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010216#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010217/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010218#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10219 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010220#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010221
Johannes Bergf84f7712013-11-14 17:14:45 +010010222static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010223 struct genl_info *info)
10224{
10225 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010226 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010227 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010228 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10229
10230 if (rtnl)
10231 rtnl_lock();
10232
10233 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010234 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010235 if (IS_ERR(rdev)) {
10236 if (rtnl)
10237 rtnl_unlock();
10238 return PTR_ERR(rdev);
10239 }
10240 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010241 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10242 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010243 ASSERT_RTNL();
10244
Johannes Berg89a54e42012-06-15 14:33:17 +020010245 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10246 info->attrs);
10247 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010248 if (rtnl)
10249 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010250 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010251 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010252
Johannes Berg89a54e42012-06-15 14:33:17 +020010253 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010254 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010255
Johannes Berg1bf614e2012-06-15 15:23:36 +020010256 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10257 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010258 if (rtnl)
10259 rtnl_unlock();
10260 return -EINVAL;
10261 }
10262
10263 info->user_ptr[1] = dev;
10264 } else {
10265 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010266 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010267
Johannes Berg1bf614e2012-06-15 15:23:36 +020010268 if (dev) {
10269 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10270 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010271 if (rtnl)
10272 rtnl_unlock();
10273 return -ENETDOWN;
10274 }
10275
10276 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010277 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10278 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010279 if (rtnl)
10280 rtnl_unlock();
10281 return -ENETDOWN;
10282 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010283 }
10284
Johannes Berg4c476992010-10-04 21:36:35 +020010285 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010286 }
10287
10288 return 0;
10289}
10290
Johannes Bergf84f7712013-11-14 17:14:45 +010010291static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010292 struct genl_info *info)
10293{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010294 if (info->user_ptr[1]) {
10295 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10296 struct wireless_dev *wdev = info->user_ptr[1];
10297
10298 if (wdev->netdev)
10299 dev_put(wdev->netdev);
10300 } else {
10301 dev_put(info->user_ptr[1]);
10302 }
10303 }
Johannes Berg5393b912014-09-10 15:00:16 +030010304
Johannes Berg4c476992010-10-04 21:36:35 +020010305 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10306 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010307
10308 /* If needed, clear the netlink message payload from the SKB
10309 * as it might contain key data that shouldn't stick around on
10310 * the heap after the SKB is freed. The netlink message header
10311 * is still needed for further processing, so leave it intact.
10312 */
10313 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10314 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10315
10316 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10317 }
Johannes Berg4c476992010-10-04 21:36:35 +020010318}
10319
Johannes Berg4534de82013-11-14 17:14:46 +010010320static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010321 {
10322 .cmd = NL80211_CMD_GET_WIPHY,
10323 .doit = nl80211_get_wiphy,
10324 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010325 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010326 .policy = nl80211_policy,
10327 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010328 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10329 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010330 },
10331 {
10332 .cmd = NL80211_CMD_SET_WIPHY,
10333 .doit = nl80211_set_wiphy,
10334 .policy = nl80211_policy,
10335 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010336 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010337 },
10338 {
10339 .cmd = NL80211_CMD_GET_INTERFACE,
10340 .doit = nl80211_get_interface,
10341 .dumpit = nl80211_dump_interface,
10342 .policy = nl80211_policy,
10343 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010344 .internal_flags = NL80211_FLAG_NEED_WDEV |
10345 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010346 },
10347 {
10348 .cmd = NL80211_CMD_SET_INTERFACE,
10349 .doit = nl80211_set_interface,
10350 .policy = nl80211_policy,
10351 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010352 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10353 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010354 },
10355 {
10356 .cmd = NL80211_CMD_NEW_INTERFACE,
10357 .doit = nl80211_new_interface,
10358 .policy = nl80211_policy,
10359 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010360 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10361 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010362 },
10363 {
10364 .cmd = NL80211_CMD_DEL_INTERFACE,
10365 .doit = nl80211_del_interface,
10366 .policy = nl80211_policy,
10367 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010368 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010369 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010370 },
Johannes Berg41ade002007-12-19 02:03:29 +010010371 {
10372 .cmd = NL80211_CMD_GET_KEY,
10373 .doit = nl80211_get_key,
10374 .policy = nl80211_policy,
10375 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010376 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010377 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010378 },
10379 {
10380 .cmd = NL80211_CMD_SET_KEY,
10381 .doit = nl80211_set_key,
10382 .policy = nl80211_policy,
10383 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010384 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010385 NL80211_FLAG_NEED_RTNL |
10386 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010387 },
10388 {
10389 .cmd = NL80211_CMD_NEW_KEY,
10390 .doit = nl80211_new_key,
10391 .policy = nl80211_policy,
10392 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010393 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010394 NL80211_FLAG_NEED_RTNL |
10395 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010396 },
10397 {
10398 .cmd = NL80211_CMD_DEL_KEY,
10399 .doit = nl80211_del_key,
10400 .policy = nl80211_policy,
10401 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010402 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010403 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010404 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010405 {
10406 .cmd = NL80211_CMD_SET_BEACON,
10407 .policy = nl80211_policy,
10408 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010409 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010410 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010411 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010412 },
10413 {
Johannes Berg88600202012-02-13 15:17:18 +010010414 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010415 .policy = nl80211_policy,
10416 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010417 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010418 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010419 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010420 },
10421 {
Johannes Berg88600202012-02-13 15:17:18 +010010422 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010423 .policy = nl80211_policy,
10424 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010425 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010426 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010427 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010428 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010429 {
10430 .cmd = NL80211_CMD_GET_STATION,
10431 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010432 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010433 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010434 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10435 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010436 },
10437 {
10438 .cmd = NL80211_CMD_SET_STATION,
10439 .doit = nl80211_set_station,
10440 .policy = nl80211_policy,
10441 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010442 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010443 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010444 },
10445 {
10446 .cmd = NL80211_CMD_NEW_STATION,
10447 .doit = nl80211_new_station,
10448 .policy = nl80211_policy,
10449 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010450 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010451 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010452 },
10453 {
10454 .cmd = NL80211_CMD_DEL_STATION,
10455 .doit = nl80211_del_station,
10456 .policy = nl80211_policy,
10457 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010458 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010459 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010460 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010461 {
10462 .cmd = NL80211_CMD_GET_MPATH,
10463 .doit = nl80211_get_mpath,
10464 .dumpit = nl80211_dump_mpath,
10465 .policy = nl80211_policy,
10466 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010467 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010468 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010469 },
10470 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010471 .cmd = NL80211_CMD_GET_MPP,
10472 .doit = nl80211_get_mpp,
10473 .dumpit = nl80211_dump_mpp,
10474 .policy = nl80211_policy,
10475 .flags = GENL_ADMIN_PERM,
10476 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10477 NL80211_FLAG_NEED_RTNL,
10478 },
10479 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010480 .cmd = NL80211_CMD_SET_MPATH,
10481 .doit = nl80211_set_mpath,
10482 .policy = nl80211_policy,
10483 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010484 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010485 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010486 },
10487 {
10488 .cmd = NL80211_CMD_NEW_MPATH,
10489 .doit = nl80211_new_mpath,
10490 .policy = nl80211_policy,
10491 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010492 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010493 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010494 },
10495 {
10496 .cmd = NL80211_CMD_DEL_MPATH,
10497 .doit = nl80211_del_mpath,
10498 .policy = nl80211_policy,
10499 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010500 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010501 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010502 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010503 {
10504 .cmd = NL80211_CMD_SET_BSS,
10505 .doit = nl80211_set_bss,
10506 .policy = nl80211_policy,
10507 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010508 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010509 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010510 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010511 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010512 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010513 .doit = nl80211_get_reg_do,
10514 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010515 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010516 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010517 /* can be retrieved by unprivileged users */
10518 },
10519 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010520 .cmd = NL80211_CMD_SET_REG,
10521 .doit = nl80211_set_reg,
10522 .policy = nl80211_policy,
10523 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010524 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010525 },
10526 {
10527 .cmd = NL80211_CMD_REQ_SET_REG,
10528 .doit = nl80211_req_set_reg,
10529 .policy = nl80211_policy,
10530 .flags = GENL_ADMIN_PERM,
10531 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010532 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010533 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10534 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010535 .policy = nl80211_policy,
10536 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010537 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010538 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010539 },
10540 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010541 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10542 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010543 .policy = nl80211_policy,
10544 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010545 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010546 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010547 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010548 {
Johannes Berg2a519312009-02-10 21:25:55 +010010549 .cmd = NL80211_CMD_TRIGGER_SCAN,
10550 .doit = nl80211_trigger_scan,
10551 .policy = nl80211_policy,
10552 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010553 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010554 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010555 },
10556 {
10557 .cmd = NL80211_CMD_GET_SCAN,
10558 .policy = nl80211_policy,
10559 .dumpit = nl80211_dump_scan,
10560 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010561 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010562 .cmd = NL80211_CMD_START_SCHED_SCAN,
10563 .doit = nl80211_start_sched_scan,
10564 .policy = nl80211_policy,
10565 .flags = GENL_ADMIN_PERM,
10566 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10567 NL80211_FLAG_NEED_RTNL,
10568 },
10569 {
10570 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10571 .doit = nl80211_stop_sched_scan,
10572 .policy = nl80211_policy,
10573 .flags = GENL_ADMIN_PERM,
10574 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10575 NL80211_FLAG_NEED_RTNL,
10576 },
10577 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010578 .cmd = NL80211_CMD_AUTHENTICATE,
10579 .doit = nl80211_authenticate,
10580 .policy = nl80211_policy,
10581 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010582 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010583 NL80211_FLAG_NEED_RTNL |
10584 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010585 },
10586 {
10587 .cmd = NL80211_CMD_ASSOCIATE,
10588 .doit = nl80211_associate,
10589 .policy = nl80211_policy,
10590 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010591 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010592 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010593 },
10594 {
10595 .cmd = NL80211_CMD_DEAUTHENTICATE,
10596 .doit = nl80211_deauthenticate,
10597 .policy = nl80211_policy,
10598 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010599 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010600 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010601 },
10602 {
10603 .cmd = NL80211_CMD_DISASSOCIATE,
10604 .doit = nl80211_disassociate,
10605 .policy = nl80211_policy,
10606 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010607 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010608 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010609 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010610 {
10611 .cmd = NL80211_CMD_JOIN_IBSS,
10612 .doit = nl80211_join_ibss,
10613 .policy = nl80211_policy,
10614 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010615 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010616 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010617 },
10618 {
10619 .cmd = NL80211_CMD_LEAVE_IBSS,
10620 .doit = nl80211_leave_ibss,
10621 .policy = nl80211_policy,
10622 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010623 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010624 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010625 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010626#ifdef CONFIG_NL80211_TESTMODE
10627 {
10628 .cmd = NL80211_CMD_TESTMODE,
10629 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010630 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010631 .policy = nl80211_policy,
10632 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010633 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10634 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010635 },
10636#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010637 {
10638 .cmd = NL80211_CMD_CONNECT,
10639 .doit = nl80211_connect,
10640 .policy = nl80211_policy,
10641 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010642 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010643 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010644 },
10645 {
10646 .cmd = NL80211_CMD_DISCONNECT,
10647 .doit = nl80211_disconnect,
10648 .policy = nl80211_policy,
10649 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010650 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010651 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010652 },
Johannes Berg463d0182009-07-14 00:33:35 +020010653 {
10654 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10655 .doit = nl80211_wiphy_netns,
10656 .policy = nl80211_policy,
10657 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010658 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10659 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010660 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010661 {
10662 .cmd = NL80211_CMD_GET_SURVEY,
10663 .policy = nl80211_policy,
10664 .dumpit = nl80211_dump_survey,
10665 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010666 {
10667 .cmd = NL80211_CMD_SET_PMKSA,
10668 .doit = nl80211_setdel_pmksa,
10669 .policy = nl80211_policy,
10670 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010671 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010672 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010673 },
10674 {
10675 .cmd = NL80211_CMD_DEL_PMKSA,
10676 .doit = nl80211_setdel_pmksa,
10677 .policy = nl80211_policy,
10678 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010679 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010680 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010681 },
10682 {
10683 .cmd = NL80211_CMD_FLUSH_PMKSA,
10684 .doit = nl80211_flush_pmksa,
10685 .policy = nl80211_policy,
10686 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010687 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010688 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010689 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010690 {
10691 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10692 .doit = nl80211_remain_on_channel,
10693 .policy = nl80211_policy,
10694 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010695 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010696 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010697 },
10698 {
10699 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10700 .doit = nl80211_cancel_remain_on_channel,
10701 .policy = nl80211_policy,
10702 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010703 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010704 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010705 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010706 {
10707 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10708 .doit = nl80211_set_tx_bitrate_mask,
10709 .policy = nl80211_policy,
10710 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010711 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10712 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010713 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010714 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010715 .cmd = NL80211_CMD_REGISTER_FRAME,
10716 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010717 .policy = nl80211_policy,
10718 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010719 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010720 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010721 },
10722 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010723 .cmd = NL80211_CMD_FRAME,
10724 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010725 .policy = nl80211_policy,
10726 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010727 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010728 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010729 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010730 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010731 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10732 .doit = nl80211_tx_mgmt_cancel_wait,
10733 .policy = nl80211_policy,
10734 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010735 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010736 NL80211_FLAG_NEED_RTNL,
10737 },
10738 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010739 .cmd = NL80211_CMD_SET_POWER_SAVE,
10740 .doit = nl80211_set_power_save,
10741 .policy = nl80211_policy,
10742 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010743 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10744 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010745 },
10746 {
10747 .cmd = NL80211_CMD_GET_POWER_SAVE,
10748 .doit = nl80211_get_power_save,
10749 .policy = nl80211_policy,
10750 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010751 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10752 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010753 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010754 {
10755 .cmd = NL80211_CMD_SET_CQM,
10756 .doit = nl80211_set_cqm,
10757 .policy = nl80211_policy,
10758 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010759 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10760 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010761 },
Johannes Bergf444de02010-05-05 15:25:02 +020010762 {
10763 .cmd = NL80211_CMD_SET_CHANNEL,
10764 .doit = nl80211_set_channel,
10765 .policy = nl80211_policy,
10766 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010767 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10768 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010769 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010770 {
10771 .cmd = NL80211_CMD_SET_WDS_PEER,
10772 .doit = nl80211_set_wds_peer,
10773 .policy = nl80211_policy,
10774 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010775 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10776 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010777 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010778 {
10779 .cmd = NL80211_CMD_JOIN_MESH,
10780 .doit = nl80211_join_mesh,
10781 .policy = nl80211_policy,
10782 .flags = GENL_ADMIN_PERM,
10783 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10784 NL80211_FLAG_NEED_RTNL,
10785 },
10786 {
10787 .cmd = NL80211_CMD_LEAVE_MESH,
10788 .doit = nl80211_leave_mesh,
10789 .policy = nl80211_policy,
10790 .flags = GENL_ADMIN_PERM,
10791 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10792 NL80211_FLAG_NEED_RTNL,
10793 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010794 {
10795 .cmd = NL80211_CMD_JOIN_OCB,
10796 .doit = nl80211_join_ocb,
10797 .policy = nl80211_policy,
10798 .flags = GENL_ADMIN_PERM,
10799 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10800 NL80211_FLAG_NEED_RTNL,
10801 },
10802 {
10803 .cmd = NL80211_CMD_LEAVE_OCB,
10804 .doit = nl80211_leave_ocb,
10805 .policy = nl80211_policy,
10806 .flags = GENL_ADMIN_PERM,
10807 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10808 NL80211_FLAG_NEED_RTNL,
10809 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010810#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010811 {
10812 .cmd = NL80211_CMD_GET_WOWLAN,
10813 .doit = nl80211_get_wowlan,
10814 .policy = nl80211_policy,
10815 /* can be retrieved by unprivileged users */
10816 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10817 NL80211_FLAG_NEED_RTNL,
10818 },
10819 {
10820 .cmd = NL80211_CMD_SET_WOWLAN,
10821 .doit = nl80211_set_wowlan,
10822 .policy = nl80211_policy,
10823 .flags = GENL_ADMIN_PERM,
10824 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10825 NL80211_FLAG_NEED_RTNL,
10826 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010827#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010828 {
10829 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10830 .doit = nl80211_set_rekey_data,
10831 .policy = nl80211_policy,
10832 .flags = GENL_ADMIN_PERM,
10833 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010834 NL80211_FLAG_NEED_RTNL |
10835 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010836 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010837 {
10838 .cmd = NL80211_CMD_TDLS_MGMT,
10839 .doit = nl80211_tdls_mgmt,
10840 .policy = nl80211_policy,
10841 .flags = GENL_ADMIN_PERM,
10842 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10843 NL80211_FLAG_NEED_RTNL,
10844 },
10845 {
10846 .cmd = NL80211_CMD_TDLS_OPER,
10847 .doit = nl80211_tdls_oper,
10848 .policy = nl80211_policy,
10849 .flags = GENL_ADMIN_PERM,
10850 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10851 NL80211_FLAG_NEED_RTNL,
10852 },
Johannes Berg28946da2011-11-04 11:18:12 +010010853 {
10854 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10855 .doit = nl80211_register_unexpected_frame,
10856 .policy = nl80211_policy,
10857 .flags = GENL_ADMIN_PERM,
10858 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10859 NL80211_FLAG_NEED_RTNL,
10860 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010861 {
10862 .cmd = NL80211_CMD_PROBE_CLIENT,
10863 .doit = nl80211_probe_client,
10864 .policy = nl80211_policy,
10865 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010866 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010867 NL80211_FLAG_NEED_RTNL,
10868 },
Johannes Berg5e760232011-11-04 11:18:17 +010010869 {
10870 .cmd = NL80211_CMD_REGISTER_BEACONS,
10871 .doit = nl80211_register_beacons,
10872 .policy = nl80211_policy,
10873 .flags = GENL_ADMIN_PERM,
10874 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10875 NL80211_FLAG_NEED_RTNL,
10876 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010877 {
10878 .cmd = NL80211_CMD_SET_NOACK_MAP,
10879 .doit = nl80211_set_noack_map,
10880 .policy = nl80211_policy,
10881 .flags = GENL_ADMIN_PERM,
10882 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10883 NL80211_FLAG_NEED_RTNL,
10884 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010885 {
10886 .cmd = NL80211_CMD_START_P2P_DEVICE,
10887 .doit = nl80211_start_p2p_device,
10888 .policy = nl80211_policy,
10889 .flags = GENL_ADMIN_PERM,
10890 .internal_flags = NL80211_FLAG_NEED_WDEV |
10891 NL80211_FLAG_NEED_RTNL,
10892 },
10893 {
10894 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10895 .doit = nl80211_stop_p2p_device,
10896 .policy = nl80211_policy,
10897 .flags = GENL_ADMIN_PERM,
10898 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10899 NL80211_FLAG_NEED_RTNL,
10900 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010901 {
10902 .cmd = NL80211_CMD_SET_MCAST_RATE,
10903 .doit = nl80211_set_mcast_rate,
10904 .policy = nl80211_policy,
10905 .flags = GENL_ADMIN_PERM,
10906 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10907 NL80211_FLAG_NEED_RTNL,
10908 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010909 {
10910 .cmd = NL80211_CMD_SET_MAC_ACL,
10911 .doit = nl80211_set_mac_acl,
10912 .policy = nl80211_policy,
10913 .flags = GENL_ADMIN_PERM,
10914 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10915 NL80211_FLAG_NEED_RTNL,
10916 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010917 {
10918 .cmd = NL80211_CMD_RADAR_DETECT,
10919 .doit = nl80211_start_radar_detection,
10920 .policy = nl80211_policy,
10921 .flags = GENL_ADMIN_PERM,
10922 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10923 NL80211_FLAG_NEED_RTNL,
10924 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010925 {
10926 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10927 .doit = nl80211_get_protocol_features,
10928 .policy = nl80211_policy,
10929 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010930 {
10931 .cmd = NL80211_CMD_UPDATE_FT_IES,
10932 .doit = nl80211_update_ft_ies,
10933 .policy = nl80211_policy,
10934 .flags = GENL_ADMIN_PERM,
10935 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10936 NL80211_FLAG_NEED_RTNL,
10937 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010938 {
10939 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10940 .doit = nl80211_crit_protocol_start,
10941 .policy = nl80211_policy,
10942 .flags = GENL_ADMIN_PERM,
10943 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10944 NL80211_FLAG_NEED_RTNL,
10945 },
10946 {
10947 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10948 .doit = nl80211_crit_protocol_stop,
10949 .policy = nl80211_policy,
10950 .flags = GENL_ADMIN_PERM,
10951 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10952 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b99a2013-06-28 11:51:26 -070010953 },
10954 {
10955 .cmd = NL80211_CMD_GET_COALESCE,
10956 .doit = nl80211_get_coalesce,
10957 .policy = nl80211_policy,
10958 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10959 NL80211_FLAG_NEED_RTNL,
10960 },
10961 {
10962 .cmd = NL80211_CMD_SET_COALESCE,
10963 .doit = nl80211_set_coalesce,
10964 .policy = nl80211_policy,
10965 .flags = GENL_ADMIN_PERM,
10966 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10967 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010968 },
10969 {
10970 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10971 .doit = nl80211_channel_switch,
10972 .policy = nl80211_policy,
10973 .flags = GENL_ADMIN_PERM,
10974 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10975 NL80211_FLAG_NEED_RTNL,
10976 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010977 {
10978 .cmd = NL80211_CMD_VENDOR,
10979 .doit = nl80211_vendor_cmd,
10980 .policy = nl80211_policy,
10981 .flags = GENL_ADMIN_PERM,
10982 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10983 NL80211_FLAG_NEED_RTNL,
10984 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080010985 {
10986 .cmd = NL80211_CMD_SET_QOS_MAP,
10987 .doit = nl80211_set_qos_map,
10988 .policy = nl80211_policy,
10989 .flags = GENL_ADMIN_PERM,
10990 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10991 NL80211_FLAG_NEED_RTNL,
10992 },
Johannes Berg960d01a2014-09-09 22:55:35 +030010993 {
10994 .cmd = NL80211_CMD_ADD_TX_TS,
10995 .doit = nl80211_add_tx_ts,
10996 .policy = nl80211_policy,
10997 .flags = GENL_ADMIN_PERM,
10998 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10999 NL80211_FLAG_NEED_RTNL,
11000 },
11001 {
11002 .cmd = NL80211_CMD_DEL_TX_TS,
11003 .doit = nl80211_del_tx_ts,
11004 .policy = nl80211_policy,
11005 .flags = GENL_ADMIN_PERM,
11006 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11007 NL80211_FLAG_NEED_RTNL,
11008 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011009 {
11010 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11011 .doit = nl80211_tdls_channel_switch,
11012 .policy = nl80211_policy,
11013 .flags = GENL_ADMIN_PERM,
11014 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11015 NL80211_FLAG_NEED_RTNL,
11016 },
11017 {
11018 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11019 .doit = nl80211_tdls_cancel_channel_switch,
11020 .policy = nl80211_policy,
11021 .flags = GENL_ADMIN_PERM,
11022 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11023 NL80211_FLAG_NEED_RTNL,
11024 },
Johannes Berg55682962007-09-20 13:09:35 -040011025};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011026
Johannes Berg55682962007-09-20 13:09:35 -040011027/* notification functions */
11028
Johannes Berg3bb20552014-05-26 13:52:25 +020011029void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11030 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011031{
11032 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011033 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011034
Johannes Berg3bb20552014-05-26 13:52:25 +020011035 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11036 cmd != NL80211_CMD_DEL_WIPHY);
11037
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011038 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011039 if (!msg)
11040 return;
11041
Johannes Berg3bb20552014-05-26 13:52:25 +020011042 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011043 nlmsg_free(msg);
11044 return;
11045 }
11046
Johannes Berg68eb5502013-11-19 15:19:38 +010011047 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011048 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011049}
11050
Johannes Berg362a4152009-05-24 16:43:15 +020011051static int nl80211_add_scan_req(struct sk_buff *msg,
11052 struct cfg80211_registered_device *rdev)
11053{
11054 struct cfg80211_scan_request *req = rdev->scan_req;
11055 struct nlattr *nest;
11056 int i;
11057
11058 if (WARN_ON(!req))
11059 return 0;
11060
11061 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11062 if (!nest)
11063 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011064 for (i = 0; i < req->n_ssids; i++) {
11065 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11066 goto nla_put_failure;
11067 }
Johannes Berg362a4152009-05-24 16:43:15 +020011068 nla_nest_end(msg, nest);
11069
11070 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11071 if (!nest)
11072 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011073 for (i = 0; i < req->n_channels; i++) {
11074 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11075 goto nla_put_failure;
11076 }
Johannes Berg362a4152009-05-24 16:43:15 +020011077 nla_nest_end(msg, nest);
11078
David S. Miller9360ffd2012-03-29 04:41:26 -040011079 if (req->ie &&
11080 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11081 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011082
Johannes Bergae917c92013-10-25 11:05:22 +020011083 if (req->flags &&
11084 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11085 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011086
Johannes Berg362a4152009-05-24 16:43:15 +020011087 return 0;
11088 nla_put_failure:
11089 return -ENOBUFS;
11090}
11091
Johannes Berga538e2d2009-06-16 19:56:42 +020011092static int nl80211_send_scan_msg(struct sk_buff *msg,
11093 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011094 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011095 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011096 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011097{
11098 void *hdr;
11099
Eric W. Biederman15e47302012-09-07 20:12:54 +000011100 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011101 if (!hdr)
11102 return -1;
11103
David S. Miller9360ffd2012-03-29 04:41:26 -040011104 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011105 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11106 wdev->netdev->ifindex)) ||
11107 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011108 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011109
Johannes Berg362a4152009-05-24 16:43:15 +020011110 /* ignore errors and send incomplete event anyway */
11111 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011112
Johannes Berg053c0952015-01-16 22:09:00 +010011113 genlmsg_end(msg, hdr);
11114 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011115
11116 nla_put_failure:
11117 genlmsg_cancel(msg, hdr);
11118 return -EMSGSIZE;
11119}
11120
Luciano Coelho807f8a82011-05-11 17:09:35 +030011121static int
11122nl80211_send_sched_scan_msg(struct sk_buff *msg,
11123 struct cfg80211_registered_device *rdev,
11124 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011125 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011126{
11127 void *hdr;
11128
Eric W. Biederman15e47302012-09-07 20:12:54 +000011129 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011130 if (!hdr)
11131 return -1;
11132
David S. Miller9360ffd2012-03-29 04:41:26 -040011133 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11134 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11135 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011136
Johannes Berg053c0952015-01-16 22:09:00 +010011137 genlmsg_end(msg, hdr);
11138 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011139
11140 nla_put_failure:
11141 genlmsg_cancel(msg, hdr);
11142 return -EMSGSIZE;
11143}
11144
Johannes Berga538e2d2009-06-16 19:56:42 +020011145void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011146 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011147{
11148 struct sk_buff *msg;
11149
Thomas Graf58050fc2012-06-28 03:57:45 +000011150 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011151 if (!msg)
11152 return;
11153
Johannes Bergfd014282012-06-18 19:17:03 +020011154 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011155 NL80211_CMD_TRIGGER_SCAN) < 0) {
11156 nlmsg_free(msg);
11157 return;
11158 }
11159
Johannes Berg68eb5502013-11-19 15:19:38 +010011160 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011161 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011162}
11163
Johannes Bergf9d15d12014-01-22 11:14:19 +020011164struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11165 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011166{
11167 struct sk_buff *msg;
11168
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011169 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011170 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011171 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011172
Johannes Bergfd014282012-06-18 19:17:03 +020011173 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011174 aborted ? NL80211_CMD_SCAN_ABORTED :
11175 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011176 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011177 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011178 }
11179
Johannes Bergf9d15d12014-01-22 11:14:19 +020011180 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011181}
11182
Johannes Bergf9d15d12014-01-22 11:14:19 +020011183void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11184 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011185{
Johannes Berg2a519312009-02-10 21:25:55 +010011186 if (!msg)
11187 return;
11188
Johannes Berg68eb5502013-11-19 15:19:38 +010011189 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011190 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011191}
11192
Luciano Coelho807f8a82011-05-11 17:09:35 +030011193void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11194 struct net_device *netdev)
11195{
11196 struct sk_buff *msg;
11197
11198 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11199 if (!msg)
11200 return;
11201
11202 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11203 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11204 nlmsg_free(msg);
11205 return;
11206 }
11207
Johannes Berg68eb5502013-11-19 15:19:38 +010011208 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011209 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011210}
11211
11212void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11213 struct net_device *netdev, u32 cmd)
11214{
11215 struct sk_buff *msg;
11216
Thomas Graf58050fc2012-06-28 03:57:45 +000011217 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011218 if (!msg)
11219 return;
11220
11221 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11222 nlmsg_free(msg);
11223 return;
11224 }
11225
Johannes Berg68eb5502013-11-19 15:19:38 +010011226 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011227 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011228}
11229
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011230static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11231 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011232{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011233 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011234 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11235 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011236
David S. Miller9360ffd2012-03-29 04:41:26 -040011237 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11238 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11239 NL80211_REGDOM_TYPE_WORLD))
11240 goto nla_put_failure;
11241 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11242 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11243 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11244 goto nla_put_failure;
11245 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11246 request->intersect) {
11247 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11248 NL80211_REGDOM_TYPE_INTERSECTION))
11249 goto nla_put_failure;
11250 } else {
11251 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11252 NL80211_REGDOM_TYPE_COUNTRY) ||
11253 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11254 request->alpha2))
11255 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011256 }
11257
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011258 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11259 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11260
11261 if (wiphy &&
11262 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11263 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011264
11265 if (wiphy &&
11266 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11267 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11268 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011269 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011270
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011271 return true;
11272
11273nla_put_failure:
11274 return false;
11275}
11276
11277/*
11278 * This can happen on global regulatory changes or device specific settings
11279 * based on custom regulatory domains.
11280 */
11281void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11282 struct regulatory_request *request)
11283{
11284 struct sk_buff *msg;
11285 void *hdr;
11286
11287 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11288 if (!msg)
11289 return;
11290
11291 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11292 if (!hdr) {
11293 nlmsg_free(msg);
11294 return;
11295 }
11296
11297 if (nl80211_reg_change_event_fill(msg, request) == false)
11298 goto nla_put_failure;
11299
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011300 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011301
Johannes Bergbc43b282009-07-25 10:54:13 +020011302 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011303 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011304 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011305 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011306
11307 return;
11308
11309nla_put_failure:
11310 genlmsg_cancel(msg, hdr);
11311 nlmsg_free(msg);
11312}
11313
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011314static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11315 struct net_device *netdev,
11316 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011317 enum nl80211_commands cmd, gfp_t gfp,
11318 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011319{
11320 struct sk_buff *msg;
11321 void *hdr;
11322
Johannes Berge6d6e342009-07-01 21:26:47 +020011323 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011324 if (!msg)
11325 return;
11326
11327 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11328 if (!hdr) {
11329 nlmsg_free(msg);
11330 return;
11331 }
11332
David S. Miller9360ffd2012-03-29 04:41:26 -040011333 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11334 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11335 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11336 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011337
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011338 if (uapsd_queues >= 0) {
11339 struct nlattr *nla_wmm =
11340 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11341 if (!nla_wmm)
11342 goto nla_put_failure;
11343
11344 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11345 uapsd_queues))
11346 goto nla_put_failure;
11347
11348 nla_nest_end(msg, nla_wmm);
11349 }
11350
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011351 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011352
Johannes Berg68eb5502013-11-19 15:19:38 +010011353 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011354 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011355 return;
11356
11357 nla_put_failure:
11358 genlmsg_cancel(msg, hdr);
11359 nlmsg_free(msg);
11360}
11361
11362void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011363 struct net_device *netdev, const u8 *buf,
11364 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011365{
11366 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011367 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011368}
11369
11370void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11371 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011372 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011373{
Johannes Berge6d6e342009-07-01 21:26:47 +020011374 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011375 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011376}
11377
Jouni Malinen53b46b82009-03-27 20:53:56 +020011378void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011379 struct net_device *netdev, const u8 *buf,
11380 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011381{
11382 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011383 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011384}
11385
Jouni Malinen53b46b82009-03-27 20:53:56 +020011386void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11387 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011388 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011389{
11390 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011391 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011392}
11393
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011394void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11395 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011396{
Johannes Berg947add32013-02-22 22:05:20 +010011397 struct wireless_dev *wdev = dev->ieee80211_ptr;
11398 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011399 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011400 const struct ieee80211_mgmt *mgmt = (void *)buf;
11401 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011402
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011403 if (WARN_ON(len < 2))
11404 return;
11405
11406 if (ieee80211_is_deauth(mgmt->frame_control))
11407 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11408 else
11409 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11410
11411 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011412 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011413}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011414EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011415
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011416static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11417 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011418 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011419{
11420 struct sk_buff *msg;
11421 void *hdr;
11422
Johannes Berge6d6e342009-07-01 21:26:47 +020011423 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011424 if (!msg)
11425 return;
11426
11427 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11428 if (!hdr) {
11429 nlmsg_free(msg);
11430 return;
11431 }
11432
David S. Miller9360ffd2012-03-29 04:41:26 -040011433 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11434 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11435 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11436 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11437 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011438
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011439 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011440
Johannes Berg68eb5502013-11-19 15:19:38 +010011441 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011442 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011443 return;
11444
11445 nla_put_failure:
11446 genlmsg_cancel(msg, hdr);
11447 nlmsg_free(msg);
11448}
11449
11450void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011451 struct net_device *netdev, const u8 *addr,
11452 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011453{
11454 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011455 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011456}
11457
11458void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011459 struct net_device *netdev, const u8 *addr,
11460 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011461{
Johannes Berge6d6e342009-07-01 21:26:47 +020011462 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11463 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011464}
11465
Samuel Ortizb23aa672009-07-01 21:26:54 +020011466void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11467 struct net_device *netdev, const u8 *bssid,
11468 const u8 *req_ie, size_t req_ie_len,
11469 const u8 *resp_ie, size_t resp_ie_len,
11470 u16 status, gfp_t gfp)
11471{
11472 struct sk_buff *msg;
11473 void *hdr;
11474
Thomas Graf58050fc2012-06-28 03:57:45 +000011475 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011476 if (!msg)
11477 return;
11478
11479 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11480 if (!hdr) {
11481 nlmsg_free(msg);
11482 return;
11483 }
11484
David S. Miller9360ffd2012-03-29 04:41:26 -040011485 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11486 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11487 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11488 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11489 (req_ie &&
11490 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11491 (resp_ie &&
11492 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11493 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011494
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011495 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011496
Johannes Berg68eb5502013-11-19 15:19:38 +010011497 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011498 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011499 return;
11500
11501 nla_put_failure:
11502 genlmsg_cancel(msg, hdr);
11503 nlmsg_free(msg);
11504
11505}
11506
11507void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11508 struct net_device *netdev, const u8 *bssid,
11509 const u8 *req_ie, size_t req_ie_len,
11510 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11511{
11512 struct sk_buff *msg;
11513 void *hdr;
11514
Thomas Graf58050fc2012-06-28 03:57:45 +000011515 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011516 if (!msg)
11517 return;
11518
11519 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11520 if (!hdr) {
11521 nlmsg_free(msg);
11522 return;
11523 }
11524
David S. Miller9360ffd2012-03-29 04:41:26 -040011525 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11526 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11527 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11528 (req_ie &&
11529 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11530 (resp_ie &&
11531 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11532 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011533
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011534 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011535
Johannes Berg68eb5502013-11-19 15:19:38 +010011536 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011537 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011538 return;
11539
11540 nla_put_failure:
11541 genlmsg_cancel(msg, hdr);
11542 nlmsg_free(msg);
11543
11544}
11545
11546void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11547 struct net_device *netdev, u16 reason,
Johannes Berg667503d2009-07-07 03:56:11 +020011548 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011549{
11550 struct sk_buff *msg;
11551 void *hdr;
11552
Thomas Graf58050fc2012-06-28 03:57:45 +000011553 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011554 if (!msg)
11555 return;
11556
11557 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11558 if (!hdr) {
11559 nlmsg_free(msg);
11560 return;
11561 }
11562
David S. Miller9360ffd2012-03-29 04:41:26 -040011563 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11564 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11565 (from_ap && reason &&
11566 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11567 (from_ap &&
11568 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11569 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11570 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011571
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011572 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011573
Johannes Berg68eb5502013-11-19 15:19:38 +010011574 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011575 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011576 return;
11577
11578 nla_put_failure:
11579 genlmsg_cancel(msg, hdr);
11580 nlmsg_free(msg);
11581
11582}
11583
Johannes Berg04a773a2009-04-19 21:24:32 +020011584void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11585 struct net_device *netdev, const u8 *bssid,
11586 gfp_t gfp)
11587{
11588 struct sk_buff *msg;
11589 void *hdr;
11590
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011591 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011592 if (!msg)
11593 return;
11594
11595 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11596 if (!hdr) {
11597 nlmsg_free(msg);
11598 return;
11599 }
11600
David S. Miller9360ffd2012-03-29 04:41:26 -040011601 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11602 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11603 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11604 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011605
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011606 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011607
Johannes Berg68eb5502013-11-19 15:19:38 +010011608 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011609 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011610 return;
11611
11612 nla_put_failure:
11613 genlmsg_cancel(msg, hdr);
11614 nlmsg_free(msg);
11615}
11616
Johannes Berg947add32013-02-22 22:05:20 +010011617void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11618 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011619{
Johannes Berg947add32013-02-22 22:05:20 +010011620 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011621 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011622 struct sk_buff *msg;
11623 void *hdr;
11624
Johannes Berg947add32013-02-22 22:05:20 +010011625 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11626 return;
11627
11628 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11629
Javier Cardonac93b5e72011-04-07 15:08:34 -070011630 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11631 if (!msg)
11632 return;
11633
11634 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11635 if (!hdr) {
11636 nlmsg_free(msg);
11637 return;
11638 }
11639
David S. Miller9360ffd2012-03-29 04:41:26 -040011640 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011641 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11642 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011643 (ie_len && ie &&
11644 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11645 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011646
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011647 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011648
Johannes Berg68eb5502013-11-19 15:19:38 +010011649 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011650 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011651 return;
11652
11653 nla_put_failure:
11654 genlmsg_cancel(msg, hdr);
11655 nlmsg_free(msg);
11656}
Johannes Berg947add32013-02-22 22:05:20 +010011657EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011658
Jouni Malinena3b8b052009-03-27 21:59:49 +020011659void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11660 struct net_device *netdev, const u8 *addr,
11661 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011662 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011663{
11664 struct sk_buff *msg;
11665 void *hdr;
11666
Johannes Berge6d6e342009-07-01 21:26:47 +020011667 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011668 if (!msg)
11669 return;
11670
11671 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11672 if (!hdr) {
11673 nlmsg_free(msg);
11674 return;
11675 }
11676
David S. Miller9360ffd2012-03-29 04:41:26 -040011677 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11678 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11679 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11680 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11681 (key_id != -1 &&
11682 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11683 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11684 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011685
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011686 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011687
Johannes Berg68eb5502013-11-19 15:19:38 +010011688 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011689 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011690 return;
11691
11692 nla_put_failure:
11693 genlmsg_cancel(msg, hdr);
11694 nlmsg_free(msg);
11695}
11696
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011697void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11698 struct ieee80211_channel *channel_before,
11699 struct ieee80211_channel *channel_after)
11700{
11701 struct sk_buff *msg;
11702 void *hdr;
11703 struct nlattr *nl_freq;
11704
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011705 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011706 if (!msg)
11707 return;
11708
11709 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11710 if (!hdr) {
11711 nlmsg_free(msg);
11712 return;
11713 }
11714
11715 /*
11716 * Since we are applying the beacon hint to a wiphy we know its
11717 * wiphy_idx is valid
11718 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011719 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11720 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011721
11722 /* Before */
11723 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11724 if (!nl_freq)
11725 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011726 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011727 goto nla_put_failure;
11728 nla_nest_end(msg, nl_freq);
11729
11730 /* After */
11731 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11732 if (!nl_freq)
11733 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011734 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011735 goto nla_put_failure;
11736 nla_nest_end(msg, nl_freq);
11737
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011738 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011739
Johannes Berg463d0182009-07-14 00:33:35 +020011740 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011741 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011742 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011743 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011744
11745 return;
11746
11747nla_put_failure:
11748 genlmsg_cancel(msg, hdr);
11749 nlmsg_free(msg);
11750}
11751
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011752static void nl80211_send_remain_on_chan_event(
11753 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011754 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011755 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011756 unsigned int duration, gfp_t gfp)
11757{
11758 struct sk_buff *msg;
11759 void *hdr;
11760
11761 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11762 if (!msg)
11763 return;
11764
11765 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11766 if (!hdr) {
11767 nlmsg_free(msg);
11768 return;
11769 }
11770
David S. Miller9360ffd2012-03-29 04:41:26 -040011771 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011772 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11773 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011774 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011775 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011776 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11777 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011778 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11779 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011780
David S. Miller9360ffd2012-03-29 04:41:26 -040011781 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11782 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11783 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011784
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011785 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011786
Johannes Berg68eb5502013-11-19 15:19:38 +010011787 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011788 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011789 return;
11790
11791 nla_put_failure:
11792 genlmsg_cancel(msg, hdr);
11793 nlmsg_free(msg);
11794}
11795
Johannes Berg947add32013-02-22 22:05:20 +010011796void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11797 struct ieee80211_channel *chan,
11798 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011799{
Johannes Berg947add32013-02-22 22:05:20 +010011800 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011801 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011802
11803 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011804 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011805 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011806 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011807}
Johannes Berg947add32013-02-22 22:05:20 +010011808EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011809
Johannes Berg947add32013-02-22 22:05:20 +010011810void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11811 struct ieee80211_channel *chan,
11812 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011813{
Johannes Berg947add32013-02-22 22:05:20 +010011814 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011815 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011816
11817 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011818 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011819 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011820}
Johannes Berg947add32013-02-22 22:05:20 +010011821EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011822
Johannes Berg947add32013-02-22 22:05:20 +010011823void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11824 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011825{
Johannes Berg947add32013-02-22 22:05:20 +010011826 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011827 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011828 struct sk_buff *msg;
11829
Johannes Berg947add32013-02-22 22:05:20 +010011830 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11831
Thomas Graf58050fc2012-06-28 03:57:45 +000011832 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011833 if (!msg)
11834 return;
11835
Johannes Bergcf5ead82014-11-14 17:14:00 +010011836 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040011837 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011838 nlmsg_free(msg);
11839 return;
11840 }
11841
Johannes Berg68eb5502013-11-19 15:19:38 +010011842 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011843 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011844}
Johannes Berg947add32013-02-22 22:05:20 +010011845EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011846
Johannes Bergcf5ead82014-11-14 17:14:00 +010011847void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
11848 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011849{
Johannes Berg947add32013-02-22 22:05:20 +010011850 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011851 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011852 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010011853 struct station_info empty_sinfo = {};
11854
11855 if (!sinfo)
11856 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020011857
Johannes Berg947add32013-02-22 22:05:20 +010011858 trace_cfg80211_del_sta(dev, mac_addr);
11859
Thomas Graf58050fc2012-06-28 03:57:45 +000011860 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011861 if (!msg)
11862 return;
11863
Johannes Bergcf5ead82014-11-14 17:14:00 +010011864 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010011865 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020011866 nlmsg_free(msg);
11867 return;
11868 }
11869
Johannes Berg68eb5502013-11-19 15:19:38 +010011870 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011871 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011872}
Johannes Bergcf5ead82014-11-14 17:14:00 +010011873EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020011874
Johannes Berg947add32013-02-22 22:05:20 +010011875void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11876 enum nl80211_connect_failed_reason reason,
11877 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011878{
Johannes Berg947add32013-02-22 22:05:20 +010011879 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011880 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011881 struct sk_buff *msg;
11882 void *hdr;
11883
11884 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11885 if (!msg)
11886 return;
11887
11888 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11889 if (!hdr) {
11890 nlmsg_free(msg);
11891 return;
11892 }
11893
11894 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11895 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11896 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11897 goto nla_put_failure;
11898
11899 genlmsg_end(msg, hdr);
11900
Johannes Berg68eb5502013-11-19 15:19:38 +010011901 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011902 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011903 return;
11904
11905 nla_put_failure:
11906 genlmsg_cancel(msg, hdr);
11907 nlmsg_free(msg);
11908}
Johannes Berg947add32013-02-22 22:05:20 +010011909EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011910
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011911static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11912 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011913{
11914 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011915 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011916 struct sk_buff *msg;
11917 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011918 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011919
Eric W. Biederman15e47302012-09-07 20:12:54 +000011920 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011921 return false;
11922
11923 msg = nlmsg_new(100, gfp);
11924 if (!msg)
11925 return true;
11926
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011927 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011928 if (!hdr) {
11929 nlmsg_free(msg);
11930 return true;
11931 }
11932
David S. Miller9360ffd2012-03-29 04:41:26 -040011933 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11934 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11935 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11936 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011937
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011938 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011939 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011940 return true;
11941
11942 nla_put_failure:
11943 genlmsg_cancel(msg, hdr);
11944 nlmsg_free(msg);
11945 return true;
11946}
11947
Johannes Berg947add32013-02-22 22:05:20 +010011948bool cfg80211_rx_spurious_frame(struct net_device *dev,
11949 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011950{
Johannes Berg947add32013-02-22 22:05:20 +010011951 struct wireless_dev *wdev = dev->ieee80211_ptr;
11952 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011953
Johannes Berg947add32013-02-22 22:05:20 +010011954 trace_cfg80211_rx_spurious_frame(dev, addr);
11955
11956 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11957 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11958 trace_cfg80211_return_bool(false);
11959 return false;
11960 }
11961 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11962 addr, gfp);
11963 trace_cfg80211_return_bool(ret);
11964 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011965}
Johannes Berg947add32013-02-22 22:05:20 +010011966EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11967
11968bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11969 const u8 *addr, gfp_t gfp)
11970{
11971 struct wireless_dev *wdev = dev->ieee80211_ptr;
11972 bool ret;
11973
11974 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11975
11976 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11977 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11978 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11979 trace_cfg80211_return_bool(false);
11980 return false;
11981 }
11982 ret = __nl80211_unexpected_frame(dev,
11983 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11984 addr, gfp);
11985 trace_cfg80211_return_bool(ret);
11986 return ret;
11987}
11988EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011989
Johannes Berg2e161f72010-08-12 15:38:38 +020011990int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011991 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010011992 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030011993 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020011994{
Johannes Berg71bbc992012-06-15 15:30:18 +020011995 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020011996 struct sk_buff *msg;
11997 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020011998
11999 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12000 if (!msg)
12001 return -ENOMEM;
12002
Johannes Berg2e161f72010-08-12 15:38:38 +020012003 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012004 if (!hdr) {
12005 nlmsg_free(msg);
12006 return -ENOMEM;
12007 }
12008
David S. Miller9360ffd2012-03-29 04:41:26 -040012009 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012010 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12011 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012012 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012013 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12014 (sig_dbm &&
12015 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012016 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12017 (flags &&
12018 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012019 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012020
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012021 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012022
Eric W. Biederman15e47302012-09-07 20:12:54 +000012023 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012024
12025 nla_put_failure:
12026 genlmsg_cancel(msg, hdr);
12027 nlmsg_free(msg);
12028 return -ENOBUFS;
12029}
12030
Johannes Berg947add32013-02-22 22:05:20 +010012031void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12032 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012033{
Johannes Berg947add32013-02-22 22:05:20 +010012034 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012035 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012036 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012037 struct sk_buff *msg;
12038 void *hdr;
12039
Johannes Berg947add32013-02-22 22:05:20 +010012040 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12041
Jouni Malinen026331c2010-02-15 12:53:10 +020012042 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12043 if (!msg)
12044 return;
12045
Johannes Berg2e161f72010-08-12 15:38:38 +020012046 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012047 if (!hdr) {
12048 nlmsg_free(msg);
12049 return;
12050 }
12051
David S. Miller9360ffd2012-03-29 04:41:26 -040012052 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012053 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12054 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012055 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012056 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12057 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12058 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12059 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012060
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012061 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012062
Johannes Berg68eb5502013-11-19 15:19:38 +010012063 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012064 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012065 return;
12066
12067 nla_put_failure:
12068 genlmsg_cancel(msg, hdr);
12069 nlmsg_free(msg);
12070}
Johannes Berg947add32013-02-22 22:05:20 +010012071EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012072
Johannes Berg5b97f492014-11-26 12:37:43 +010012073static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12074 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012075{
Johannes Berg947add32013-02-22 22:05:20 +010012076 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012077 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12078 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12079 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012080
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012081 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012082 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012083
Johannes Berg5b97f492014-11-26 12:37:43 +010012084 cb = (void **)msg->cb;
12085
12086 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12087 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012088 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012089 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012090 }
12091
David S. Miller9360ffd2012-03-29 04:41:26 -040012092 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012093 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012094 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012095
Johannes Berg5b97f492014-11-26 12:37:43 +010012096 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012097 goto nla_put_failure;
12098
Johannes Berg5b97f492014-11-26 12:37:43 +010012099 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12100 if (!cb[1])
12101 goto nla_put_failure;
12102
12103 cb[2] = rdev;
12104
12105 return msg;
12106 nla_put_failure:
12107 nlmsg_free(msg);
12108 return NULL;
12109}
12110
12111static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12112{
12113 void **cb = (void **)msg->cb;
12114 struct cfg80211_registered_device *rdev = cb[2];
12115
12116 nla_nest_end(msg, cb[1]);
12117 genlmsg_end(msg, cb[0]);
12118
12119 memset(msg->cb, 0, sizeof(msg->cb));
12120
12121 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12122 NL80211_MCGRP_MLME, gfp);
12123}
12124
12125void cfg80211_cqm_rssi_notify(struct net_device *dev,
12126 enum nl80211_cqm_rssi_threshold_event rssi_event,
12127 gfp_t gfp)
12128{
12129 struct sk_buff *msg;
12130
12131 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12132
Johannes Berg98f03342014-11-26 12:42:02 +010012133 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12134 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12135 return;
12136
Johannes Berg5b97f492014-11-26 12:37:43 +010012137 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12138 if (!msg)
12139 return;
12140
David S. Miller9360ffd2012-03-29 04:41:26 -040012141 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12142 rssi_event))
12143 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012144
Johannes Berg5b97f492014-11-26 12:37:43 +010012145 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012146
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012147 return;
12148
12149 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012150 nlmsg_free(msg);
12151}
Johannes Berg947add32013-02-22 22:05:20 +010012152EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012153
Johannes Berg5b97f492014-11-26 12:37:43 +010012154void cfg80211_cqm_txe_notify(struct net_device *dev,
12155 const u8 *peer, u32 num_packets,
12156 u32 rate, u32 intvl, gfp_t gfp)
12157{
12158 struct sk_buff *msg;
12159
12160 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12161 if (!msg)
12162 return;
12163
12164 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12165 goto nla_put_failure;
12166
12167 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12168 goto nla_put_failure;
12169
12170 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12171 goto nla_put_failure;
12172
12173 cfg80211_send_cqm(msg, gfp);
12174 return;
12175
12176 nla_put_failure:
12177 nlmsg_free(msg);
12178}
12179EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12180
12181void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12182 const u8 *peer, u32 num_packets, gfp_t gfp)
12183{
12184 struct sk_buff *msg;
12185
12186 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12187
12188 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12189 if (!msg)
12190 return;
12191
12192 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12193 goto nla_put_failure;
12194
12195 cfg80211_send_cqm(msg, gfp);
12196 return;
12197
12198 nla_put_failure:
12199 nlmsg_free(msg);
12200}
12201EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12202
Johannes Berg98f03342014-11-26 12:42:02 +010012203void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12204{
12205 struct sk_buff *msg;
12206
12207 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12208 if (!msg)
12209 return;
12210
12211 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12212 goto nla_put_failure;
12213
12214 cfg80211_send_cqm(msg, gfp);
12215 return;
12216
12217 nla_put_failure:
12218 nlmsg_free(msg);
12219}
12220EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12221
Johannes Berg947add32013-02-22 22:05:20 +010012222static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12223 struct net_device *netdev, const u8 *bssid,
12224 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012225{
12226 struct sk_buff *msg;
12227 struct nlattr *rekey_attr;
12228 void *hdr;
12229
Thomas Graf58050fc2012-06-28 03:57:45 +000012230 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012231 if (!msg)
12232 return;
12233
12234 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12235 if (!hdr) {
12236 nlmsg_free(msg);
12237 return;
12238 }
12239
David S. Miller9360ffd2012-03-29 04:41:26 -040012240 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12241 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12242 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12243 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012244
12245 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12246 if (!rekey_attr)
12247 goto nla_put_failure;
12248
David S. Miller9360ffd2012-03-29 04:41:26 -040012249 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12250 NL80211_REPLAY_CTR_LEN, replay_ctr))
12251 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012252
12253 nla_nest_end(msg, rekey_attr);
12254
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012255 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012256
Johannes Berg68eb5502013-11-19 15:19:38 +010012257 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012258 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012259 return;
12260
12261 nla_put_failure:
12262 genlmsg_cancel(msg, hdr);
12263 nlmsg_free(msg);
12264}
12265
Johannes Berg947add32013-02-22 22:05:20 +010012266void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12267 const u8 *replay_ctr, gfp_t gfp)
12268{
12269 struct wireless_dev *wdev = dev->ieee80211_ptr;
12270 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012271 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012272
12273 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12274 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12275}
12276EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12277
12278static void
12279nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12280 struct net_device *netdev, int index,
12281 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012282{
12283 struct sk_buff *msg;
12284 struct nlattr *attr;
12285 void *hdr;
12286
Thomas Graf58050fc2012-06-28 03:57:45 +000012287 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012288 if (!msg)
12289 return;
12290
12291 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12292 if (!hdr) {
12293 nlmsg_free(msg);
12294 return;
12295 }
12296
David S. Miller9360ffd2012-03-29 04:41:26 -040012297 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12298 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12299 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012300
12301 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12302 if (!attr)
12303 goto nla_put_failure;
12304
David S. Miller9360ffd2012-03-29 04:41:26 -040012305 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12306 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12307 (preauth &&
12308 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12309 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012310
12311 nla_nest_end(msg, attr);
12312
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012313 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012314
Johannes Berg68eb5502013-11-19 15:19:38 +010012315 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012316 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012317 return;
12318
12319 nla_put_failure:
12320 genlmsg_cancel(msg, hdr);
12321 nlmsg_free(msg);
12322}
12323
Johannes Berg947add32013-02-22 22:05:20 +010012324void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12325 const u8 *bssid, bool preauth, gfp_t gfp)
12326{
12327 struct wireless_dev *wdev = dev->ieee80211_ptr;
12328 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012329 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012330
12331 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12332 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12333}
12334EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12335
12336static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12337 struct net_device *netdev,
12338 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012339 gfp_t gfp,
12340 enum nl80211_commands notif,
12341 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012342{
12343 struct sk_buff *msg;
12344 void *hdr;
12345
Thomas Graf58050fc2012-06-28 03:57:45 +000012346 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012347 if (!msg)
12348 return;
12349
Luciano Coelhof8d75522014-11-07 14:31:35 +020012350 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012351 if (!hdr) {
12352 nlmsg_free(msg);
12353 return;
12354 }
12355
Johannes Berg683b6d32012-11-08 21:25:48 +010012356 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12357 goto nla_put_failure;
12358
12359 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012360 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012361
Luciano Coelhof8d75522014-11-07 14:31:35 +020012362 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12363 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12364 goto nla_put_failure;
12365
Thomas Pedersen53145262012-04-06 13:35:47 -070012366 genlmsg_end(msg, hdr);
12367
Johannes Berg68eb5502013-11-19 15:19:38 +010012368 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012369 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012370 return;
12371
12372 nla_put_failure:
12373 genlmsg_cancel(msg, hdr);
12374 nlmsg_free(msg);
12375}
12376
Johannes Berg947add32013-02-22 22:05:20 +010012377void cfg80211_ch_switch_notify(struct net_device *dev,
12378 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012379{
Johannes Berg947add32013-02-22 22:05:20 +010012380 struct wireless_dev *wdev = dev->ieee80211_ptr;
12381 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012382 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012383
Simon Wunderliche487eae2013-11-21 18:19:51 +010012384 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012385
Simon Wunderliche487eae2013-11-21 18:19:51 +010012386 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012387
Michal Kazior9e0e2962014-01-29 14:22:27 +010012388 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012389 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012390 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12391 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012392}
12393EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12394
Luciano Coelhof8d75522014-11-07 14:31:35 +020012395void cfg80211_ch_switch_started_notify(struct net_device *dev,
12396 struct cfg80211_chan_def *chandef,
12397 u8 count)
12398{
12399 struct wireless_dev *wdev = dev->ieee80211_ptr;
12400 struct wiphy *wiphy = wdev->wiphy;
12401 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12402
12403 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12404
12405 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12406 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12407}
12408EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12409
Thomas Pedersen84f10702012-07-12 16:17:33 -070012410void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012411nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012412 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012413 enum nl80211_radar_event event,
12414 struct net_device *netdev, gfp_t gfp)
12415{
12416 struct sk_buff *msg;
12417 void *hdr;
12418
12419 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12420 if (!msg)
12421 return;
12422
12423 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12424 if (!hdr) {
12425 nlmsg_free(msg);
12426 return;
12427 }
12428
12429 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12430 goto nla_put_failure;
12431
12432 /* NOP and radar events don't need a netdev parameter */
12433 if (netdev) {
12434 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12435
12436 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12437 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12438 goto nla_put_failure;
12439 }
12440
12441 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12442 goto nla_put_failure;
12443
12444 if (nl80211_send_chandef(msg, chandef))
12445 goto nla_put_failure;
12446
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012447 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012448
Johannes Berg68eb5502013-11-19 15:19:38 +010012449 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012450 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012451 return;
12452
12453 nla_put_failure:
12454 genlmsg_cancel(msg, hdr);
12455 nlmsg_free(msg);
12456}
12457
Johannes Berg7f6cf312011-11-04 11:18:15 +010012458void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12459 u64 cookie, bool acked, gfp_t gfp)
12460{
12461 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012462 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012463 struct sk_buff *msg;
12464 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012465
Beni Lev4ee3e062012-08-27 12:49:39 +030012466 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12467
Thomas Graf58050fc2012-06-28 03:57:45 +000012468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012469
Johannes Berg7f6cf312011-11-04 11:18:15 +010012470 if (!msg)
12471 return;
12472
12473 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12474 if (!hdr) {
12475 nlmsg_free(msg);
12476 return;
12477 }
12478
David S. Miller9360ffd2012-03-29 04:41:26 -040012479 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12480 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12481 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12482 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12483 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12484 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012485
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012486 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012487
Johannes Berg68eb5502013-11-19 15:19:38 +010012488 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012489 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012490 return;
12491
12492 nla_put_failure:
12493 genlmsg_cancel(msg, hdr);
12494 nlmsg_free(msg);
12495}
12496EXPORT_SYMBOL(cfg80211_probe_status);
12497
Johannes Berg5e760232011-11-04 11:18:17 +010012498void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12499 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012500 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012501{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012502 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012503 struct sk_buff *msg;
12504 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012505 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012506
Beni Lev4ee3e062012-08-27 12:49:39 +030012507 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12508
Ben Greear37c73b52012-10-26 14:49:25 -070012509 spin_lock_bh(&rdev->beacon_registrations_lock);
12510 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12511 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12512 if (!msg) {
12513 spin_unlock_bh(&rdev->beacon_registrations_lock);
12514 return;
12515 }
Johannes Berg5e760232011-11-04 11:18:17 +010012516
Ben Greear37c73b52012-10-26 14:49:25 -070012517 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12518 if (!hdr)
12519 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012520
Ben Greear37c73b52012-10-26 14:49:25 -070012521 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12522 (freq &&
12523 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12524 (sig_dbm &&
12525 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12526 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12527 goto nla_put_failure;
12528
12529 genlmsg_end(msg, hdr);
12530
12531 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012532 }
Ben Greear37c73b52012-10-26 14:49:25 -070012533 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012534 return;
12535
12536 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012537 spin_unlock_bh(&rdev->beacon_registrations_lock);
12538 if (hdr)
12539 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012540 nlmsg_free(msg);
12541}
12542EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12543
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012544#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012545static int cfg80211_net_detect_results(struct sk_buff *msg,
12546 struct cfg80211_wowlan_wakeup *wakeup)
12547{
12548 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12549 struct nlattr *nl_results, *nl_match, *nl_freqs;
12550 int i, j;
12551
12552 nl_results = nla_nest_start(
12553 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12554 if (!nl_results)
12555 return -EMSGSIZE;
12556
12557 for (i = 0; i < nd->n_matches; i++) {
12558 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12559
12560 nl_match = nla_nest_start(msg, i);
12561 if (!nl_match)
12562 break;
12563
12564 /* The SSID attribute is optional in nl80211, but for
12565 * simplicity reasons it's always present in the
12566 * cfg80211 structure. If a driver can't pass the
12567 * SSID, that needs to be changed. A zero length SSID
12568 * is still a valid SSID (wildcard), so it cannot be
12569 * used for this purpose.
12570 */
12571 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12572 match->ssid.ssid)) {
12573 nla_nest_cancel(msg, nl_match);
12574 goto out;
12575 }
12576
12577 if (match->n_channels) {
12578 nl_freqs = nla_nest_start(
12579 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12580 if (!nl_freqs) {
12581 nla_nest_cancel(msg, nl_match);
12582 goto out;
12583 }
12584
12585 for (j = 0; j < match->n_channels; j++) {
12586 if (nla_put_u32(msg,
12587 NL80211_ATTR_WIPHY_FREQ,
12588 match->channels[j])) {
12589 nla_nest_cancel(msg, nl_freqs);
12590 nla_nest_cancel(msg, nl_match);
12591 goto out;
12592 }
12593 }
12594
12595 nla_nest_end(msg, nl_freqs);
12596 }
12597
12598 nla_nest_end(msg, nl_match);
12599 }
12600
12601out:
12602 nla_nest_end(msg, nl_results);
12603 return 0;
12604}
12605
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012606void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12607 struct cfg80211_wowlan_wakeup *wakeup,
12608 gfp_t gfp)
12609{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012610 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012611 struct sk_buff *msg;
12612 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012613 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012614
12615 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12616
12617 if (wakeup)
12618 size += wakeup->packet_present_len;
12619
12620 msg = nlmsg_new(size, gfp);
12621 if (!msg)
12622 return;
12623
12624 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12625 if (!hdr)
12626 goto free_msg;
12627
12628 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12629 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12630 goto free_msg;
12631
12632 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12633 wdev->netdev->ifindex))
12634 goto free_msg;
12635
12636 if (wakeup) {
12637 struct nlattr *reasons;
12638
12639 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012640 if (!reasons)
12641 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012642
12643 if (wakeup->disconnect &&
12644 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12645 goto free_msg;
12646 if (wakeup->magic_pkt &&
12647 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12648 goto free_msg;
12649 if (wakeup->gtk_rekey_failure &&
12650 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12651 goto free_msg;
12652 if (wakeup->eap_identity_req &&
12653 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12654 goto free_msg;
12655 if (wakeup->four_way_handshake &&
12656 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12657 goto free_msg;
12658 if (wakeup->rfkill_release &&
12659 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12660 goto free_msg;
12661
12662 if (wakeup->pattern_idx >= 0 &&
12663 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12664 wakeup->pattern_idx))
12665 goto free_msg;
12666
Johannes Bergae917c92013-10-25 11:05:22 +020012667 if (wakeup->tcp_match &&
12668 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12669 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012670
Johannes Bergae917c92013-10-25 11:05:22 +020012671 if (wakeup->tcp_connlost &&
12672 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12673 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012674
Johannes Bergae917c92013-10-25 11:05:22 +020012675 if (wakeup->tcp_nomoretokens &&
12676 nla_put_flag(msg,
12677 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12678 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012679
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012680 if (wakeup->packet) {
12681 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12682 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12683
12684 if (!wakeup->packet_80211) {
12685 pkt_attr =
12686 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12687 len_attr =
12688 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12689 }
12690
12691 if (wakeup->packet_len &&
12692 nla_put_u32(msg, len_attr, wakeup->packet_len))
12693 goto free_msg;
12694
12695 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12696 wakeup->packet))
12697 goto free_msg;
12698 }
12699
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012700 if (wakeup->net_detect &&
12701 cfg80211_net_detect_results(msg, wakeup))
12702 goto free_msg;
12703
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012704 nla_nest_end(msg, reasons);
12705 }
12706
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012707 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012708
Johannes Berg68eb5502013-11-19 15:19:38 +010012709 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012710 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012711 return;
12712
12713 free_msg:
12714 nlmsg_free(msg);
12715}
12716EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12717#endif
12718
Jouni Malinen3475b092012-11-16 22:49:57 +020012719void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12720 enum nl80211_tdls_operation oper,
12721 u16 reason_code, gfp_t gfp)
12722{
12723 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012724 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012725 struct sk_buff *msg;
12726 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012727
12728 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12729 reason_code);
12730
12731 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12732 if (!msg)
12733 return;
12734
12735 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12736 if (!hdr) {
12737 nlmsg_free(msg);
12738 return;
12739 }
12740
12741 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12742 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12743 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12744 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12745 (reason_code > 0 &&
12746 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12747 goto nla_put_failure;
12748
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012749 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012750
Johannes Berg68eb5502013-11-19 15:19:38 +010012751 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012752 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012753 return;
12754
12755 nla_put_failure:
12756 genlmsg_cancel(msg, hdr);
12757 nlmsg_free(msg);
12758}
12759EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12760
Jouni Malinen026331c2010-02-15 12:53:10 +020012761static int nl80211_netlink_notify(struct notifier_block * nb,
12762 unsigned long state,
12763 void *_notify)
12764{
12765 struct netlink_notify *notify = _notify;
12766 struct cfg80211_registered_device *rdev;
12767 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012768 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012769
12770 if (state != NETLINK_URELEASE)
12771 return NOTIFY_DONE;
12772
12773 rcu_read_lock();
12774
Johannes Berg5e760232011-11-04 11:18:17 +010012775 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012776 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012777 bool schedule_scan_stop = false;
12778 struct cfg80211_sched_scan_request *sched_scan_req =
12779 rcu_dereference(rdev->sched_scan_req);
12780
12781 if (sched_scan_req && notify->portid &&
12782 sched_scan_req->owner_nlportid == notify->portid)
12783 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010012784
12785 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012786 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012787
Johannes Berg78f22b62014-03-24 17:57:27 +010012788 if (wdev->owner_nlportid == notify->portid)
12789 schedule_destroy_work = true;
12790 }
12791
Ben Greear37c73b52012-10-26 14:49:25 -070012792 spin_lock_bh(&rdev->beacon_registrations_lock);
12793 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12794 list) {
12795 if (reg->nlportid == notify->portid) {
12796 list_del(&reg->list);
12797 kfree(reg);
12798 break;
12799 }
12800 }
12801 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012802
12803 if (schedule_destroy_work) {
12804 struct cfg80211_iface_destroy *destroy;
12805
12806 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12807 if (destroy) {
12808 destroy->nlportid = notify->portid;
12809 spin_lock(&rdev->destroy_list_lock);
12810 list_add(&destroy->list, &rdev->destroy_list);
12811 spin_unlock(&rdev->destroy_list_lock);
12812 schedule_work(&rdev->destroy_work);
12813 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012814 } else if (schedule_scan_stop) {
12815 sched_scan_req->owner_nlportid = 0;
12816
12817 if (rdev->ops->sched_scan_stop &&
12818 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
12819 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010012820 }
Johannes Berg5e760232011-11-04 11:18:17 +010012821 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012822
12823 rcu_read_unlock();
12824
Ilan peer05050752015-03-04 00:32:06 -050012825 /*
12826 * It is possible that the user space process that is controlling the
12827 * indoor setting disappeared, so notify the regulatory core.
12828 */
12829 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012830 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012831}
12832
12833static struct notifier_block nl80211_netlink_notifier = {
12834 .notifier_call = nl80211_netlink_notify,
12835};
12836
Jouni Malinen355199e2013-02-27 17:14:27 +020012837void cfg80211_ft_event(struct net_device *netdev,
12838 struct cfg80211_ft_event_params *ft_event)
12839{
12840 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012841 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012842 struct sk_buff *msg;
12843 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012844
12845 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12846
12847 if (!ft_event->target_ap)
12848 return;
12849
12850 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12851 if (!msg)
12852 return;
12853
12854 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012855 if (!hdr)
12856 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012857
Johannes Bergae917c92013-10-25 11:05:22 +020012858 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12859 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12860 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12861 goto out;
12862
12863 if (ft_event->ies &&
12864 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12865 goto out;
12866 if (ft_event->ric_ies &&
12867 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12868 ft_event->ric_ies))
12869 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012870
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012871 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012872
Johannes Berg68eb5502013-11-19 15:19:38 +010012873 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012874 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012875 return;
12876 out:
12877 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012878}
12879EXPORT_SYMBOL(cfg80211_ft_event);
12880
Arend van Spriel5de17982013-04-18 15:49:00 +020012881void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12882{
12883 struct cfg80211_registered_device *rdev;
12884 struct sk_buff *msg;
12885 void *hdr;
12886 u32 nlportid;
12887
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012888 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012889 if (!rdev->crit_proto_nlportid)
12890 return;
12891
12892 nlportid = rdev->crit_proto_nlportid;
12893 rdev->crit_proto_nlportid = 0;
12894
12895 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12896 if (!msg)
12897 return;
12898
12899 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12900 if (!hdr)
12901 goto nla_put_failure;
12902
12903 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12904 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12905 goto nla_put_failure;
12906
12907 genlmsg_end(msg, hdr);
12908
12909 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12910 return;
12911
12912 nla_put_failure:
12913 if (hdr)
12914 genlmsg_cancel(msg, hdr);
12915 nlmsg_free(msg);
12916
12917}
12918EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12919
Johannes Berg348baf02014-01-24 14:06:29 +010012920void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12921{
12922 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012923 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012924 struct sk_buff *msg;
12925 void *hdr;
12926
12927 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12928 if (!msg)
12929 return;
12930
12931 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12932 if (!hdr)
12933 goto out;
12934
12935 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12936 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12937 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12938 goto out;
12939
12940 genlmsg_end(msg, hdr);
12941
12942 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12943 NL80211_MCGRP_MLME, GFP_KERNEL);
12944 return;
12945 out:
12946 nlmsg_free(msg);
12947}
12948
Johannes Berg55682962007-09-20 13:09:35 -040012949/* initialisation/exit functions */
12950
12951int nl80211_init(void)
12952{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012953 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012954
Johannes Berg2a94fe42013-11-19 15:19:39 +010012955 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12956 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012957 if (err)
12958 return err;
12959
Jouni Malinen026331c2010-02-15 12:53:10 +020012960 err = netlink_register_notifier(&nl80211_netlink_notifier);
12961 if (err)
12962 goto err_out;
12963
Johannes Berg55682962007-09-20 13:09:35 -040012964 return 0;
12965 err_out:
12966 genl_unregister_family(&nl80211_fam);
12967 return err;
12968}
12969
12970void nl80211_exit(void)
12971{
Jouni Malinen026331c2010-02-15 12:53:10 +020012972 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012973 genl_unregister_family(&nl80211_fam);
12974}