blob: 76b41578a838e3bed8596c5950ffbd6881d54a64 [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 Malinen36aedc902008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200391 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200398 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200399 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200400 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200401 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500402 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400403};
404
Johannes Berge31b8212010-10-05 19:39:30 +0200405/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000406static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200407 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 [NL80211_KEY_IDX] = { .type = NLA_U8 },
409 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200410 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200411 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
412 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200413 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100414 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
415};
416
417/* policy for the key default flags */
418static const struct nla_policy
419nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
420 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
421 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200422};
423
Johannes Bergff1b6e62011-05-04 15:37:28 +0200424/* policy for WoWLAN attributes */
425static const struct nla_policy
426nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
427 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200431 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100435 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300436 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100437};
438
439static const struct nla_policy
440nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
441 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
442 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
443 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
444 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
445 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
446 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
448 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
449 },
450 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
451 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
452 },
453 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
454 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
455 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200456};
457
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700458/* policy for coalesce rule attributes */
459static const struct nla_policy
460nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
461 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
462 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
463 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
464};
465
Johannes Berge5497d72011-07-05 16:35:40 +0200466/* policy for GTK rekey offload attributes */
467static const struct nla_policy
468nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
469 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
470 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
471 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
472};
473
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300474static const struct nla_policy
475nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200476 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300477 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700478 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300479};
480
Johannes Berg97990a02013-04-19 01:02:55 +0200481static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
482 struct netlink_callback *cb,
483 struct cfg80211_registered_device **rdev,
484 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100485{
Johannes Berg67748892010-10-04 21:14:06 +0200486 int err;
487
Johannes Berg67748892010-10-04 21:14:06 +0200488 rtnl_lock();
489
Johannes Berg97990a02013-04-19 01:02:55 +0200490 if (!cb->args[0]) {
491 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
492 nl80211_fam.attrbuf, nl80211_fam.maxattr,
493 nl80211_policy);
494 if (err)
495 goto out_unlock;
496
497 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
498 nl80211_fam.attrbuf);
499 if (IS_ERR(*wdev)) {
500 err = PTR_ERR(*wdev);
501 goto out_unlock;
502 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800503 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200504 /* 0 is the first index - add 1 to parse only once */
505 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200506 cb->args[1] = (*wdev)->identifier;
507 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200508 /* subtract the 1 again here */
509 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200510 struct wireless_dev *tmp;
511
512 if (!wiphy) {
513 err = -ENODEV;
514 goto out_unlock;
515 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800516 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200517 *wdev = NULL;
518
Johannes Berg97990a02013-04-19 01:02:55 +0200519 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
520 if (tmp->identifier == cb->args[1]) {
521 *wdev = tmp;
522 break;
523 }
524 }
Johannes Berg97990a02013-04-19 01:02:55 +0200525
526 if (!*wdev) {
527 err = -ENODEV;
528 goto out_unlock;
529 }
Johannes Berg67748892010-10-04 21:14:06 +0200530 }
531
Johannes Berg67748892010-10-04 21:14:06 +0200532 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200533 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200534 rtnl_unlock();
535 return err;
536}
537
Johannes Berg97990a02013-04-19 01:02:55 +0200538static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200539{
Johannes Berg67748892010-10-04 21:14:06 +0200540 rtnl_unlock();
541}
542
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100543/* IE validation */
544static bool is_valid_ie_attr(const struct nlattr *attr)
545{
546 const u8 *pos;
547 int len;
548
549 if (!attr)
550 return true;
551
552 pos = nla_data(attr);
553 len = nla_len(attr);
554
555 while (len) {
556 u8 elemlen;
557
558 if (len < 2)
559 return false;
560 len -= 2;
561
562 elemlen = pos[1];
563 if (elemlen > len)
564 return false;
565
566 len -= elemlen;
567 pos += 2 + elemlen;
568 }
569
570 return true;
571}
572
Johannes Berg55682962007-09-20 13:09:35 -0400573/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000574static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400575 int flags, u8 cmd)
576{
577 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000578 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400579}
580
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400581static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100582 struct ieee80211_channel *chan,
583 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400584{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200585 /* Some channels must be completely excluded from the
586 * list to protect old user-space tools from breaking
587 */
588 if (!large && chan->flags &
589 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
590 return 0;
591
David S. Miller9360ffd2012-03-29 04:41:26 -0400592 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
593 chan->center_freq))
594 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400595
David S. Miller9360ffd2012-03-29 04:41:26 -0400596 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
597 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
598 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200599 if (chan->flags & IEEE80211_CHAN_NO_IR) {
600 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
601 goto nla_put_failure;
602 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
603 goto nla_put_failure;
604 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100605 if (chan->flags & IEEE80211_CHAN_RADAR) {
606 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
607 goto nla_put_failure;
608 if (large) {
609 u32 time;
610
611 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
612
613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
614 chan->dfs_state))
615 goto nla_put_failure;
616 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
617 time))
618 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100619 if (nla_put_u32(msg,
620 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
621 chan->dfs_cac_ms))
622 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100623 }
624 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400625
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100626 if (large) {
627 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
635 goto nla_put_failure;
636 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
638 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200639 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
641 goto nla_put_failure;
Arik Nemtsov06f207f2015-05-06 16:28:31 +0300642 if ((chan->flags & IEEE80211_CHAN_IR_CONCURRENT) &&
643 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_IR_CONCURRENT))
David Spinadel570dbde2014-02-23 09:12:59 +0200644 goto nla_put_failure;
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200645 if ((chan->flags & IEEE80211_CHAN_NO_20MHZ) &&
646 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_20MHZ))
647 goto nla_put_failure;
648 if ((chan->flags & IEEE80211_CHAN_NO_10MHZ) &&
649 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_10MHZ))
650 goto nla_put_failure;
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100651 }
652
David S. Miller9360ffd2012-03-29 04:41:26 -0400653 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_MAX_TX_POWER,
654 DBM_TO_MBM(chan->max_power)))
655 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400656
657 return 0;
658
659 nla_put_failure:
660 return -ENOBUFS;
661}
662
Johannes Berg55682962007-09-20 13:09:35 -0400663/* netlink command implementations */
664
Johannes Bergb9454e82009-07-08 13:29:08 +0200665struct key_parse {
666 struct key_params p;
667 int idx;
Johannes Berge31b8212010-10-05 19:39:30 +0200668 int type;
Johannes Bergb9454e82009-07-08 13:29:08 +0200669 bool def, defmgmt;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100670 bool def_uni, def_multi;
Johannes Bergb9454e82009-07-08 13:29:08 +0200671};
672
673static int nl80211_parse_key_new(struct nlattr *key, struct key_parse *k)
674{
675 struct nlattr *tb[NL80211_KEY_MAX + 1];
676 int err = nla_parse_nested(tb, NL80211_KEY_MAX, key,
677 nl80211_key_policy);
678 if (err)
679 return err;
680
681 k->def = !!tb[NL80211_KEY_DEFAULT];
682 k->defmgmt = !!tb[NL80211_KEY_DEFAULT_MGMT];
683
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100684 if (k->def) {
685 k->def_uni = true;
686 k->def_multi = true;
687 }
688 if (k->defmgmt)
689 k->def_multi = true;
690
Johannes Bergb9454e82009-07-08 13:29:08 +0200691 if (tb[NL80211_KEY_IDX])
692 k->idx = nla_get_u8(tb[NL80211_KEY_IDX]);
693
694 if (tb[NL80211_KEY_DATA]) {
695 k->p.key = nla_data(tb[NL80211_KEY_DATA]);
696 k->p.key_len = nla_len(tb[NL80211_KEY_DATA]);
697 }
698
699 if (tb[NL80211_KEY_SEQ]) {
700 k->p.seq = nla_data(tb[NL80211_KEY_SEQ]);
701 k->p.seq_len = nla_len(tb[NL80211_KEY_SEQ]);
702 }
703
704 if (tb[NL80211_KEY_CIPHER])
705 k->p.cipher = nla_get_u32(tb[NL80211_KEY_CIPHER]);
706
Johannes Berge31b8212010-10-05 19:39:30 +0200707 if (tb[NL80211_KEY_TYPE]) {
708 k->type = nla_get_u32(tb[NL80211_KEY_TYPE]);
709 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
710 return -EINVAL;
711 }
712
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100713 if (tb[NL80211_KEY_DEFAULT_TYPES]) {
714 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
Johannes Berg2da8f412012-01-20 13:52:37 +0100715 err = nla_parse_nested(kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
716 tb[NL80211_KEY_DEFAULT_TYPES],
717 nl80211_key_default_policy);
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100718 if (err)
719 return err;
720
721 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
722 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
723 }
724
Johannes Bergb9454e82009-07-08 13:29:08 +0200725 return 0;
726}
727
728static int nl80211_parse_key_old(struct genl_info *info, struct key_parse *k)
729{
730 if (info->attrs[NL80211_ATTR_KEY_DATA]) {
731 k->p.key = nla_data(info->attrs[NL80211_ATTR_KEY_DATA]);
732 k->p.key_len = nla_len(info->attrs[NL80211_ATTR_KEY_DATA]);
733 }
734
735 if (info->attrs[NL80211_ATTR_KEY_SEQ]) {
736 k->p.seq = nla_data(info->attrs[NL80211_ATTR_KEY_SEQ]);
737 k->p.seq_len = nla_len(info->attrs[NL80211_ATTR_KEY_SEQ]);
738 }
739
740 if (info->attrs[NL80211_ATTR_KEY_IDX])
741 k->idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
742
743 if (info->attrs[NL80211_ATTR_KEY_CIPHER])
744 k->p.cipher = nla_get_u32(info->attrs[NL80211_ATTR_KEY_CIPHER]);
745
746 k->def = !!info->attrs[NL80211_ATTR_KEY_DEFAULT];
747 k->defmgmt = !!info->attrs[NL80211_ATTR_KEY_DEFAULT_MGMT];
748
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100749 if (k->def) {
750 k->def_uni = true;
751 k->def_multi = true;
752 }
753 if (k->defmgmt)
754 k->def_multi = true;
755
Johannes Berge31b8212010-10-05 19:39:30 +0200756 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
757 k->type = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
758 if (k->type < 0 || k->type >= NUM_NL80211_KEYTYPES)
759 return -EINVAL;
760 }
761
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100762 if (info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES]) {
763 struct nlattr *kdt[NUM_NL80211_KEY_DEFAULT_TYPES];
764 int err = nla_parse_nested(
765 kdt, NUM_NL80211_KEY_DEFAULT_TYPES - 1,
766 info->attrs[NL80211_ATTR_KEY_DEFAULT_TYPES],
767 nl80211_key_default_policy);
768 if (err)
769 return err;
770
771 k->def_uni = kdt[NL80211_KEY_DEFAULT_TYPE_UNICAST];
772 k->def_multi = kdt[NL80211_KEY_DEFAULT_TYPE_MULTICAST];
773 }
774
Johannes Bergb9454e82009-07-08 13:29:08 +0200775 return 0;
776}
777
778static int nl80211_parse_key(struct genl_info *info, struct key_parse *k)
779{
780 int err;
781
782 memset(k, 0, sizeof(*k));
783 k->idx = -1;
Johannes Berge31b8212010-10-05 19:39:30 +0200784 k->type = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +0200785
786 if (info->attrs[NL80211_ATTR_KEY])
787 err = nl80211_parse_key_new(info->attrs[NL80211_ATTR_KEY], k);
788 else
789 err = nl80211_parse_key_old(info, k);
790
791 if (err)
792 return err;
793
794 if (k->def && k->defmgmt)
795 return -EINVAL;
796
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100797 if (k->defmgmt) {
798 if (k->def_uni || !k->def_multi)
799 return -EINVAL;
800 }
801
Johannes Bergb9454e82009-07-08 13:29:08 +0200802 if (k->idx != -1) {
803 if (k->defmgmt) {
804 if (k->idx < 4 || k->idx > 5)
805 return -EINVAL;
806 } else if (k->def) {
807 if (k->idx < 0 || k->idx > 3)
808 return -EINVAL;
809 } else {
810 if (k->idx < 0 || k->idx > 5)
811 return -EINVAL;
812 }
813 }
814
815 return 0;
816}
817
Johannes Bergfffd0932009-07-08 14:22:54 +0200818static struct cfg80211_cached_keys *
819nl80211_parse_connkeys(struct cfg80211_registered_device *rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +0530820 struct nlattr *keys, bool *no_ht)
Johannes Bergfffd0932009-07-08 14:22:54 +0200821{
822 struct key_parse parse;
823 struct nlattr *key;
824 struct cfg80211_cached_keys *result;
825 int rem, err, def = 0;
826
827 result = kzalloc(sizeof(*result), GFP_KERNEL);
828 if (!result)
829 return ERR_PTR(-ENOMEM);
830
831 result->def = -1;
832 result->defmgmt = -1;
833
834 nla_for_each_nested(key, keys, rem) {
835 memset(&parse, 0, sizeof(parse));
836 parse.idx = -1;
837
838 err = nl80211_parse_key_new(key, &parse);
839 if (err)
840 goto error;
841 err = -EINVAL;
842 if (!parse.p.key)
843 goto error;
844 if (parse.idx < 0 || parse.idx > 4)
845 goto error;
846 if (parse.def) {
847 if (def)
848 goto error;
849 def = 1;
850 result->def = parse.idx;
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100851 if (!parse.def_uni || !parse.def_multi)
852 goto error;
Johannes Bergfffd0932009-07-08 14:22:54 +0200853 } else if (parse.defmgmt)
854 goto error;
855 err = cfg80211_validate_key_settings(rdev, &parse.p,
Johannes Berge31b8212010-10-05 19:39:30 +0200856 parse.idx, false, NULL);
Johannes Bergfffd0932009-07-08 14:22:54 +0200857 if (err)
858 goto error;
859 result->params[parse.idx].cipher = parse.p.cipher;
860 result->params[parse.idx].key_len = parse.p.key_len;
861 result->params[parse.idx].key = result->data[parse.idx];
862 memcpy(result->data[parse.idx], parse.p.key, parse.p.key_len);
Sujith Manoharande7044e2012-10-18 10:19:28 +0530863
864 if (parse.p.cipher == WLAN_CIPHER_SUITE_WEP40 ||
865 parse.p.cipher == WLAN_CIPHER_SUITE_WEP104) {
866 if (no_ht)
867 *no_ht = true;
868 }
Johannes Bergfffd0932009-07-08 14:22:54 +0200869 }
870
871 return result;
872 error:
873 kfree(result);
874 return ERR_PTR(err);
875}
876
877static int nl80211_key_allowed(struct wireless_dev *wdev)
878{
879 ASSERT_WDEV_LOCK(wdev);
880
Johannes Bergfffd0932009-07-08 14:22:54 +0200881 switch (wdev->iftype) {
882 case NL80211_IFTYPE_AP:
883 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200884 case NL80211_IFTYPE_P2P_GO:
Thomas Pedersenff973af2011-05-03 16:57:12 -0700885 case NL80211_IFTYPE_MESH_POINT:
Johannes Bergfffd0932009-07-08 14:22:54 +0200886 break;
887 case NL80211_IFTYPE_ADHOC:
Johannes Bergfffd0932009-07-08 14:22:54 +0200888 case NL80211_IFTYPE_STATION:
Johannes Berg074ac8d2010-09-16 14:58:22 +0200889 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergceca7b72013-05-16 00:55:45 +0200890 if (!wdev->current_bss)
Johannes Bergfffd0932009-07-08 14:22:54 +0200891 return -ENOLINK;
892 break;
Johannes Bergde4fcba2014-10-31 14:16:12 +0100893 case NL80211_IFTYPE_UNSPECIFIED:
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +0100894 case NL80211_IFTYPE_OCB:
Johannes Bergde4fcba2014-10-31 14:16:12 +0100895 case NL80211_IFTYPE_MONITOR:
896 case NL80211_IFTYPE_P2P_DEVICE:
897 case NL80211_IFTYPE_WDS:
898 case NUM_NL80211_IFTYPES:
Johannes Bergfffd0932009-07-08 14:22:54 +0200899 return -EINVAL;
900 }
901
902 return 0;
903}
904
Jouni Malinen664834d2014-01-15 00:01:44 +0200905static struct ieee80211_channel *nl80211_get_valid_chan(struct wiphy *wiphy,
906 struct nlattr *tb)
907{
908 struct ieee80211_channel *chan;
909
910 if (tb == NULL)
911 return NULL;
912 chan = ieee80211_get_channel(wiphy, nla_get_u32(tb));
913 if (!chan || chan->flags & IEEE80211_CHAN_DISABLED)
914 return NULL;
915 return chan;
916}
917
Johannes Berg7527a782011-05-13 10:58:57 +0200918static int nl80211_put_iftypes(struct sk_buff *msg, u32 attr, u16 ifmodes)
919{
920 struct nlattr *nl_modes = nla_nest_start(msg, attr);
921 int i;
922
923 if (!nl_modes)
924 goto nla_put_failure;
925
926 i = 0;
927 while (ifmodes) {
David S. Miller9360ffd2012-03-29 04:41:26 -0400928 if ((ifmodes & 1) && nla_put_flag(msg, i))
929 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200930 ifmodes >>= 1;
931 i++;
932 }
933
934 nla_nest_end(msg, nl_modes);
935 return 0;
936
937nla_put_failure:
938 return -ENOBUFS;
939}
940
941static int nl80211_put_iface_combinations(struct wiphy *wiphy,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100942 struct sk_buff *msg,
943 bool large)
Johannes Berg7527a782011-05-13 10:58:57 +0200944{
945 struct nlattr *nl_combis;
946 int i, j;
947
948 nl_combis = nla_nest_start(msg,
949 NL80211_ATTR_INTERFACE_COMBINATIONS);
950 if (!nl_combis)
951 goto nla_put_failure;
952
953 for (i = 0; i < wiphy->n_iface_combinations; i++) {
954 const struct ieee80211_iface_combination *c;
955 struct nlattr *nl_combi, *nl_limits;
956
957 c = &wiphy->iface_combinations[i];
958
959 nl_combi = nla_nest_start(msg, i + 1);
960 if (!nl_combi)
961 goto nla_put_failure;
962
963 nl_limits = nla_nest_start(msg, NL80211_IFACE_COMB_LIMITS);
964 if (!nl_limits)
965 goto nla_put_failure;
966
967 for (j = 0; j < c->n_limits; j++) {
968 struct nlattr *nl_limit;
969
970 nl_limit = nla_nest_start(msg, j + 1);
971 if (!nl_limit)
972 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -0400973 if (nla_put_u32(msg, NL80211_IFACE_LIMIT_MAX,
974 c->limits[j].max))
975 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200976 if (nl80211_put_iftypes(msg, NL80211_IFACE_LIMIT_TYPES,
977 c->limits[j].types))
978 goto nla_put_failure;
979 nla_nest_end(msg, nl_limit);
980 }
981
982 nla_nest_end(msg, nl_limits);
983
David S. Miller9360ffd2012-03-29 04:41:26 -0400984 if (c->beacon_int_infra_match &&
985 nla_put_flag(msg, NL80211_IFACE_COMB_STA_AP_BI_MATCH))
986 goto nla_put_failure;
987 if (nla_put_u32(msg, NL80211_IFACE_COMB_NUM_CHANNELS,
988 c->num_different_channels) ||
989 nla_put_u32(msg, NL80211_IFACE_COMB_MAXNUM,
990 c->max_interfaces))
991 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100992 if (large &&
Felix Fietkau8c48b502014-05-05 11:48:40 +0200993 (nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_WIDTHS,
994 c->radar_detect_widths) ||
995 nla_put_u32(msg, NL80211_IFACE_COMB_RADAR_DETECT_REGIONS,
996 c->radar_detect_regions)))
Johannes Bergcdc89b92013-02-18 23:54:36 +0100997 goto nla_put_failure;
Johannes Berg7527a782011-05-13 10:58:57 +0200998
999 nla_nest_end(msg, nl_combi);
1000 }
1001
1002 nla_nest_end(msg, nl_combis);
1003
1004 return 0;
1005nla_put_failure:
1006 return -ENOBUFS;
1007}
1008
Johannes Berg3713b4e2013-02-14 16:19:38 +01001009#ifdef CONFIG_PM
Johannes Bergb56cf722013-02-20 01:02:38 +01001010static int nl80211_send_wowlan_tcp_caps(struct cfg80211_registered_device *rdev,
1011 struct sk_buff *msg)
1012{
Johannes Berg964dc9e2013-06-03 17:25:34 +02001013 const struct wiphy_wowlan_tcp_support *tcp = rdev->wiphy.wowlan->tcp;
Johannes Bergb56cf722013-02-20 01:02:38 +01001014 struct nlattr *nl_tcp;
1015
1016 if (!tcp)
1017 return 0;
1018
1019 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
1020 if (!nl_tcp)
1021 return -ENOBUFS;
1022
1023 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1024 tcp->data_payload_max))
1025 return -ENOBUFS;
1026
1027 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
1028 tcp->data_payload_max))
1029 return -ENOBUFS;
1030
1031 if (tcp->seq && nla_put_flag(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ))
1032 return -ENOBUFS;
1033
1034 if (tcp->tok && nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
1035 sizeof(*tcp->tok), tcp->tok))
1036 return -ENOBUFS;
1037
1038 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
1039 tcp->data_interval_max))
1040 return -ENOBUFS;
1041
1042 if (nla_put_u32(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
1043 tcp->wake_payload_max))
1044 return -ENOBUFS;
1045
1046 nla_nest_end(msg, nl_tcp);
1047 return 0;
1048}
1049
Johannes Berg3713b4e2013-02-14 16:19:38 +01001050static int nl80211_send_wowlan(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001051 struct cfg80211_registered_device *rdev,
Johannes Bergb56cf722013-02-20 01:02:38 +01001052 bool large)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001053{
1054 struct nlattr *nl_wowlan;
1055
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001056 if (!rdev->wiphy.wowlan)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001057 return 0;
1058
1059 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS_SUPPORTED);
1060 if (!nl_wowlan)
1061 return -ENOBUFS;
1062
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001063 if (((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_ANY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001064 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001065 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_DISCONNECT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001066 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001067 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001068 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001069 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001070 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001071 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001072 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001073 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001074 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001075 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001076 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001077 ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001078 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
1079 return -ENOBUFS;
1080
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001081 if (rdev->wiphy.wowlan->n_patterns) {
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07001082 struct nl80211_pattern_support pat = {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001083 .max_patterns = rdev->wiphy.wowlan->n_patterns,
1084 .min_pattern_len = rdev->wiphy.wowlan->pattern_min_len,
1085 .max_pattern_len = rdev->wiphy.wowlan->pattern_max_len,
1086 .max_pkt_offset = rdev->wiphy.wowlan->max_pkt_offset,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001087 };
1088
1089 if (nla_put(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
1090 sizeof(pat), &pat))
1091 return -ENOBUFS;
1092 }
1093
Luciano Coelho75453cc2015-01-09 14:06:37 +02001094 if ((rdev->wiphy.wowlan->flags & WIPHY_WOWLAN_NET_DETECT) &&
1095 nla_put_u32(msg, NL80211_WOWLAN_TRIG_NET_DETECT,
1096 rdev->wiphy.wowlan->max_nd_match_sets))
1097 return -ENOBUFS;
1098
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001099 if (large && nl80211_send_wowlan_tcp_caps(rdev, msg))
Johannes Bergb56cf722013-02-20 01:02:38 +01001100 return -ENOBUFS;
1101
Johannes Berg3713b4e2013-02-14 16:19:38 +01001102 nla_nest_end(msg, nl_wowlan);
1103
1104 return 0;
1105}
1106#endif
1107
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001108static int nl80211_send_coalesce(struct sk_buff *msg,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001109 struct cfg80211_registered_device *rdev)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001110{
1111 struct nl80211_coalesce_rule_support rule;
1112
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001113 if (!rdev->wiphy.coalesce)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001114 return 0;
1115
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001116 rule.max_rules = rdev->wiphy.coalesce->n_rules;
1117 rule.max_delay = rdev->wiphy.coalesce->max_delay;
1118 rule.pat.max_patterns = rdev->wiphy.coalesce->n_patterns;
1119 rule.pat.min_pattern_len = rdev->wiphy.coalesce->pattern_min_len;
1120 rule.pat.max_pattern_len = rdev->wiphy.coalesce->pattern_max_len;
1121 rule.pat.max_pkt_offset = rdev->wiphy.coalesce->max_pkt_offset;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001122
1123 if (nla_put(msg, NL80211_ATTR_COALESCE_RULE, sizeof(rule), &rule))
1124 return -ENOBUFS;
1125
1126 return 0;
1127}
1128
Johannes Berg3713b4e2013-02-14 16:19:38 +01001129static int nl80211_send_band_rateinfo(struct sk_buff *msg,
1130 struct ieee80211_supported_band *sband)
1131{
1132 struct nlattr *nl_rates, *nl_rate;
1133 struct ieee80211_rate *rate;
1134 int i;
1135
1136 /* add HT info */
1137 if (sband->ht_cap.ht_supported &&
1138 (nla_put(msg, NL80211_BAND_ATTR_HT_MCS_SET,
1139 sizeof(sband->ht_cap.mcs),
1140 &sband->ht_cap.mcs) ||
1141 nla_put_u16(msg, NL80211_BAND_ATTR_HT_CAPA,
1142 sband->ht_cap.cap) ||
1143 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_FACTOR,
1144 sband->ht_cap.ampdu_factor) ||
1145 nla_put_u8(msg, NL80211_BAND_ATTR_HT_AMPDU_DENSITY,
1146 sband->ht_cap.ampdu_density)))
1147 return -ENOBUFS;
1148
1149 /* add VHT info */
1150 if (sband->vht_cap.vht_supported &&
1151 (nla_put(msg, NL80211_BAND_ATTR_VHT_MCS_SET,
1152 sizeof(sband->vht_cap.vht_mcs),
1153 &sband->vht_cap.vht_mcs) ||
1154 nla_put_u32(msg, NL80211_BAND_ATTR_VHT_CAPA,
1155 sband->vht_cap.cap)))
1156 return -ENOBUFS;
1157
1158 /* add bitrates */
1159 nl_rates = nla_nest_start(msg, NL80211_BAND_ATTR_RATES);
1160 if (!nl_rates)
1161 return -ENOBUFS;
1162
1163 for (i = 0; i < sband->n_bitrates; i++) {
1164 nl_rate = nla_nest_start(msg, i);
1165 if (!nl_rate)
1166 return -ENOBUFS;
1167
1168 rate = &sband->bitrates[i];
1169 if (nla_put_u32(msg, NL80211_BITRATE_ATTR_RATE,
1170 rate->bitrate))
1171 return -ENOBUFS;
1172 if ((rate->flags & IEEE80211_RATE_SHORT_PREAMBLE) &&
1173 nla_put_flag(msg,
1174 NL80211_BITRATE_ATTR_2GHZ_SHORTPREAMBLE))
1175 return -ENOBUFS;
1176
1177 nla_nest_end(msg, nl_rate);
1178 }
1179
1180 nla_nest_end(msg, nl_rates);
1181
1182 return 0;
1183}
1184
1185static int
1186nl80211_send_mgmt_stypes(struct sk_buff *msg,
1187 const struct ieee80211_txrx_stypes *mgmt_stypes)
1188{
1189 u16 stypes;
1190 struct nlattr *nl_ftypes, *nl_ifs;
1191 enum nl80211_iftype ift;
1192 int i;
1193
1194 if (!mgmt_stypes)
1195 return 0;
1196
1197 nl_ifs = nla_nest_start(msg, NL80211_ATTR_TX_FRAME_TYPES);
1198 if (!nl_ifs)
1199 return -ENOBUFS;
1200
1201 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1202 nl_ftypes = nla_nest_start(msg, ift);
1203 if (!nl_ftypes)
1204 return -ENOBUFS;
1205 i = 0;
1206 stypes = mgmt_stypes[ift].tx;
1207 while (stypes) {
1208 if ((stypes & 1) &&
1209 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1210 (i << 4) | IEEE80211_FTYPE_MGMT))
1211 return -ENOBUFS;
1212 stypes >>= 1;
1213 i++;
1214 }
1215 nla_nest_end(msg, nl_ftypes);
1216 }
1217
1218 nla_nest_end(msg, nl_ifs);
1219
1220 nl_ifs = nla_nest_start(msg, NL80211_ATTR_RX_FRAME_TYPES);
1221 if (!nl_ifs)
1222 return -ENOBUFS;
1223
1224 for (ift = 0; ift < NUM_NL80211_IFTYPES; ift++) {
1225 nl_ftypes = nla_nest_start(msg, ift);
1226 if (!nl_ftypes)
1227 return -ENOBUFS;
1228 i = 0;
1229 stypes = mgmt_stypes[ift].rx;
1230 while (stypes) {
1231 if ((stypes & 1) &&
1232 nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE,
1233 (i << 4) | IEEE80211_FTYPE_MGMT))
1234 return -ENOBUFS;
1235 stypes >>= 1;
1236 i++;
1237 }
1238 nla_nest_end(msg, nl_ftypes);
1239 }
1240 nla_nest_end(msg, nl_ifs);
1241
1242 return 0;
1243}
1244
Johannes Berg86e8cf92013-06-19 10:57:22 +02001245struct nl80211_dump_wiphy_state {
1246 s64 filter_wiphy;
1247 long start;
1248 long split_start, band_start, chan_start;
1249 bool split;
1250};
1251
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001252static int nl80211_send_wiphy(struct cfg80211_registered_device *rdev,
Johannes Berg3bb20552014-05-26 13:52:25 +02001253 enum nl80211_commands cmd,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001254 struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001255 int flags, struct nl80211_dump_wiphy_state *state)
Johannes Berg55682962007-09-20 13:09:35 -04001256{
1257 void *hdr;
Johannes Bergee688b002008-01-24 19:38:39 +01001258 struct nlattr *nl_bands, *nl_band;
1259 struct nlattr *nl_freqs, *nl_freq;
Johannes Berg8fdc6212009-03-14 09:34:01 +01001260 struct nlattr *nl_cmds;
Johannes Bergee688b002008-01-24 19:38:39 +01001261 enum ieee80211_band band;
1262 struct ieee80211_channel *chan;
Johannes Bergee688b002008-01-24 19:38:39 +01001263 int i;
Johannes Berg2e161f72010-08-12 15:38:38 +02001264 const struct ieee80211_txrx_stypes *mgmt_stypes =
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001265 rdev->wiphy.mgmt_stypes;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001266 u32 features;
Johannes Berg55682962007-09-20 13:09:35 -04001267
Johannes Berg3bb20552014-05-26 13:52:25 +02001268 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04001269 if (!hdr)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001270 return -ENOBUFS;
1271
Johannes Berg86e8cf92013-06-19 10:57:22 +02001272 if (WARN_ON(!state))
1273 return -EINVAL;
Johannes Berg55682962007-09-20 13:09:35 -04001274
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001275 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001276 nla_put_string(msg, NL80211_ATTR_WIPHY_NAME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001277 wiphy_name(&rdev->wiphy)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04001278 nla_put_u32(msg, NL80211_ATTR_GENERATION,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001279 cfg80211_rdev_list_generation))
David S. Miller9360ffd2012-03-29 04:41:26 -04001280 goto nla_put_failure;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001281
Johannes Berg3bb20552014-05-26 13:52:25 +02001282 if (cmd != NL80211_CMD_NEW_WIPHY)
1283 goto finish;
1284
Johannes Berg86e8cf92013-06-19 10:57:22 +02001285 switch (state->split_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001286 case 0:
1287 if (nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_SHORT,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001288 rdev->wiphy.retry_short) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001289 nla_put_u8(msg, NL80211_ATTR_WIPHY_RETRY_LONG,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001290 rdev->wiphy.retry_long) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001291 nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001292 rdev->wiphy.frag_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001293 nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001294 rdev->wiphy.rts_threshold) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001295 nla_put_u8(msg, NL80211_ATTR_WIPHY_COVERAGE_CLASS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001296 rdev->wiphy.coverage_class) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001297 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001298 rdev->wiphy.max_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001299 nla_put_u8(msg, NL80211_ATTR_MAX_NUM_SCHED_SCAN_SSIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001300 rdev->wiphy.max_sched_scan_ssids) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001301 nla_put_u16(msg, NL80211_ATTR_MAX_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001302 rdev->wiphy.max_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001303 nla_put_u16(msg, NL80211_ATTR_MAX_SCHED_SCAN_IE_LEN,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001304 rdev->wiphy.max_sched_scan_ie_len) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001305 nla_put_u8(msg, NL80211_ATTR_MAX_MATCH_SETS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001306 rdev->wiphy.max_match_sets))
Johannes Bergee688b002008-01-24 19:38:39 +01001307 goto nla_put_failure;
1308
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001309 if ((rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001310 nla_put_flag(msg, NL80211_ATTR_SUPPORT_IBSS_RSN))
1311 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001312 if ((rdev->wiphy.flags & WIPHY_FLAG_MESH_AUTH) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001313 nla_put_flag(msg, NL80211_ATTR_SUPPORT_MESH_AUTH))
1314 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001315 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001316 nla_put_flag(msg, NL80211_ATTR_SUPPORT_AP_UAPSD))
1317 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001318 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_FW_ROAM) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001319 nla_put_flag(msg, NL80211_ATTR_ROAM_SUPPORT))
1320 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001321 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001322 nla_put_flag(msg, NL80211_ATTR_TDLS_SUPPORT))
1323 goto nla_put_failure;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001324 if ((rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001325 nla_put_flag(msg, NL80211_ATTR_TDLS_EXTERNAL_SETUP))
David S. Miller9360ffd2012-03-29 04:41:26 -04001326 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001327 state->split_start++;
1328 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001329 break;
1330 case 1:
1331 if (nla_put(msg, NL80211_ATTR_CIPHER_SUITES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001332 sizeof(u32) * rdev->wiphy.n_cipher_suites,
1333 rdev->wiphy.cipher_suites))
Mahesh Palivelabf0c111e2012-06-22 07:27:46 +00001334 goto nla_put_failure;
1335
Johannes Berg3713b4e2013-02-14 16:19:38 +01001336 if (nla_put_u8(msg, NL80211_ATTR_MAX_NUM_PMKIDS,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001337 rdev->wiphy.max_num_pmkids))
Johannes Bergee688b002008-01-24 19:38:39 +01001338 goto nla_put_failure;
1339
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001340 if ((rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001341 nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE))
1342 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001343
Johannes Berg3713b4e2013-02-14 16:19:38 +01001344 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_TX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001345 rdev->wiphy.available_antennas_tx) ||
Johannes Berg3713b4e2013-02-14 16:19:38 +01001346 nla_put_u32(msg, NL80211_ATTR_WIPHY_ANTENNA_AVAIL_RX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001347 rdev->wiphy.available_antennas_rx))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001348 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001349
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001350 if ((rdev->wiphy.flags & WIPHY_FLAG_AP_PROBE_RESP_OFFLOAD) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001351 nla_put_u32(msg, NL80211_ATTR_PROBE_RESP_OFFLOAD,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001352 rdev->wiphy.probe_resp_offload))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001353 goto nla_put_failure;
Jouni Malinene2f367f262008-11-21 19:01:30 +02001354
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001355 if ((rdev->wiphy.available_antennas_tx ||
1356 rdev->wiphy.available_antennas_rx) &&
1357 rdev->ops->get_antenna) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001358 u32 tx_ant = 0, rx_ant = 0;
1359 int res;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001360 res = rdev_get_antenna(rdev, &tx_ant, &rx_ant);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001361 if (!res) {
1362 if (nla_put_u32(msg,
1363 NL80211_ATTR_WIPHY_ANTENNA_TX,
1364 tx_ant) ||
1365 nla_put_u32(msg,
1366 NL80211_ATTR_WIPHY_ANTENNA_RX,
1367 rx_ant))
1368 goto nla_put_failure;
1369 }
Johannes Bergee688b002008-01-24 19:38:39 +01001370 }
1371
Johannes Berg86e8cf92013-06-19 10:57:22 +02001372 state->split_start++;
1373 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001374 break;
1375 case 2:
1376 if (nl80211_put_iftypes(msg, NL80211_ATTR_SUPPORTED_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001377 rdev->wiphy.interface_modes))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001378 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001379 state->split_start++;
1380 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001381 break;
1382 case 3:
1383 nl_bands = nla_nest_start(msg, NL80211_ATTR_WIPHY_BANDS);
1384 if (!nl_bands)
Johannes Bergee688b002008-01-24 19:38:39 +01001385 goto nla_put_failure;
1386
Johannes Berg86e8cf92013-06-19 10:57:22 +02001387 for (band = state->band_start;
1388 band < IEEE80211_NUM_BANDS; band++) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001389 struct ieee80211_supported_band *sband;
1390
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001391 sband = rdev->wiphy.bands[band];
Johannes Berg3713b4e2013-02-14 16:19:38 +01001392
1393 if (!sband)
1394 continue;
1395
1396 nl_band = nla_nest_start(msg, band);
1397 if (!nl_band)
Johannes Bergee688b002008-01-24 19:38:39 +01001398 goto nla_put_failure;
1399
Johannes Berg86e8cf92013-06-19 10:57:22 +02001400 switch (state->chan_start) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001401 case 0:
1402 if (nl80211_send_band_rateinfo(msg, sband))
1403 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001404 state->chan_start++;
1405 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001406 break;
1407 default:
1408 /* add frequencies */
1409 nl_freqs = nla_nest_start(
1410 msg, NL80211_BAND_ATTR_FREQS);
1411 if (!nl_freqs)
1412 goto nla_put_failure;
Johannes Bergee688b002008-01-24 19:38:39 +01001413
Johannes Berg86e8cf92013-06-19 10:57:22 +02001414 for (i = state->chan_start - 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001415 i < sband->n_channels;
1416 i++) {
1417 nl_freq = nla_nest_start(msg, i);
1418 if (!nl_freq)
1419 goto nla_put_failure;
1420
1421 chan = &sband->channels[i];
1422
Johannes Berg86e8cf92013-06-19 10:57:22 +02001423 if (nl80211_msg_put_channel(
1424 msg, chan,
1425 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001426 goto nla_put_failure;
1427
1428 nla_nest_end(msg, nl_freq);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001429 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001430 break;
1431 }
1432 if (i < sband->n_channels)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001433 state->chan_start = i + 2;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001434 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001435 state->chan_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001436 nla_nest_end(msg, nl_freqs);
1437 }
1438
1439 nla_nest_end(msg, nl_band);
1440
Johannes Berg86e8cf92013-06-19 10:57:22 +02001441 if (state->split) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001442 /* start again here */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001443 if (state->chan_start)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001444 band--;
1445 break;
1446 }
Johannes Bergee688b002008-01-24 19:38:39 +01001447 }
Johannes Berg3713b4e2013-02-14 16:19:38 +01001448 nla_nest_end(msg, nl_bands);
Johannes Bergee688b002008-01-24 19:38:39 +01001449
Johannes Berg3713b4e2013-02-14 16:19:38 +01001450 if (band < IEEE80211_NUM_BANDS)
Johannes Berg86e8cf92013-06-19 10:57:22 +02001451 state->band_start = band + 1;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001452 else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001453 state->band_start = 0;
Johannes Bergee688b002008-01-24 19:38:39 +01001454
Johannes Berg3713b4e2013-02-14 16:19:38 +01001455 /* if bands & channels are done, continue outside */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001456 if (state->band_start == 0 && state->chan_start == 0)
1457 state->split_start++;
1458 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001459 break;
1460 case 4:
1461 nl_cmds = nla_nest_start(msg, NL80211_ATTR_SUPPORTED_COMMANDS);
1462 if (!nl_cmds)
David S. Miller9360ffd2012-03-29 04:41:26 -04001463 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001464
1465 i = 0;
1466#define CMD(op, n) \
1467 do { \
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001468 if (rdev->ops->op) { \
Johannes Berg3713b4e2013-02-14 16:19:38 +01001469 i++; \
1470 if (nla_put_u32(msg, i, NL80211_CMD_ ## n)) \
1471 goto nla_put_failure; \
1472 } \
1473 } while (0)
1474
1475 CMD(add_virtual_intf, NEW_INTERFACE);
1476 CMD(change_virtual_intf, SET_INTERFACE);
1477 CMD(add_key, NEW_KEY);
1478 CMD(start_ap, START_AP);
1479 CMD(add_station, NEW_STATION);
1480 CMD(add_mpath, NEW_MPATH);
1481 CMD(update_mesh_config, SET_MESH_CONFIG);
1482 CMD(change_bss, SET_BSS);
1483 CMD(auth, AUTHENTICATE);
1484 CMD(assoc, ASSOCIATE);
1485 CMD(deauth, DEAUTHENTICATE);
1486 CMD(disassoc, DISASSOCIATE);
1487 CMD(join_ibss, JOIN_IBSS);
1488 CMD(join_mesh, JOIN_MESH);
1489 CMD(set_pmksa, SET_PMKSA);
1490 CMD(del_pmksa, DEL_PMKSA);
1491 CMD(flush_pmksa, FLUSH_PMKSA);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001492 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001493 CMD(remain_on_channel, REMAIN_ON_CHANNEL);
1494 CMD(set_bitrate_mask, SET_TX_BITRATE_MASK);
1495 CMD(mgmt_tx, FRAME);
1496 CMD(mgmt_tx_cancel_wait, FRAME_WAIT_CANCEL);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001497 if (rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001498 i++;
1499 if (nla_put_u32(msg, i, NL80211_CMD_SET_WIPHY_NETNS))
1500 goto nla_put_failure;
1501 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001502 if (rdev->ops->set_monitor_channel || rdev->ops->start_ap ||
1503 rdev->ops->join_mesh) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001504 i++;
1505 if (nla_put_u32(msg, i, NL80211_CMD_SET_CHANNEL))
1506 goto nla_put_failure;
1507 }
1508 CMD(set_wds_peer, SET_WDS_PEER);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001509 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001510 CMD(tdls_mgmt, TDLS_MGMT);
1511 CMD(tdls_oper, TDLS_OPER);
1512 }
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001513 if (rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001514 CMD(sched_scan_start, START_SCHED_SCAN);
1515 CMD(probe_client, PROBE_CLIENT);
1516 CMD(set_noack_map, SET_NOACK_MAP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001517 if (rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001518 i++;
1519 if (nla_put_u32(msg, i, NL80211_CMD_REGISTER_BEACONS))
1520 goto nla_put_failure;
1521 }
1522 CMD(start_p2p_device, START_P2P_DEVICE);
1523 CMD(set_mcast_rate, SET_MCAST_RATE);
Johannes Berg02df00e2014-06-10 14:06:25 +02001524#ifdef CONFIG_NL80211_TESTMODE
1525 CMD(testmode_cmd, TESTMODE);
1526#endif
Johannes Berg86e8cf92013-06-19 10:57:22 +02001527 if (state->split) {
Arend van Spriel5de17982013-04-18 15:49:00 +02001528 CMD(crit_proto_start, CRIT_PROTOCOL_START);
1529 CMD(crit_proto_stop, CRIT_PROTOCOL_STOP);
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001530 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH)
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02001531 CMD(channel_switch, CHANNEL_SWITCH);
Johannes Berg02df00e2014-06-10 14:06:25 +02001532 CMD(set_qos_map, SET_QOS_MAP);
Johannes Berg723e73a2014-10-22 09:25:06 +02001533 if (rdev->wiphy.features &
1534 NL80211_FEATURE_SUPPORTS_WMM_ADMISSION)
Johannes Berg960d01a2014-09-09 22:55:35 +03001535 CMD(add_tx_ts, ADD_TX_TS);
Arend van Spriel5de17982013-04-18 15:49:00 +02001536 }
Johannes Berg02df00e2014-06-10 14:06:25 +02001537 /* add into the if now */
Johannes Berg8fdc6212009-03-14 09:34:01 +01001538#undef CMD
Samuel Ortizb23aa672009-07-01 21:26:54 +02001539
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001540 if (rdev->ops->connect || rdev->ops->auth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001541 i++;
1542 if (nla_put_u32(msg, i, NL80211_CMD_CONNECT))
Johannes Berg2e161f72010-08-12 15:38:38 +02001543 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001544 }
1545
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001546 if (rdev->ops->disconnect || rdev->ops->deauth) {
Johannes Berg3713b4e2013-02-14 16:19:38 +01001547 i++;
1548 if (nla_put_u32(msg, i, NL80211_CMD_DISCONNECT))
1549 goto nla_put_failure;
1550 }
Johannes Berg74b70a42010-08-24 12:15:53 +02001551
Johannes Berg3713b4e2013-02-14 16:19:38 +01001552 nla_nest_end(msg, nl_cmds);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001553 state->split_start++;
1554 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001555 break;
1556 case 5:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001557 if (rdev->ops->remain_on_channel &&
1558 (rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001559 nla_put_u32(msg,
1560 NL80211_ATTR_MAX_REMAIN_ON_CHANNEL_DURATION,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001561 rdev->wiphy.max_remain_on_channel_duration))
Johannes Berg2e161f72010-08-12 15:38:38 +02001562 goto nla_put_failure;
1563
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001564 if ((rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001565 nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK))
1566 goto nla_put_failure;
Johannes Berg2e161f72010-08-12 15:38:38 +02001567
Johannes Berg3713b4e2013-02-14 16:19:38 +01001568 if (nl80211_send_mgmt_stypes(msg, mgmt_stypes))
1569 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001570 state->split_start++;
1571 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001572 break;
1573 case 6:
Johannes Bergdfb89c52012-06-27 09:23:48 +02001574#ifdef CONFIG_PM
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001575 if (nl80211_send_wowlan(msg, rdev, state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001576 goto nla_put_failure;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001577 state->split_start++;
1578 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001579 break;
1580#else
Johannes Berg86e8cf92013-06-19 10:57:22 +02001581 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001582#endif
1583 case 7:
1584 if (nl80211_put_iftypes(msg, NL80211_ATTR_SOFTWARE_IFTYPES,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001585 rdev->wiphy.software_iftypes))
Johannes Bergff1b6e62011-05-04 15:37:28 +02001586 goto nla_put_failure;
1587
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001588 if (nl80211_put_iface_combinations(&rdev->wiphy, msg,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001589 state->split))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001590 goto nla_put_failure;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001591
Johannes Berg86e8cf92013-06-19 10:57:22 +02001592 state->split_start++;
1593 if (state->split)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001594 break;
1595 case 8:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001596 if ((rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME) &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001597 nla_put_u32(msg, NL80211_ATTR_DEVICE_AP_SME,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001598 rdev->wiphy.ap_sme_capa))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001599 goto nla_put_failure;
1600
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001601 features = rdev->wiphy.features;
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001602 /*
1603 * We can only add the per-channel limit information if the
1604 * dump is split, otherwise it makes it too big. Therefore
1605 * only advertise it in that case.
1606 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001607 if (state->split)
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001608 features |= NL80211_FEATURE_ADVERTISE_CHAN_LIMITS;
1609 if (nla_put_u32(msg, NL80211_ATTR_FEATURE_FLAGS, features))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001610 goto nla_put_failure;
1611
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001612 if (rdev->wiphy.ht_capa_mod_mask &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001613 nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001614 sizeof(*rdev->wiphy.ht_capa_mod_mask),
1615 rdev->wiphy.ht_capa_mod_mask))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001616 goto nla_put_failure;
1617
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001618 if (rdev->wiphy.flags & WIPHY_FLAG_HAVE_AP_SME &&
1619 rdev->wiphy.max_acl_mac_addrs &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001620 nla_put_u32(msg, NL80211_ATTR_MAC_ACL_MAX,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001621 rdev->wiphy.max_acl_mac_addrs))
Johannes Berg3713b4e2013-02-14 16:19:38 +01001622 goto nla_put_failure;
1623
1624 /*
1625 * Any information below this point is only available to
1626 * applications that can deal with it being split. This
1627 * helps ensure that newly added capabilities don't break
1628 * older tools by overrunning their buffers.
1629 *
1630 * We still increment split_start so that in the split
1631 * case we'll continue with more data in the next round,
1632 * but break unconditionally so unsplit data stops here.
1633 */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001634 state->split_start++;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001635 break;
1636 case 9:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001637 if (rdev->wiphy.extended_capabilities &&
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001638 (nla_put(msg, NL80211_ATTR_EXT_CAPA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001639 rdev->wiphy.extended_capabilities_len,
1640 rdev->wiphy.extended_capabilities) ||
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001641 nla_put(msg, NL80211_ATTR_EXT_CAPA_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001642 rdev->wiphy.extended_capabilities_len,
1643 rdev->wiphy.extended_capabilities_mask)))
Johannes Bergfe1abaf2013-02-27 15:39:45 +01001644 goto nla_put_failure;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001645
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001646 if (rdev->wiphy.vht_capa_mod_mask &&
Johannes Bergee2aca32013-02-21 17:36:01 +01001647 nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001648 sizeof(*rdev->wiphy.vht_capa_mod_mask),
1649 rdev->wiphy.vht_capa_mod_mask))
Johannes Bergee2aca32013-02-21 17:36:01 +01001650 goto nla_put_failure;
1651
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001652 state->split_start++;
1653 break;
1654 case 10:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001655 if (nl80211_send_coalesce(msg, rdev))
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07001656 goto nla_put_failure;
1657
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001658 if ((rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ) &&
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001659 (nla_put_flag(msg, NL80211_ATTR_SUPPORT_5_MHZ) ||
1660 nla_put_flag(msg, NL80211_ATTR_SUPPORT_10_MHZ)))
1661 goto nla_put_failure;
Jouni Malinenb43504c2014-01-15 00:01:08 +02001662
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001663 if (rdev->wiphy.max_ap_assoc_sta &&
Jouni Malinenb43504c2014-01-15 00:01:08 +02001664 nla_put_u32(msg, NL80211_ATTR_MAX_AP_ASSOC_STA,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001665 rdev->wiphy.max_ap_assoc_sta))
Jouni Malinenb43504c2014-01-15 00:01:08 +02001666 goto nla_put_failure;
1667
Johannes Bergad7e7182013-11-13 13:37:47 +01001668 state->split_start++;
1669 break;
1670 case 11:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001671 if (rdev->wiphy.n_vendor_commands) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001672 const struct nl80211_vendor_cmd_info *info;
1673 struct nlattr *nested;
Johannes Bergad7e7182013-11-13 13:37:47 +01001674
Johannes Berg567ffc32013-12-18 14:43:31 +01001675 nested = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA);
1676 if (!nested)
Johannes Bergad7e7182013-11-13 13:37:47 +01001677 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01001678
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001679 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
1680 info = &rdev->wiphy.vendor_commands[i].info;
Johannes Berg567ffc32013-12-18 14:43:31 +01001681 if (nla_put(msg, i + 1, sizeof(*info), info))
1682 goto nla_put_failure;
1683 }
1684 nla_nest_end(msg, nested);
1685 }
1686
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001687 if (rdev->wiphy.n_vendor_events) {
Johannes Berg567ffc32013-12-18 14:43:31 +01001688 const struct nl80211_vendor_cmd_info *info;
1689 struct nlattr *nested;
1690
1691 nested = nla_nest_start(msg,
1692 NL80211_ATTR_VENDOR_EVENTS);
1693 if (!nested)
1694 goto nla_put_failure;
1695
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001696 for (i = 0; i < rdev->wiphy.n_vendor_events; i++) {
1697 info = &rdev->wiphy.vendor_events[i];
Johannes Berg567ffc32013-12-18 14:43:31 +01001698 if (nla_put(msg, i + 1, sizeof(*info), info))
1699 goto nla_put_failure;
1700 }
1701 nla_nest_end(msg, nested);
1702 }
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03001703 state->split_start++;
1704 break;
1705 case 12:
1706 if (rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH &&
1707 nla_put_u8(msg, NL80211_ATTR_MAX_CSA_COUNTERS,
1708 rdev->wiphy.max_num_csa_counters))
1709 goto nla_put_failure;
Felix Fietkau01e0daa2013-11-09 14:57:54 +01001710
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02001711 if (rdev->wiphy.regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
1712 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
1713 goto nla_put_failure;
1714
Gautam Kumar Shuklad75bb062014-12-23 16:55:19 +01001715 if (nla_put(msg, NL80211_ATTR_EXT_FEATURES,
1716 sizeof(rdev->wiphy.ext_features),
1717 rdev->wiphy.ext_features))
1718 goto nla_put_failure;
1719
Johannes Berg3713b4e2013-02-14 16:19:38 +01001720 /* done */
Johannes Berg86e8cf92013-06-19 10:57:22 +02001721 state->split_start = 0;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001722 break;
Johannes Bergff1b6e62011-05-04 15:37:28 +02001723 }
Johannes Berg3bb20552014-05-26 13:52:25 +02001724 finish:
Johannes Berg053c0952015-01-16 22:09:00 +01001725 genlmsg_end(msg, hdr);
1726 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04001727
1728 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07001729 genlmsg_cancel(msg, hdr);
1730 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04001731}
1732
Johannes Berg86e8cf92013-06-19 10:57:22 +02001733static int nl80211_dump_wiphy_parse(struct sk_buff *skb,
1734 struct netlink_callback *cb,
1735 struct nl80211_dump_wiphy_state *state)
1736{
1737 struct nlattr **tb = nl80211_fam.attrbuf;
1738 int ret = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
1739 tb, nl80211_fam.maxattr, nl80211_policy);
1740 /* ignore parse errors for backward compatibility */
1741 if (ret)
1742 return 0;
1743
1744 state->split = tb[NL80211_ATTR_SPLIT_WIPHY_DUMP];
1745 if (tb[NL80211_ATTR_WIPHY])
1746 state->filter_wiphy = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
1747 if (tb[NL80211_ATTR_WDEV])
1748 state->filter_wiphy = nla_get_u64(tb[NL80211_ATTR_WDEV]) >> 32;
1749 if (tb[NL80211_ATTR_IFINDEX]) {
1750 struct net_device *netdev;
1751 struct cfg80211_registered_device *rdev;
1752 int ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
1753
Ying Xue7f2b8562014-01-15 10:23:45 +08001754 netdev = __dev_get_by_index(sock_net(skb->sk), ifidx);
Johannes Berg86e8cf92013-06-19 10:57:22 +02001755 if (!netdev)
1756 return -ENODEV;
1757 if (netdev->ieee80211_ptr) {
Zhao, Gangf26cbf42014-04-21 12:53:03 +08001758 rdev = wiphy_to_rdev(
Johannes Berg86e8cf92013-06-19 10:57:22 +02001759 netdev->ieee80211_ptr->wiphy);
1760 state->filter_wiphy = rdev->wiphy_idx;
1761 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001762 }
1763
1764 return 0;
1765}
1766
Johannes Berg55682962007-09-20 13:09:35 -04001767static int nl80211_dump_wiphy(struct sk_buff *skb, struct netlink_callback *cb)
1768{
Johannes Berg645e77d2013-03-01 14:03:49 +01001769 int idx = 0, ret;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001770 struct nl80211_dump_wiphy_state *state = (void *)cb->args[0];
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001771 struct cfg80211_registered_device *rdev;
Johannes Berg3a5a4232013-06-19 10:09:57 +02001772
Johannes Berg5fe231e2013-05-08 21:45:15 +02001773 rtnl_lock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001774 if (!state) {
1775 state = kzalloc(sizeof(*state), GFP_KERNEL);
John W. Linville57ed5cd2013-06-28 13:18:21 -04001776 if (!state) {
1777 rtnl_unlock();
Johannes Berg86e8cf92013-06-19 10:57:22 +02001778 return -ENOMEM;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001779 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001780 state->filter_wiphy = -1;
1781 ret = nl80211_dump_wiphy_parse(skb, cb, state);
1782 if (ret) {
1783 kfree(state);
1784 rtnl_unlock();
1785 return ret;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001786 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001787 cb->args[0] = (long)state;
Johannes Berg3713b4e2013-02-14 16:19:38 +01001788 }
1789
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001790 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
1791 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02001792 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001793 if (++idx <= state->start)
Johannes Berg55682962007-09-20 13:09:35 -04001794 continue;
Johannes Berg86e8cf92013-06-19 10:57:22 +02001795 if (state->filter_wiphy != -1 &&
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001796 state->filter_wiphy != rdev->wiphy_idx)
Johannes Berg3713b4e2013-02-14 16:19:38 +01001797 continue;
1798 /* attempt to fit multiple wiphy data chunks into the skb */
1799 do {
Johannes Berg3bb20552014-05-26 13:52:25 +02001800 ret = nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY,
1801 skb,
Johannes Berg3713b4e2013-02-14 16:19:38 +01001802 NETLINK_CB(cb->skb).portid,
1803 cb->nlh->nlmsg_seq,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001804 NLM_F_MULTI, state);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001805 if (ret < 0) {
1806 /*
1807 * If sending the wiphy data didn't fit (ENOBUFS
1808 * or EMSGSIZE returned), this SKB is still
1809 * empty (so it's not too big because another
1810 * wiphy dataset is already in the skb) and
1811 * we've not tried to adjust the dump allocation
1812 * yet ... then adjust the alloc size to be
1813 * bigger, and return 1 but with the empty skb.
1814 * This results in an empty message being RX'ed
1815 * in userspace, but that is ignored.
1816 *
1817 * We can then retry with the larger buffer.
1818 */
1819 if ((ret == -ENOBUFS || ret == -EMSGSIZE) &&
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001820 !skb->len && !state->split &&
Johannes Berg3713b4e2013-02-14 16:19:38 +01001821 cb->min_dump_alloc < 4096) {
1822 cb->min_dump_alloc = 4096;
Pontus Fuchsf12cb282014-01-16 15:00:40 +01001823 state->split_start = 0;
David S. Millerd98cae64e2013-06-19 16:49:39 -07001824 rtnl_unlock();
Johannes Berg3713b4e2013-02-14 16:19:38 +01001825 return 1;
1826 }
1827 idx--;
1828 break;
Johannes Berg645e77d2013-03-01 14:03:49 +01001829 }
Johannes Berg86e8cf92013-06-19 10:57:22 +02001830 } while (state->split_start > 0);
Johannes Berg3713b4e2013-02-14 16:19:38 +01001831 break;
Johannes Berg55682962007-09-20 13:09:35 -04001832 }
Johannes Berg5fe231e2013-05-08 21:45:15 +02001833 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04001834
Johannes Berg86e8cf92013-06-19 10:57:22 +02001835 state->start = idx;
Johannes Berg55682962007-09-20 13:09:35 -04001836
1837 return skb->len;
1838}
1839
Johannes Berg86e8cf92013-06-19 10:57:22 +02001840static int nl80211_dump_wiphy_done(struct netlink_callback *cb)
1841{
1842 kfree((void *)cb->args[0]);
1843 return 0;
1844}
1845
Johannes Berg55682962007-09-20 13:09:35 -04001846static int nl80211_get_wiphy(struct sk_buff *skb, struct genl_info *info)
1847{
1848 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08001849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg86e8cf92013-06-19 10:57:22 +02001850 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -04001851
Johannes Berg645e77d2013-03-01 14:03:49 +01001852 msg = nlmsg_new(4096, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04001853 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02001854 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04001855
Johannes Berg3bb20552014-05-26 13:52:25 +02001856 if (nl80211_send_wiphy(rdev, NL80211_CMD_NEW_WIPHY, msg,
1857 info->snd_portid, info->snd_seq, 0,
Johannes Berg86e8cf92013-06-19 10:57:22 +02001858 &state) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02001859 nlmsg_free(msg);
1860 return -ENOBUFS;
1861 }
Johannes Berg55682962007-09-20 13:09:35 -04001862
Johannes Berg134e6372009-07-10 09:51:34 +00001863 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04001864}
1865
Jouni Malinen31888482008-10-30 16:59:24 +02001866static const struct nla_policy txq_params_policy[NL80211_TXQ_ATTR_MAX + 1] = {
1867 [NL80211_TXQ_ATTR_QUEUE] = { .type = NLA_U8 },
1868 [NL80211_TXQ_ATTR_TXOP] = { .type = NLA_U16 },
1869 [NL80211_TXQ_ATTR_CWMIN] = { .type = NLA_U16 },
1870 [NL80211_TXQ_ATTR_CWMAX] = { .type = NLA_U16 },
1871 [NL80211_TXQ_ATTR_AIFS] = { .type = NLA_U8 },
1872};
1873
1874static int parse_txq_params(struct nlattr *tb[],
1875 struct ieee80211_txq_params *txq_params)
1876{
Johannes Berga3304b02012-03-28 11:04:24 +02001877 if (!tb[NL80211_TXQ_ATTR_AC] || !tb[NL80211_TXQ_ATTR_TXOP] ||
Jouni Malinen31888482008-10-30 16:59:24 +02001878 !tb[NL80211_TXQ_ATTR_CWMIN] || !tb[NL80211_TXQ_ATTR_CWMAX] ||
1879 !tb[NL80211_TXQ_ATTR_AIFS])
1880 return -EINVAL;
1881
Johannes Berga3304b02012-03-28 11:04:24 +02001882 txq_params->ac = nla_get_u8(tb[NL80211_TXQ_ATTR_AC]);
Jouni Malinen31888482008-10-30 16:59:24 +02001883 txq_params->txop = nla_get_u16(tb[NL80211_TXQ_ATTR_TXOP]);
1884 txq_params->cwmin = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMIN]);
1885 txq_params->cwmax = nla_get_u16(tb[NL80211_TXQ_ATTR_CWMAX]);
1886 txq_params->aifs = nla_get_u8(tb[NL80211_TXQ_ATTR_AIFS]);
1887
Johannes Berga3304b02012-03-28 11:04:24 +02001888 if (txq_params->ac >= NL80211_NUM_ACS)
1889 return -EINVAL;
1890
Jouni Malinen31888482008-10-30 16:59:24 +02001891 return 0;
1892}
1893
Johannes Bergf444de02010-05-05 15:25:02 +02001894static bool nl80211_can_set_dev_channel(struct wireless_dev *wdev)
1895{
1896 /*
Johannes Bergcc1d2802012-05-16 23:50:20 +02001897 * You can only set the channel explicitly for WDS interfaces,
1898 * all others have their channel managed via their respective
1899 * "establish a connection" command (connect, join, ...)
1900 *
1901 * For AP/GO and mesh mode, the channel can be set with the
1902 * channel userspace API, but is only stored and passed to the
1903 * low-level driver when the AP starts or the mesh is joined.
1904 * This is for backward compatibility, userspace can also give
1905 * the channel in the start-ap or join-mesh commands instead.
Johannes Bergf444de02010-05-05 15:25:02 +02001906 *
1907 * Monitors are special as they are normally slaved to
Johannes Berge8c9bd52012-06-06 08:18:22 +02001908 * whatever else is going on, so they have their own special
1909 * operation to set the monitor channel if possible.
Johannes Bergf444de02010-05-05 15:25:02 +02001910 */
1911 return !wdev ||
1912 wdev->iftype == NL80211_IFTYPE_AP ||
Johannes Bergf444de02010-05-05 15:25:02 +02001913 wdev->iftype == NL80211_IFTYPE_MESH_POINT ||
Johannes Berg074ac8d2010-09-16 14:58:22 +02001914 wdev->iftype == NL80211_IFTYPE_MONITOR ||
1915 wdev->iftype == NL80211_IFTYPE_P2P_GO;
Johannes Bergf444de02010-05-05 15:25:02 +02001916}
1917
Johannes Berg683b6d32012-11-08 21:25:48 +01001918static int nl80211_parse_chandef(struct cfg80211_registered_device *rdev,
1919 struct genl_info *info,
1920 struct cfg80211_chan_def *chandef)
1921{
Mahesh Paliveladbeca2e2012-11-29 14:11:07 +05301922 u32 control_freq;
Johannes Berg683b6d32012-11-08 21:25:48 +01001923
1924 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
1925 return -EINVAL;
1926
1927 control_freq = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_FREQ]);
1928
1929 chandef->chan = ieee80211_get_channel(&rdev->wiphy, control_freq);
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001930 chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
1931 chandef->center_freq1 = control_freq;
1932 chandef->center_freq2 = 0;
Johannes Berg683b6d32012-11-08 21:25:48 +01001933
1934 /* Primary channel not allowed */
1935 if (!chandef->chan || chandef->chan->flags & IEEE80211_CHAN_DISABLED)
1936 return -EINVAL;
1937
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001938 if (info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) {
1939 enum nl80211_channel_type chantype;
Johannes Berg683b6d32012-11-08 21:25:48 +01001940
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001941 chantype = nla_get_u32(
1942 info->attrs[NL80211_ATTR_WIPHY_CHANNEL_TYPE]);
1943
1944 switch (chantype) {
1945 case NL80211_CHAN_NO_HT:
1946 case NL80211_CHAN_HT20:
1947 case NL80211_CHAN_HT40PLUS:
1948 case NL80211_CHAN_HT40MINUS:
1949 cfg80211_chandef_create(chandef, chandef->chan,
1950 chantype);
1951 break;
1952 default:
Johannes Berg683b6d32012-11-08 21:25:48 +01001953 return -EINVAL;
Johannes Berg683b6d32012-11-08 21:25:48 +01001954 }
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001955 } else if (info->attrs[NL80211_ATTR_CHANNEL_WIDTH]) {
1956 chandef->width =
1957 nla_get_u32(info->attrs[NL80211_ATTR_CHANNEL_WIDTH]);
1958 if (info->attrs[NL80211_ATTR_CENTER_FREQ1])
1959 chandef->center_freq1 =
1960 nla_get_u32(
1961 info->attrs[NL80211_ATTR_CENTER_FREQ1]);
1962 if (info->attrs[NL80211_ATTR_CENTER_FREQ2])
1963 chandef->center_freq2 =
1964 nla_get_u32(
1965 info->attrs[NL80211_ATTR_CENTER_FREQ2]);
1966 }
1967
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001968 if (!cfg80211_chandef_valid(chandef))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001969 return -EINVAL;
1970
Johannes Berg9f5e8f62012-11-22 16:59:45 +01001971 if (!cfg80211_chandef_usable(&rdev->wiphy, chandef,
1972 IEEE80211_CHAN_DISABLED))
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001973 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01001974
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02001975 if ((chandef->width == NL80211_CHAN_WIDTH_5 ||
1976 chandef->width == NL80211_CHAN_WIDTH_10) &&
1977 !(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_5_10_MHZ))
1978 return -EINVAL;
1979
Johannes Berg683b6d32012-11-08 21:25:48 +01001980 return 0;
1981}
1982
Johannes Bergf444de02010-05-05 15:25:02 +02001983static int __nl80211_set_channel(struct cfg80211_registered_device *rdev,
Jouni Malinene16821b2014-04-28 11:22:08 +03001984 struct net_device *dev,
Johannes Bergf444de02010-05-05 15:25:02 +02001985 struct genl_info *info)
1986{
Johannes Berg683b6d32012-11-08 21:25:48 +01001987 struct cfg80211_chan_def chandef;
Johannes Bergf444de02010-05-05 15:25:02 +02001988 int result;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001989 enum nl80211_iftype iftype = NL80211_IFTYPE_MONITOR;
Jouni Malinene16821b2014-04-28 11:22:08 +03001990 struct wireless_dev *wdev = NULL;
Johannes Berge8c9bd52012-06-06 08:18:22 +02001991
Jouni Malinene16821b2014-04-28 11:22:08 +03001992 if (dev)
1993 wdev = dev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02001994 if (!nl80211_can_set_dev_channel(wdev))
1995 return -EOPNOTSUPP;
Jouni Malinene16821b2014-04-28 11:22:08 +03001996 if (wdev)
1997 iftype = wdev->iftype;
Johannes Bergf444de02010-05-05 15:25:02 +02001998
Johannes Berg683b6d32012-11-08 21:25:48 +01001999 result = nl80211_parse_chandef(rdev, info, &chandef);
2000 if (result)
2001 return result;
Johannes Bergf444de02010-05-05 15:25:02 +02002002
Johannes Berge8c9bd52012-06-06 08:18:22 +02002003 switch (iftype) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002004 case NL80211_IFTYPE_AP:
2005 case NL80211_IFTYPE_P2P_GO:
Arik Nemtsov923b3522015-07-08 15:41:44 +03002006 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
2007 iftype)) {
Johannes Bergaa430da2012-05-16 23:50:18 +02002008 result = -EINVAL;
2009 break;
2010 }
Jouni Malinene16821b2014-04-28 11:22:08 +03002011 if (wdev->beacon_interval) {
2012 if (!dev || !rdev->ops->set_ap_chanwidth ||
2013 !(rdev->wiphy.features &
2014 NL80211_FEATURE_AP_MODE_CHAN_WIDTH_CHANGE)) {
2015 result = -EBUSY;
2016 break;
2017 }
2018
2019 /* Only allow dynamic channel width changes */
2020 if (chandef.chan != wdev->preset_chandef.chan) {
2021 result = -EBUSY;
2022 break;
2023 }
2024 result = rdev_set_ap_chanwidth(rdev, dev, &chandef);
2025 if (result)
2026 break;
2027 }
Johannes Berg683b6d32012-11-08 21:25:48 +01002028 wdev->preset_chandef = chandef;
Johannes Bergaa430da2012-05-16 23:50:18 +02002029 result = 0;
2030 break;
Johannes Bergcc1d2802012-05-16 23:50:20 +02002031 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg683b6d32012-11-08 21:25:48 +01002032 result = cfg80211_set_mesh_channel(rdev, wdev, &chandef);
Johannes Bergcc1d2802012-05-16 23:50:20 +02002033 break;
Johannes Berge8c9bd52012-06-06 08:18:22 +02002034 case NL80211_IFTYPE_MONITOR:
Johannes Berg683b6d32012-11-08 21:25:48 +01002035 result = cfg80211_set_monitor_channel(rdev, &chandef);
Johannes Berge8c9bd52012-06-06 08:18:22 +02002036 break;
Johannes Bergaa430da2012-05-16 23:50:18 +02002037 default:
Johannes Berge8c9bd52012-06-06 08:18:22 +02002038 result = -EINVAL;
Johannes Bergf444de02010-05-05 15:25:02 +02002039 }
Johannes Bergf444de02010-05-05 15:25:02 +02002040
2041 return result;
2042}
2043
2044static int nl80211_set_channel(struct sk_buff *skb, struct genl_info *info)
2045{
Johannes Berg4c476992010-10-04 21:36:35 +02002046 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2047 struct net_device *netdev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02002048
Jouni Malinene16821b2014-04-28 11:22:08 +03002049 return __nl80211_set_channel(rdev, netdev, info);
Johannes Bergf444de02010-05-05 15:25:02 +02002050}
2051
Bill Jordane8347eb2010-10-01 13:54:28 -04002052static int nl80211_set_wds_peer(struct sk_buff *skb, struct genl_info *info)
2053{
Johannes Berg43b19952010-10-07 13:10:30 +02002054 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2055 struct net_device *dev = info->user_ptr[1];
2056 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg388ac772010-10-07 13:11:09 +02002057 const u8 *bssid;
Bill Jordane8347eb2010-10-01 13:54:28 -04002058
2059 if (!info->attrs[NL80211_ATTR_MAC])
2060 return -EINVAL;
2061
Johannes Berg43b19952010-10-07 13:10:30 +02002062 if (netif_running(dev))
2063 return -EBUSY;
Bill Jordane8347eb2010-10-01 13:54:28 -04002064
Johannes Berg43b19952010-10-07 13:10:30 +02002065 if (!rdev->ops->set_wds_peer)
2066 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002067
Johannes Berg43b19952010-10-07 13:10:30 +02002068 if (wdev->iftype != NL80211_IFTYPE_WDS)
2069 return -EOPNOTSUPP;
Bill Jordane8347eb2010-10-01 13:54:28 -04002070
2071 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Hila Gonene35e4d22012-06-27 17:19:42 +03002072 return rdev_set_wds_peer(rdev, dev, bssid);
Bill Jordane8347eb2010-10-01 13:54:28 -04002073}
2074
2075
Johannes Berg55682962007-09-20 13:09:35 -04002076static int nl80211_set_wiphy(struct sk_buff *skb, struct genl_info *info)
2077{
2078 struct cfg80211_registered_device *rdev;
Johannes Bergf444de02010-05-05 15:25:02 +02002079 struct net_device *netdev = NULL;
2080 struct wireless_dev *wdev;
Bill Jordana1e567c2010-09-10 11:22:32 -04002081 int result = 0, rem_txq_params = 0;
Jouni Malinen31888482008-10-30 16:59:24 +02002082 struct nlattr *nl_txq_params;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002083 u32 changed;
2084 u8 retry_short = 0, retry_long = 0;
2085 u32 frag_threshold = 0, rts_threshold = 0;
Lukáš Turek81077e82009-12-21 22:50:47 +01002086 u8 coverage_class = 0;
Johannes Berg55682962007-09-20 13:09:35 -04002087
Johannes Berg5fe231e2013-05-08 21:45:15 +02002088 ASSERT_RTNL();
2089
Johannes Bergf444de02010-05-05 15:25:02 +02002090 /*
2091 * Try to find the wiphy and netdev. Normally this
2092 * function shouldn't need the netdev, but this is
2093 * done for backward compatibility -- previously
2094 * setting the channel was done per wiphy, but now
2095 * it is per netdev. Previous userland like hostapd
2096 * also passed a netdev to set_wiphy, so that it is
2097 * possible to let that go to the right netdev!
2098 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002099
Johannes Bergf444de02010-05-05 15:25:02 +02002100 if (info->attrs[NL80211_ATTR_IFINDEX]) {
2101 int ifindex = nla_get_u32(info->attrs[NL80211_ATTR_IFINDEX]);
2102
Ying Xue7f2b8562014-01-15 10:23:45 +08002103 netdev = __dev_get_by_index(genl_info_net(info), ifindex);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002104 if (netdev && netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002105 rdev = wiphy_to_rdev(netdev->ieee80211_ptr->wiphy);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002106 else
Johannes Bergf444de02010-05-05 15:25:02 +02002107 netdev = NULL;
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002108 }
2109
Johannes Bergf444de02010-05-05 15:25:02 +02002110 if (!netdev) {
Johannes Berg878d9ec2012-06-15 14:18:32 +02002111 rdev = __cfg80211_rdev_from_attrs(genl_info_net(info),
2112 info->attrs);
Johannes Berg5fe231e2013-05-08 21:45:15 +02002113 if (IS_ERR(rdev))
Johannes Berg4c476992010-10-04 21:36:35 +02002114 return PTR_ERR(rdev);
Johannes Bergf444de02010-05-05 15:25:02 +02002115 wdev = NULL;
2116 netdev = NULL;
2117 result = 0;
Johannes Berg71fe96b2012-10-24 10:04:58 +02002118 } else
Johannes Bergf444de02010-05-05 15:25:02 +02002119 wdev = netdev->ieee80211_ptr;
Johannes Bergf444de02010-05-05 15:25:02 +02002120
2121 /*
2122 * end workaround code, by now the rdev is available
2123 * and locked, and wdev may or may not be NULL.
2124 */
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002125
2126 if (info->attrs[NL80211_ATTR_WIPHY_NAME])
Jouni Malinen31888482008-10-30 16:59:24 +02002127 result = cfg80211_dev_rename(
2128 rdev, nla_data(info->attrs[NL80211_ATTR_WIPHY_NAME]));
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002129
Johannes Berg4bbf4d52009-03-24 09:35:46 +01002130 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002131 return result;
Johannes Berg55682962007-09-20 13:09:35 -04002132
Jouni Malinen31888482008-10-30 16:59:24 +02002133 if (info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS]) {
2134 struct ieee80211_txq_params txq_params;
2135 struct nlattr *tb[NL80211_TXQ_ATTR_MAX + 1];
2136
Ying Xue7f2b8562014-01-15 10:23:45 +08002137 if (!rdev->ops->set_txq_params)
2138 return -EOPNOTSUPP;
Jouni Malinen31888482008-10-30 16:59:24 +02002139
Ying Xue7f2b8562014-01-15 10:23:45 +08002140 if (!netdev)
2141 return -EINVAL;
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002142
Johannes Berg133a3ff2011-11-03 14:50:13 +01002143 if (netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002144 netdev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
2145 return -EINVAL;
Johannes Berg133a3ff2011-11-03 14:50:13 +01002146
Ying Xue7f2b8562014-01-15 10:23:45 +08002147 if (!netif_running(netdev))
2148 return -ENETDOWN;
Johannes Berg2b5f8b02012-04-02 10:51:55 +02002149
Jouni Malinen31888482008-10-30 16:59:24 +02002150 nla_for_each_nested(nl_txq_params,
2151 info->attrs[NL80211_ATTR_WIPHY_TXQ_PARAMS],
2152 rem_txq_params) {
Johannes Bergae811e22014-01-24 10:17:47 +01002153 result = nla_parse(tb, NL80211_TXQ_ATTR_MAX,
2154 nla_data(nl_txq_params),
2155 nla_len(nl_txq_params),
2156 txq_params_policy);
2157 if (result)
2158 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002159 result = parse_txq_params(tb, &txq_params);
2160 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002161 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002162
Hila Gonene35e4d22012-06-27 17:19:42 +03002163 result = rdev_set_txq_params(rdev, netdev,
2164 &txq_params);
Jouni Malinen31888482008-10-30 16:59:24 +02002165 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002166 return result;
Jouni Malinen31888482008-10-30 16:59:24 +02002167 }
2168 }
2169
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002170 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinene16821b2014-04-28 11:22:08 +03002171 result = __nl80211_set_channel(
2172 rdev,
2173 nl80211_can_set_dev_channel(wdev) ? netdev : NULL,
2174 info);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002175 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002176 return result;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002177 }
2178
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002179 if (info->attrs[NL80211_ATTR_WIPHY_TX_POWER_SETTING]) {
Johannes Bergc8442112012-10-24 10:17:18 +02002180 struct wireless_dev *txp_wdev = wdev;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002181 enum nl80211_tx_power_setting type;
2182 int idx, mbm = 0;
2183
Johannes Bergc8442112012-10-24 10:17:18 +02002184 if (!(rdev->wiphy.features & NL80211_FEATURE_VIF_TXPOWER))
2185 txp_wdev = NULL;
2186
Ying Xue7f2b8562014-01-15 10:23:45 +08002187 if (!rdev->ops->set_tx_power)
2188 return -EOPNOTSUPP;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002189
2190 idx = NL80211_ATTR_WIPHY_TX_POWER_SETTING;
2191 type = nla_get_u32(info->attrs[idx]);
2192
2193 if (!info->attrs[NL80211_ATTR_WIPHY_TX_POWER_LEVEL] &&
Ying Xue7f2b8562014-01-15 10:23:45 +08002194 (type != NL80211_TX_POWER_AUTOMATIC))
2195 return -EINVAL;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002196
2197 if (type != NL80211_TX_POWER_AUTOMATIC) {
2198 idx = NL80211_ATTR_WIPHY_TX_POWER_LEVEL;
2199 mbm = nla_get_u32(info->attrs[idx]);
2200 }
2201
Johannes Bergc8442112012-10-24 10:17:18 +02002202 result = rdev_set_tx_power(rdev, txp_wdev, type, mbm);
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002203 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002204 return result;
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +03002205 }
2206
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002207 if (info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX] &&
2208 info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]) {
2209 u32 tx_ant, rx_ant;
Bruno Randolf7f531e02010-12-16 11:30:22 +09002210 if ((!rdev->wiphy.available_antennas_tx &&
2211 !rdev->wiphy.available_antennas_rx) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002212 !rdev->ops->set_antenna)
2213 return -EOPNOTSUPP;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002214
2215 tx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_TX]);
2216 rx_ant = nla_get_u32(info->attrs[NL80211_ATTR_WIPHY_ANTENNA_RX]);
2217
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002218 /* reject antenna configurations which don't match the
Bruno Randolf7f531e02010-12-16 11:30:22 +09002219 * available antenna masks, except for the "all" mask */
2220 if ((~tx_ant && (tx_ant & ~rdev->wiphy.available_antennas_tx)) ||
Ying Xue7f2b8562014-01-15 10:23:45 +08002221 (~rx_ant && (rx_ant & ~rdev->wiphy.available_antennas_rx)))
2222 return -EINVAL;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002223
Bruno Randolf7f531e02010-12-16 11:30:22 +09002224 tx_ant = tx_ant & rdev->wiphy.available_antennas_tx;
2225 rx_ant = rx_ant & rdev->wiphy.available_antennas_rx;
Bruno Randolfa7ffac92010-12-08 13:59:24 +09002226
Hila Gonene35e4d22012-06-27 17:19:42 +03002227 result = rdev_set_antenna(rdev, tx_ant, rx_ant);
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002228 if (result)
Ying Xue7f2b8562014-01-15 10:23:45 +08002229 return result;
Bruno Randolfafe0cbf2010-11-10 12:50:50 +09002230 }
2231
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002232 changed = 0;
2233
2234 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]) {
2235 retry_short = nla_get_u8(
2236 info->attrs[NL80211_ATTR_WIPHY_RETRY_SHORT]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002237 if (retry_short == 0)
2238 return -EINVAL;
2239
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002240 changed |= WIPHY_PARAM_RETRY_SHORT;
2241 }
2242
2243 if (info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]) {
2244 retry_long = nla_get_u8(
2245 info->attrs[NL80211_ATTR_WIPHY_RETRY_LONG]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002246 if (retry_long == 0)
2247 return -EINVAL;
2248
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002249 changed |= WIPHY_PARAM_RETRY_LONG;
2250 }
2251
2252 if (info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]) {
2253 frag_threshold = nla_get_u32(
2254 info->attrs[NL80211_ATTR_WIPHY_FRAG_THRESHOLD]);
Ying Xue7f2b8562014-01-15 10:23:45 +08002255 if (frag_threshold < 256)
2256 return -EINVAL;
2257
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002258 if (frag_threshold != (u32) -1) {
2259 /*
2260 * Fragments (apart from the last one) are required to
2261 * have even length. Make the fragmentation code
2262 * simpler by stripping LSB should someone try to use
2263 * odd threshold value.
2264 */
2265 frag_threshold &= ~0x1;
2266 }
2267 changed |= WIPHY_PARAM_FRAG_THRESHOLD;
2268 }
2269
2270 if (info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]) {
2271 rts_threshold = nla_get_u32(
2272 info->attrs[NL80211_ATTR_WIPHY_RTS_THRESHOLD]);
2273 changed |= WIPHY_PARAM_RTS_THRESHOLD;
2274 }
2275
Lukáš Turek81077e82009-12-21 22:50:47 +01002276 if (info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]) {
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002277 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK])
2278 return -EINVAL;
2279
Lukáš Turek81077e82009-12-21 22:50:47 +01002280 coverage_class = nla_get_u8(
2281 info->attrs[NL80211_ATTR_WIPHY_COVERAGE_CLASS]);
2282 changed |= WIPHY_PARAM_COVERAGE_CLASS;
2283 }
2284
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +02002285 if (info->attrs[NL80211_ATTR_WIPHY_DYN_ACK]) {
2286 if (!(rdev->wiphy.features & NL80211_FEATURE_ACKTO_ESTIMATION))
2287 return -EOPNOTSUPP;
2288
2289 changed |= WIPHY_PARAM_DYN_ACK;
2290 }
2291
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002292 if (changed) {
2293 u8 old_retry_short, old_retry_long;
2294 u32 old_frag_threshold, old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002295 u8 old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002296
Ying Xue7f2b8562014-01-15 10:23:45 +08002297 if (!rdev->ops->set_wiphy_params)
2298 return -EOPNOTSUPP;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002299
2300 old_retry_short = rdev->wiphy.retry_short;
2301 old_retry_long = rdev->wiphy.retry_long;
2302 old_frag_threshold = rdev->wiphy.frag_threshold;
2303 old_rts_threshold = rdev->wiphy.rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002304 old_coverage_class = rdev->wiphy.coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002305
2306 if (changed & WIPHY_PARAM_RETRY_SHORT)
2307 rdev->wiphy.retry_short = retry_short;
2308 if (changed & WIPHY_PARAM_RETRY_LONG)
2309 rdev->wiphy.retry_long = retry_long;
2310 if (changed & WIPHY_PARAM_FRAG_THRESHOLD)
2311 rdev->wiphy.frag_threshold = frag_threshold;
2312 if (changed & WIPHY_PARAM_RTS_THRESHOLD)
2313 rdev->wiphy.rts_threshold = rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002314 if (changed & WIPHY_PARAM_COVERAGE_CLASS)
2315 rdev->wiphy.coverage_class = coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002316
Hila Gonene35e4d22012-06-27 17:19:42 +03002317 result = rdev_set_wiphy_params(rdev, changed);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002318 if (result) {
2319 rdev->wiphy.retry_short = old_retry_short;
2320 rdev->wiphy.retry_long = old_retry_long;
2321 rdev->wiphy.frag_threshold = old_frag_threshold;
2322 rdev->wiphy.rts_threshold = old_rts_threshold;
Lukáš Turek81077e82009-12-21 22:50:47 +01002323 rdev->wiphy.coverage_class = old_coverage_class;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002324 }
2325 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002326 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002327}
2328
Johannes Berg71bbc992012-06-15 15:30:18 +02002329static inline u64 wdev_id(struct wireless_dev *wdev)
2330{
2331 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002332 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002333}
Johannes Berg55682962007-09-20 13:09:35 -04002334
Johannes Berg683b6d32012-11-08 21:25:48 +01002335static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002336 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002337{
Johannes Berg601555c2014-11-27 17:26:56 +01002338 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2339 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002340
Johannes Berg683b6d32012-11-08 21:25:48 +01002341 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2342 chandef->chan->center_freq))
2343 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002344 switch (chandef->width) {
2345 case NL80211_CHAN_WIDTH_20_NOHT:
2346 case NL80211_CHAN_WIDTH_20:
2347 case NL80211_CHAN_WIDTH_40:
2348 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2349 cfg80211_get_chandef_type(chandef)))
2350 return -ENOBUFS;
2351 break;
2352 default:
2353 break;
2354 }
2355 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2356 return -ENOBUFS;
2357 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2358 return -ENOBUFS;
2359 if (chandef->center_freq2 &&
2360 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002361 return -ENOBUFS;
2362 return 0;
2363}
2364
Eric W. Biederman15e47302012-09-07 20:12:54 +00002365static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002366 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002367 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002368{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002369 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002370 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002371 void *hdr;
2372
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002373 if (removal)
2374 cmd = NL80211_CMD_DEL_INTERFACE;
2375
2376 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002377 if (!hdr)
2378 return -1;
2379
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002380 if (dev &&
2381 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002382 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002383 goto nla_put_failure;
2384
2385 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2386 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002387 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002388 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002389 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2390 rdev->devlist_generation ^
2391 (cfg80211_rdev_list_generation << 2)))
2392 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002393
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002394 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002395 int ret;
2396 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002397
Johannes Berg683b6d32012-11-08 21:25:48 +01002398 ret = rdev_get_channel(rdev, wdev, &chandef);
2399 if (ret == 0) {
2400 if (nl80211_send_chandef(msg, &chandef))
2401 goto nla_put_failure;
2402 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002403 }
2404
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002405 if (wdev->ssid_len) {
2406 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2407 goto nla_put_failure;
2408 }
2409
Johannes Berg053c0952015-01-16 22:09:00 +01002410 genlmsg_end(msg, hdr);
2411 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002412
2413 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002414 genlmsg_cancel(msg, hdr);
2415 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002416}
2417
2418static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2419{
2420 int wp_idx = 0;
2421 int if_idx = 0;
2422 int wp_start = cb->args[0];
2423 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002424 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002425 struct wireless_dev *wdev;
2426
Johannes Berg5fe231e2013-05-08 21:45:15 +02002427 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002428 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2429 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002430 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002431 if (wp_idx < wp_start) {
2432 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002433 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002434 }
Johannes Berg55682962007-09-20 13:09:35 -04002435 if_idx = 0;
2436
Johannes Berg89a54e42012-06-15 14:33:17 +02002437 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002438 if (if_idx < if_start) {
2439 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002440 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002441 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002442 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002443 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002444 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002445 goto out;
2446 }
2447 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002448 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002449
2450 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002451 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002452 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002453 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002454
2455 cb->args[0] = wp_idx;
2456 cb->args[1] = if_idx;
2457
2458 return skb->len;
2459}
2460
2461static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2462{
2463 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002464 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002465 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002466
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002467 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002468 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002469 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002470
Eric W. Biederman15e47302012-09-07 20:12:54 +00002471 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002472 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002473 nlmsg_free(msg);
2474 return -ENOBUFS;
2475 }
Johannes Berg55682962007-09-20 13:09:35 -04002476
Johannes Berg134e6372009-07-10 09:51:34 +00002477 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002478}
2479
Michael Wu66f7ac52008-01-31 19:48:22 +01002480static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2481 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2482 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2483 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2484 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2485 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002486 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002487};
2488
2489static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2490{
2491 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2492 int flag;
2493
2494 *mntrflags = 0;
2495
2496 if (!nla)
2497 return -EINVAL;
2498
2499 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2500 nla, mntr_flags_policy))
2501 return -EINVAL;
2502
2503 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2504 if (flags[flag])
2505 *mntrflags |= (1<<flag);
2506
2507 return 0;
2508}
2509
Johannes Berg9bc383d2009-11-19 11:55:19 +01002510static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002511 struct net_device *netdev, u8 use_4addr,
2512 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002513{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002514 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002515 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002516 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002517 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002518 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002519
2520 switch (iftype) {
2521 case NL80211_IFTYPE_AP_VLAN:
2522 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2523 return 0;
2524 break;
2525 case NL80211_IFTYPE_STATION:
2526 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2527 return 0;
2528 break;
2529 default:
2530 break;
2531 }
2532
2533 return -EOPNOTSUPP;
2534}
2535
Johannes Berg55682962007-09-20 13:09:35 -04002536static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2537{
Johannes Berg4c476992010-10-04 21:36:35 +02002538 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002539 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002540 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002541 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002542 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002543 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002544 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002545
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002546 memset(&params, 0, sizeof(params));
2547
Johannes Berg04a773a2009-04-19 21:24:32 +02002548 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002549
Johannes Berg723b0382008-09-16 20:22:09 +02002550 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002551 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002552 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002553 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002554 if (ntype > NL80211_IFTYPE_MAX)
2555 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002556 }
2557
Johannes Berg92ffe052008-09-16 20:39:36 +02002558 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002559 struct wireless_dev *wdev = dev->ieee80211_ptr;
2560
Johannes Berg4c476992010-10-04 21:36:35 +02002561 if (ntype != NL80211_IFTYPE_MESH_POINT)
2562 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002563 if (netif_running(dev))
2564 return -EBUSY;
2565
2566 wdev_lock(wdev);
2567 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2568 IEEE80211_MAX_MESH_ID_LEN);
2569 wdev->mesh_id_up_len =
2570 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2571 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2572 wdev->mesh_id_up_len);
2573 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002574 }
2575
Felix Fietkau8b787642009-11-10 18:53:10 +01002576 if (info->attrs[NL80211_ATTR_4ADDR]) {
2577 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2578 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002579 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002580 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002581 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002582 } else {
2583 params.use_4addr = -1;
2584 }
2585
Johannes Berg92ffe052008-09-16 20:39:36 +02002586 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002587 if (ntype != NL80211_IFTYPE_MONITOR)
2588 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002589 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2590 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002591 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002592 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002593
2594 flags = &_flags;
2595 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002596 }
Johannes Berg3b858752009-03-12 09:55:09 +01002597
Luciano Coelho18003292013-08-29 13:26:57 +03002598 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002599 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2600 return -EOPNOTSUPP;
2601
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002602 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002603 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002604 else
2605 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002606
Johannes Berg9bc383d2009-11-19 11:55:19 +01002607 if (!err && params.use_4addr != -1)
2608 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2609
Johannes Berg55682962007-09-20 13:09:35 -04002610 return err;
2611}
2612
2613static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2614{
Johannes Berg4c476992010-10-04 21:36:35 +02002615 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002616 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002617 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002618 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002619 int err;
2620 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002621 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002622
Johannes Berg78f22b62014-03-24 17:57:27 +01002623 /* to avoid failing a new interface creation due to pending removal */
2624 cfg80211_destroy_ifaces(rdev);
2625
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002626 memset(&params, 0, sizeof(params));
2627
Johannes Berg55682962007-09-20 13:09:35 -04002628 if (!info->attrs[NL80211_ATTR_IFNAME])
2629 return -EINVAL;
2630
2631 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2632 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2633 if (type > NL80211_IFTYPE_MAX)
2634 return -EINVAL;
2635 }
2636
Johannes Berg79c97e92009-07-07 03:56:12 +02002637 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002638 !(rdev->wiphy.interface_modes & (1 << type)))
2639 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002640
Ben Greeare8f479b2014-10-22 12:23:05 -07002641 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2642 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2643 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002644 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2645 ETH_ALEN);
2646 if (!is_valid_ether_addr(params.macaddr))
2647 return -EADDRNOTAVAIL;
2648 }
2649
Johannes Berg9bc383d2009-11-19 11:55:19 +01002650 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002651 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002652 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002653 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002654 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002655 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002656
Michael Wu66f7ac52008-01-31 19:48:22 +01002657 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2658 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2659 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002660
Luciano Coelho18003292013-08-29 13:26:57 +03002661 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002662 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2663 return -EOPNOTSUPP;
2664
Johannes Berga18c7192015-02-24 10:56:42 +01002665 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2666 if (!msg)
2667 return -ENOMEM;
2668
Hila Gonene35e4d22012-06-27 17:19:42 +03002669 wdev = rdev_add_virtual_intf(rdev,
2670 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002671 NET_NAME_USER, type, err ? NULL : &flags,
2672 &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
Arik Nemtsov923b3522015-07-08 15:41:44 +03003407 if (!cfg80211_reg_can_beacon_relax(&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:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004065 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4066 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004067 return -EINVAL;
4068 break;
4069 }
4070
4071 return 0;
4072}
4073EXPORT_SYMBOL(cfg80211_check_station_change);
4074
Johannes Berg5727ef12007-12-19 02:03:34 +01004075/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004076 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004077 */
Johannes Berg80b99892011-11-18 16:23:01 +01004078static struct net_device *get_vlan(struct genl_info *info,
4079 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004080{
Johannes Berg463d0182009-07-14 00:33:35 +02004081 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004082 struct net_device *v;
4083 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004084
Johannes Berg80b99892011-11-18 16:23:01 +01004085 if (!vlanattr)
4086 return NULL;
4087
4088 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4089 if (!v)
4090 return ERR_PTR(-ENODEV);
4091
4092 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4093 ret = -EINVAL;
4094 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004095 }
Johannes Berg80b99892011-11-18 16:23:01 +01004096
Johannes Berg77ee7c82013-02-15 00:48:33 +01004097 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4098 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4099 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4100 ret = -EINVAL;
4101 goto error;
4102 }
4103
Johannes Berg80b99892011-11-18 16:23:01 +01004104 if (!netif_running(v)) {
4105 ret = -ENETDOWN;
4106 goto error;
4107 }
4108
4109 return v;
4110 error:
4111 dev_put(v);
4112 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004113}
4114
Johannes Berg94e860f2014-01-20 23:58:15 +01004115static const struct nla_policy
4116nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004117 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4118 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4119};
4120
Johannes Bergff276692013-02-15 00:09:01 +01004121static int nl80211_parse_sta_wme(struct genl_info *info,
4122 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004123{
Jouni Malinendf881292013-02-14 21:10:54 +02004124 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4125 struct nlattr *nla;
4126 int err;
4127
Jouni Malinendf881292013-02-14 21:10:54 +02004128 /* parse WME attributes if present */
4129 if (!info->attrs[NL80211_ATTR_STA_WME])
4130 return 0;
4131
4132 nla = info->attrs[NL80211_ATTR_STA_WME];
4133 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4134 nl80211_sta_wme_policy);
4135 if (err)
4136 return err;
4137
4138 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4139 params->uapsd_queues = nla_get_u8(
4140 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4141 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4142 return -EINVAL;
4143
4144 if (tb[NL80211_STA_WME_MAX_SP])
4145 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4146
4147 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4148 return -EINVAL;
4149
4150 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4151
4152 return 0;
4153}
4154
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304155static int nl80211_parse_sta_channel_info(struct genl_info *info,
4156 struct station_parameters *params)
4157{
4158 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4159 params->supported_channels =
4160 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4161 params->supported_channels_len =
4162 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4163 /*
4164 * Need to include at least one (first channel, number of
4165 * channels) tuple for each subband, and must have proper
4166 * tuples for the rest of the data as well.
4167 */
4168 if (params->supported_channels_len < 2)
4169 return -EINVAL;
4170 if (params->supported_channels_len % 2)
4171 return -EINVAL;
4172 }
4173
4174 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4175 params->supported_oper_classes =
4176 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4177 params->supported_oper_classes_len =
4178 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4179 /*
4180 * The value of the Length field of the Supported Operating
4181 * Classes element is between 2 and 253.
4182 */
4183 if (params->supported_oper_classes_len < 2 ||
4184 params->supported_oper_classes_len > 253)
4185 return -EINVAL;
4186 }
4187 return 0;
4188}
4189
Johannes Bergff276692013-02-15 00:09:01 +01004190static int nl80211_set_station_tdls(struct genl_info *info,
4191 struct station_parameters *params)
4192{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304193 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004194 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004195 if (info->attrs[NL80211_ATTR_PEER_AID])
4196 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004197 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4198 params->ht_capa =
4199 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4200 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4201 params->vht_capa =
4202 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4203
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304204 err = nl80211_parse_sta_channel_info(info, params);
4205 if (err)
4206 return err;
4207
Johannes Bergff276692013-02-15 00:09:01 +01004208 return nl80211_parse_sta_wme(info, params);
4209}
4210
Johannes Berg5727ef12007-12-19 02:03:34 +01004211static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4212{
Johannes Berg4c476992010-10-04 21:36:35 +02004213 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004214 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004215 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004216 u8 *mac_addr;
4217 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004218
4219 memset(&params, 0, sizeof(params));
4220
4221 params.listen_interval = -1;
4222
Johannes Berg77ee7c82013-02-15 00:48:33 +01004223 if (!rdev->ops->change_station)
4224 return -EOPNOTSUPP;
4225
Johannes Berg5727ef12007-12-19 02:03:34 +01004226 if (info->attrs[NL80211_ATTR_STA_AID])
4227 return -EINVAL;
4228
4229 if (!info->attrs[NL80211_ATTR_MAC])
4230 return -EINVAL;
4231
4232 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4233
4234 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4235 params.supported_rates =
4236 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4237 params.supported_rates_len =
4238 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4239 }
4240
Jouni Malinen9d62a982013-02-14 21:10:13 +02004241 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4242 params.capability =
4243 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4244 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4245 }
4246
4247 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4248 params.ext_capab =
4249 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4250 params.ext_capab_len =
4251 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4252 }
4253
Jouni Malinendf881292013-02-14 21:10:54 +02004254 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004255 return -EINVAL;
Jouni Malinen36aedc902008-08-25 11:58:58 +03004256
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004257 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004258 return -EINVAL;
4259
Johannes Bergf8bacc22013-02-14 23:27:01 +01004260 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004261 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004262 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4263 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4264 return -EINVAL;
4265 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004266
Johannes Bergf8bacc22013-02-14 23:27:01 +01004267 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004268 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004269 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4270 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4271 return -EINVAL;
4272 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4273 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004274
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004275 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4276 enum nl80211_mesh_power_mode pm = nla_get_u32(
4277 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4278
4279 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4280 pm > NL80211_MESH_POWER_MAX)
4281 return -EINVAL;
4282
4283 params.local_pm = pm;
4284 }
4285
Johannes Berg77ee7c82013-02-15 00:48:33 +01004286 /* Include parameters for TDLS peer (will check later) */
4287 err = nl80211_set_station_tdls(info, &params);
4288 if (err)
4289 return err;
4290
4291 params.vlan = get_vlan(info, rdev);
4292 if (IS_ERR(params.vlan))
4293 return PTR_ERR(params.vlan);
4294
Johannes Berga97f4422009-06-18 17:23:43 +02004295 switch (dev->ieee80211_ptr->iftype) {
4296 case NL80211_IFTYPE_AP:
4297 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004298 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004299 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004300 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004301 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004302 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004303 break;
4304 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004305 err = -EOPNOTSUPP;
4306 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004307 }
4308
Johannes Berg77ee7c82013-02-15 00:48:33 +01004309 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004310 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004311
Johannes Berg77ee7c82013-02-15 00:48:33 +01004312 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004313 if (params.vlan)
4314 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004315
Johannes Berg5727ef12007-12-19 02:03:34 +01004316 return err;
4317}
4318
4319static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4320{
Johannes Berg4c476992010-10-04 21:36:35 +02004321 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004322 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004323 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004324 struct station_parameters params;
4325 u8 *mac_addr = NULL;
4326
4327 memset(&params, 0, sizeof(params));
4328
Johannes Berg984c3112013-02-14 23:43:25 +01004329 if (!rdev->ops->add_station)
4330 return -EOPNOTSUPP;
4331
Johannes Berg5727ef12007-12-19 02:03:34 +01004332 if (!info->attrs[NL80211_ATTR_MAC])
4333 return -EINVAL;
4334
Johannes Berg5727ef12007-12-19 02:03:34 +01004335 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4336 return -EINVAL;
4337
4338 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4339 return -EINVAL;
4340
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004341 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4342 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004343 return -EINVAL;
4344
Johannes Berg5727ef12007-12-19 02:03:34 +01004345 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4346 params.supported_rates =
4347 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4348 params.supported_rates_len =
4349 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4350 params.listen_interval =
4351 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004352
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004353 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004354 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004355 else
4356 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004357 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4358 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004359
Jouni Malinen9d62a982013-02-14 21:10:13 +02004360 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4361 params.capability =
4362 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4363 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4364 }
4365
4366 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4367 params.ext_capab =
4368 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4369 params.ext_capab_len =
4370 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4371 }
4372
Jouni Malinen36aedc902008-08-25 11:58:58 +03004373 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4374 params.ht_capa =
4375 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004376
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004377 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4378 params.vht_capa =
4379 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4380
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004381 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4382 params.opmode_notif_used = true;
4383 params.opmode_notif =
4384 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4385 }
4386
Johannes Bergf8bacc22013-02-14 23:27:01 +01004387 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004388 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004389 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4390 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4391 return -EINVAL;
4392 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004393
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304394 err = nl80211_parse_sta_channel_info(info, &params);
4395 if (err)
4396 return err;
4397
Johannes Bergff276692013-02-15 00:09:01 +01004398 err = nl80211_parse_sta_wme(info, &params);
4399 if (err)
4400 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004401
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004402 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004403 return -EINVAL;
4404
Johannes Berg496fcc22015-03-12 08:53:27 +02004405 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4406 * as userspace might just pass through the capabilities from the IEs
4407 * directly, rather than enforcing this restriction and returning an
4408 * error in this case.
4409 */
4410 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4411 params.ht_capa = NULL;
4412 params.vht_capa = NULL;
4413 }
4414
Johannes Berg77ee7c82013-02-15 00:48:33 +01004415 /* When you run into this, adjust the code below for the new flag */
4416 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4417
Johannes Bergbdd90d52011-12-14 12:20:27 +01004418 switch (dev->ieee80211_ptr->iftype) {
4419 case NL80211_IFTYPE_AP:
4420 case NL80211_IFTYPE_AP_VLAN:
4421 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004422 /* ignore WME attributes if iface/sta is not capable */
4423 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4424 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4425 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004426
Johannes Bergbdd90d52011-12-14 12:20:27 +01004427 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004428 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4429 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004430 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004431 /* but don't bother the driver with it */
4432 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004433
Johannes Bergd582cff2012-10-26 17:53:44 +02004434 /* allow authenticated/associated only if driver handles it */
4435 if (!(rdev->wiphy.features &
4436 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4437 params.sta_flags_mask &
4438 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4439 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4440 return -EINVAL;
4441
Johannes Bergbdd90d52011-12-14 12:20:27 +01004442 /* must be last in here for error handling */
4443 params.vlan = get_vlan(info, rdev);
4444 if (IS_ERR(params.vlan))
4445 return PTR_ERR(params.vlan);
4446 break;
4447 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004448 /* ignore uAPSD data */
4449 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4450
Johannes Bergd582cff2012-10-26 17:53:44 +02004451 /* associated is disallowed */
4452 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4453 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004454 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004455 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4456 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004457 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004458 break;
4459 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004460 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004461 /* ignore uAPSD data */
4462 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4463
Johannes Berg77ee7c82013-02-15 00:48:33 +01004464 /* these are disallowed */
4465 if (params.sta_flags_mask &
4466 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4467 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004468 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004469 /* Only TDLS peers can be added */
4470 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4471 return -EINVAL;
4472 /* Can only add if TDLS ... */
4473 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4474 return -EOPNOTSUPP;
4475 /* ... with external setup is supported */
4476 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4477 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004478 /*
4479 * Older wpa_supplicant versions always mark the TDLS peer
4480 * as authorized, but it shouldn't yet be.
4481 */
4482 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004483 break;
4484 default:
4485 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004486 }
4487
Johannes Bergbdd90d52011-12-14 12:20:27 +01004488 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004489
Hila Gonene35e4d22012-06-27 17:19:42 +03004490 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004491
Johannes Berg5727ef12007-12-19 02:03:34 +01004492 if (params.vlan)
4493 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004494 return err;
4495}
4496
4497static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4498{
Johannes Berg4c476992010-10-04 21:36:35 +02004499 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4500 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004501 struct station_del_parameters params;
4502
4503 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004504
4505 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004506 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004507
Johannes Berge80cf852009-05-11 14:43:13 +02004508 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004509 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004510 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004511 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4512 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004513
Johannes Berg4c476992010-10-04 21:36:35 +02004514 if (!rdev->ops->del_station)
4515 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004516
Jouni Malinen98856862014-10-20 13:20:45 +03004517 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4518 params.subtype =
4519 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4520 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4521 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4522 return -EINVAL;
4523 } else {
4524 /* Default to Deauthentication frame */
4525 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4526 }
4527
4528 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4529 params.reason_code =
4530 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4531 if (params.reason_code == 0)
4532 return -EINVAL; /* 0 is reserved */
4533 } else {
4534 /* Default to reason code 2 */
4535 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4536 }
4537
Jouni Malinen89c771e2014-10-10 20:52:40 +03004538 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004539}
4540
Eric W. Biederman15e47302012-09-07 20:12:54 +00004541static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004542 int flags, struct net_device *dev,
4543 u8 *dst, u8 *next_hop,
4544 struct mpath_info *pinfo)
4545{
4546 void *hdr;
4547 struct nlattr *pinfoattr;
4548
Henning Rogge1ef4c852014-11-04 16:14:58 +01004549 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004550 if (!hdr)
4551 return -1;
4552
David S. Miller9360ffd2012-03-29 04:41:26 -04004553 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4554 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4555 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4556 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4557 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004558
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004559 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4560 if (!pinfoattr)
4561 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004562 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4563 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4564 pinfo->frame_qlen))
4565 goto nla_put_failure;
4566 if (((pinfo->filled & MPATH_INFO_SN) &&
4567 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4568 ((pinfo->filled & MPATH_INFO_METRIC) &&
4569 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4570 pinfo->metric)) ||
4571 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4572 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4573 pinfo->exptime)) ||
4574 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4575 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4576 pinfo->flags)) ||
4577 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4578 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4579 pinfo->discovery_timeout)) ||
4580 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4581 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4582 pinfo->discovery_retries)))
4583 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004584
4585 nla_nest_end(msg, pinfoattr);
4586
Johannes Berg053c0952015-01-16 22:09:00 +01004587 genlmsg_end(msg, hdr);
4588 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004589
4590 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004591 genlmsg_cancel(msg, hdr);
4592 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004593}
4594
4595static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004596 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004597{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004598 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004599 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004600 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004601 u8 dst[ETH_ALEN];
4602 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004603 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004604 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004605
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004606 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004607 if (err)
4608 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004609
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004610 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004611 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004612 goto out_err;
4613 }
4614
Johannes Berg97990a02013-04-19 01:02:55 +02004615 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004616 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004617 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004618 }
4619
Johannes Bergbba95fe2008-07-29 13:22:51 +02004620 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004621 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004622 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004623 if (err == -ENOENT)
4624 break;
4625 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004626 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004627
Eric W. Biederman15e47302012-09-07 20:12:54 +00004628 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004629 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004630 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004631 &pinfo) < 0)
4632 goto out;
4633
4634 path_idx++;
4635 }
4636
4637
4638 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004639 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004640 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004641 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004642 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004643 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004644}
4645
4646static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4647{
Johannes Berg4c476992010-10-04 21:36:35 +02004648 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004649 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004650 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004651 struct mpath_info pinfo;
4652 struct sk_buff *msg;
4653 u8 *dst = NULL;
4654 u8 next_hop[ETH_ALEN];
4655
4656 memset(&pinfo, 0, sizeof(pinfo));
4657
4658 if (!info->attrs[NL80211_ATTR_MAC])
4659 return -EINVAL;
4660
4661 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4662
Johannes Berg4c476992010-10-04 21:36:35 +02004663 if (!rdev->ops->get_mpath)
4664 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004665
Johannes Berg4c476992010-10-04 21:36:35 +02004666 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4667 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004668
Hila Gonene35e4d22012-06-27 17:19:42 +03004669 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004670 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004671 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004672
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004673 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004674 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004675 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004676
Eric W. Biederman15e47302012-09-07 20:12:54 +00004677 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004678 dev, dst, next_hop, &pinfo) < 0) {
4679 nlmsg_free(msg);
4680 return -ENOBUFS;
4681 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004682
Johannes Berg4c476992010-10-04 21:36:35 +02004683 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004684}
4685
4686static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4687{
Johannes Berg4c476992010-10-04 21:36:35 +02004688 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4689 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004690 u8 *dst = NULL;
4691 u8 *next_hop = NULL;
4692
4693 if (!info->attrs[NL80211_ATTR_MAC])
4694 return -EINVAL;
4695
4696 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4697 return -EINVAL;
4698
4699 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4700 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4701
Johannes Berg4c476992010-10-04 21:36:35 +02004702 if (!rdev->ops->change_mpath)
4703 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004704
Johannes Berg4c476992010-10-04 21:36:35 +02004705 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4706 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004707
Hila Gonene35e4d22012-06-27 17:19:42 +03004708 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004709}
Johannes Berg4c476992010-10-04 21:36:35 +02004710
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004711static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4712{
Johannes Berg4c476992010-10-04 21:36:35 +02004713 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4714 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004715 u8 *dst = NULL;
4716 u8 *next_hop = NULL;
4717
4718 if (!info->attrs[NL80211_ATTR_MAC])
4719 return -EINVAL;
4720
4721 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4722 return -EINVAL;
4723
4724 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4725 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4726
Johannes Berg4c476992010-10-04 21:36:35 +02004727 if (!rdev->ops->add_mpath)
4728 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004729
Johannes Berg4c476992010-10-04 21:36:35 +02004730 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4731 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004732
Hila Gonene35e4d22012-06-27 17:19:42 +03004733 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004734}
4735
4736static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4737{
Johannes Berg4c476992010-10-04 21:36:35 +02004738 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4739 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004740 u8 *dst = NULL;
4741
4742 if (info->attrs[NL80211_ATTR_MAC])
4743 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4744
Johannes Berg4c476992010-10-04 21:36:35 +02004745 if (!rdev->ops->del_mpath)
4746 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004747
Hila Gonene35e4d22012-06-27 17:19:42 +03004748 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004749}
4750
Henning Rogge66be7d22014-09-12 08:58:49 +02004751static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4752{
4753 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4754 int err;
4755 struct net_device *dev = info->user_ptr[1];
4756 struct mpath_info pinfo;
4757 struct sk_buff *msg;
4758 u8 *dst = NULL;
4759 u8 mpp[ETH_ALEN];
4760
4761 memset(&pinfo, 0, sizeof(pinfo));
4762
4763 if (!info->attrs[NL80211_ATTR_MAC])
4764 return -EINVAL;
4765
4766 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4767
4768 if (!rdev->ops->get_mpp)
4769 return -EOPNOTSUPP;
4770
4771 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4772 return -EOPNOTSUPP;
4773
4774 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4775 if (err)
4776 return err;
4777
4778 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4779 if (!msg)
4780 return -ENOMEM;
4781
4782 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4783 dev, dst, mpp, &pinfo) < 0) {
4784 nlmsg_free(msg);
4785 return -ENOBUFS;
4786 }
4787
4788 return genlmsg_reply(msg, info);
4789}
4790
4791static int nl80211_dump_mpp(struct sk_buff *skb,
4792 struct netlink_callback *cb)
4793{
4794 struct mpath_info pinfo;
4795 struct cfg80211_registered_device *rdev;
4796 struct wireless_dev *wdev;
4797 u8 dst[ETH_ALEN];
4798 u8 mpp[ETH_ALEN];
4799 int path_idx = cb->args[2];
4800 int err;
4801
4802 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4803 if (err)
4804 return err;
4805
4806 if (!rdev->ops->dump_mpp) {
4807 err = -EOPNOTSUPP;
4808 goto out_err;
4809 }
4810
4811 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4812 err = -EOPNOTSUPP;
4813 goto out_err;
4814 }
4815
4816 while (1) {
4817 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4818 mpp, &pinfo);
4819 if (err == -ENOENT)
4820 break;
4821 if (err)
4822 goto out_err;
4823
4824 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4825 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4826 wdev->netdev, dst, mpp,
4827 &pinfo) < 0)
4828 goto out;
4829
4830 path_idx++;
4831 }
4832
4833 out:
4834 cb->args[2] = path_idx;
4835 err = skb->len;
4836 out_err:
4837 nl80211_finish_wdev_dump(rdev);
4838 return err;
4839}
4840
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004841static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4842{
Johannes Berg4c476992010-10-04 21:36:35 +02004843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4844 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004845 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004846 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004847 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004848
4849 memset(&params, 0, sizeof(params));
4850 /* default to not changing parameters */
4851 params.use_cts_prot = -1;
4852 params.use_short_preamble = -1;
4853 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004854 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004855 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004856 params.p2p_ctwindow = -1;
4857 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004858
4859 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4860 params.use_cts_prot =
4861 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4862 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4863 params.use_short_preamble =
4864 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4865 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4866 params.use_short_slot_time =
4867 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004868 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4869 params.basic_rates =
4870 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4871 params.basic_rates_len =
4872 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4873 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004874 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4875 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004876 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4877 params.ht_opmode =
4878 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004879
Johannes Berg53cabad2012-11-14 15:17:28 +01004880 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4881 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4882 return -EINVAL;
4883 params.p2p_ctwindow =
4884 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4885 if (params.p2p_ctwindow < 0)
4886 return -EINVAL;
4887 if (params.p2p_ctwindow != 0 &&
4888 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4889 return -EINVAL;
4890 }
4891
4892 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4893 u8 tmp;
4894
4895 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4896 return -EINVAL;
4897 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4898 if (tmp > 1)
4899 return -EINVAL;
4900 params.p2p_opp_ps = tmp;
4901 if (params.p2p_opp_ps &&
4902 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4903 return -EINVAL;
4904 }
4905
Johannes Berg4c476992010-10-04 21:36:35 +02004906 if (!rdev->ops->change_bss)
4907 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004908
Johannes Berg074ac8d2010-09-16 14:58:22 +02004909 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004910 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4911 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004912
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004913 wdev_lock(wdev);
4914 err = rdev_change_bss(rdev, dev, &params);
4915 wdev_unlock(wdev);
4916
4917 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004918}
4919
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004920static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004921 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4922 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4923 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4924 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4925 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4926 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004927 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004928};
4929
4930static int parse_reg_rule(struct nlattr *tb[],
4931 struct ieee80211_reg_rule *reg_rule)
4932{
4933 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4934 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4935
4936 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4937 return -EINVAL;
4938 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4939 return -EINVAL;
4940 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4941 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004942 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4943 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004944 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4945 return -EINVAL;
4946
4947 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4948
4949 freq_range->start_freq_khz =
4950 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4951 freq_range->end_freq_khz =
4952 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004953 freq_range->max_bandwidth_khz =
4954 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004955
4956 power_rule->max_eirp =
4957 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4958
4959 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4960 power_rule->max_antenna_gain =
4961 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4962
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004963 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4964 reg_rule->dfs_cac_ms =
4965 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4966
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004967 return 0;
4968}
4969
4970static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4971{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004972 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05004973 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004974 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05004975 u32 owner_nlportid;
4976
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004977
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004978 /*
4979 * You should only get this when cfg80211 hasn't yet initialized
4980 * completely when built-in to the kernel right between the time
4981 * window between nl80211_init() and regulatory_init(), if that is
4982 * even possible.
4983 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004984 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004985 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004986
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004987 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4988 user_reg_hint_type =
4989 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4990 else
4991 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4992
4993 switch (user_reg_hint_type) {
4994 case NL80211_USER_REG_HINT_USER:
4995 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004996 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4997 return -EINVAL;
4998
4999 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5000 return regulatory_hint_user(data, user_reg_hint_type);
5001 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005002 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5003 owner_nlportid = info->snd_portid;
5004 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5005 } else {
5006 owner_nlportid = 0;
5007 is_indoor = true;
5008 }
5009
5010 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005011 default:
5012 return -EINVAL;
5013 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005014}
5015
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005016static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005017 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005018{
Johannes Berg4c476992010-10-04 21:36:35 +02005019 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005020 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005021 struct wireless_dev *wdev = dev->ieee80211_ptr;
5022 struct mesh_config cur_params;
5023 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005024 void *hdr;
5025 struct nlattr *pinfoattr;
5026 struct sk_buff *msg;
5027
Johannes Berg29cbe682010-12-03 09:20:44 +01005028 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5029 return -EOPNOTSUPP;
5030
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005031 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005032 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005033
Johannes Berg29cbe682010-12-03 09:20:44 +01005034 wdev_lock(wdev);
5035 /* If not connected, get default parameters */
5036 if (!wdev->mesh_id_len)
5037 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5038 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005039 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005040 wdev_unlock(wdev);
5041
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005042 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005043 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005044
5045 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005046 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005047 if (!msg)
5048 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005049 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005050 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005051 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005052 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005053 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005054 if (!pinfoattr)
5055 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005056 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5057 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5058 cur_params.dot11MeshRetryTimeout) ||
5059 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5060 cur_params.dot11MeshConfirmTimeout) ||
5061 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5062 cur_params.dot11MeshHoldingTimeout) ||
5063 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5064 cur_params.dot11MeshMaxPeerLinks) ||
5065 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5066 cur_params.dot11MeshMaxRetries) ||
5067 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5068 cur_params.dot11MeshTTL) ||
5069 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5070 cur_params.element_ttl) ||
5071 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5072 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005073 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5074 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005075 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5076 cur_params.dot11MeshHWMPmaxPREQretries) ||
5077 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5078 cur_params.path_refresh_time) ||
5079 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5080 cur_params.min_discovery_timeout) ||
5081 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5082 cur_params.dot11MeshHWMPactivePathTimeout) ||
5083 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5084 cur_params.dot11MeshHWMPpreqMinInterval) ||
5085 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5086 cur_params.dot11MeshHWMPperrMinInterval) ||
5087 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5088 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5089 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5090 cur_params.dot11MeshHWMPRootMode) ||
5091 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5092 cur_params.dot11MeshHWMPRannInterval) ||
5093 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5094 cur_params.dot11MeshGateAnnouncementProtocol) ||
5095 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5096 cur_params.dot11MeshForwarding) ||
5097 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005098 cur_params.rssi_threshold) ||
5099 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005100 cur_params.ht_opmode) ||
5101 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5102 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5103 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005104 cur_params.dot11MeshHWMProotInterval) ||
5105 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005106 cur_params.dot11MeshHWMPconfirmationInterval) ||
5107 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5108 cur_params.power_mode) ||
5109 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005110 cur_params.dot11MeshAwakeWindowDuration) ||
5111 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5112 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005113 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005114 nla_nest_end(msg, pinfoattr);
5115 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005116 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005117
Johannes Berg3b858752009-03-12 09:55:09 +01005118 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005119 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005120 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005121 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005122 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005123}
5124
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005125static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005126 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5127 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5128 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5129 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5130 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5131 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005132 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005133 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005134 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005135 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5136 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5137 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5138 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5139 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005140 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005141 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005142 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005143 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005144 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005145 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005146 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5147 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005148 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5149 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005150 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005151 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5152 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005153 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005154};
5155
Javier Cardonac80d5452010-12-16 17:37:49 -08005156static const struct nla_policy
5157 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005158 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005159 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5160 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005161 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005162 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005163 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005164 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005165 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005166 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005167};
5168
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005169static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005170 struct mesh_config *cfg,
5171 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005172{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005173 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005174 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005175
Marco Porschea54fba2013-01-07 16:04:48 +01005176#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5177do { \
5178 if (tb[attr]) { \
5179 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5180 return -EINVAL; \
5181 cfg->param = fn(tb[attr]); \
5182 mask |= (1 << (attr - 1)); \
5183 } \
5184} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005185
5186
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005187 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005188 return -EINVAL;
5189 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005190 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005191 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005192 return -EINVAL;
5193
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005194 /* This makes sure that there aren't more than 32 mesh config
5195 * parameters (otherwise our bitfield scheme would not work.) */
5196 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5197
5198 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005199 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005200 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5201 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005202 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005203 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5204 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005205 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005206 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5207 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005208 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005209 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5210 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005211 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005212 mask, NL80211_MESHCONF_MAX_RETRIES,
5213 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005214 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005215 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005216 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005217 mask, NL80211_MESHCONF_ELEMENT_TTL,
5218 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005219 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005220 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5221 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005222 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5223 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005224 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5225 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005226 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005227 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5228 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005229 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005230 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5231 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005232 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005233 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5234 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005235 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5236 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005237 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5238 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005239 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005240 1, 65535, mask,
5241 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005242 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005243 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005244 1, 65535, mask,
5245 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005246 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005247 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005248 dot11MeshHWMPnetDiameterTraversalTime,
5249 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005250 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5251 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005252 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5253 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5254 nla_get_u8);
5255 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5256 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005257 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005258 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005259 dot11MeshGateAnnouncementProtocol, 0, 1,
5260 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005261 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005262 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005263 mask, NL80211_MESHCONF_FORWARDING,
5264 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005265 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005266 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005267 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005268 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005269 mask, NL80211_MESHCONF_HT_OPMODE,
5270 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005271 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005272 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005273 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5274 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005275 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005276 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5277 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005278 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005279 dot11MeshHWMPconfirmationInterval,
5280 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005281 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5282 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005283 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5284 NL80211_MESH_POWER_ACTIVE,
5285 NL80211_MESH_POWER_MAX,
5286 mask, NL80211_MESHCONF_POWER_MODE,
5287 nla_get_u32);
5288 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5289 0, 65535, mask,
5290 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005291 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005292 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5293 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005294 if (mask_out)
5295 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005296
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005297 return 0;
5298
5299#undef FILL_IN_MESH_PARAM_IF_SET
5300}
5301
Javier Cardonac80d5452010-12-16 17:37:49 -08005302static int nl80211_parse_mesh_setup(struct genl_info *info,
5303 struct mesh_setup *setup)
5304{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005305 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005306 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5307
5308 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5309 return -EINVAL;
5310 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5311 info->attrs[NL80211_ATTR_MESH_SETUP],
5312 nl80211_mesh_setup_params_policy))
5313 return -EINVAL;
5314
Javier Cardonad299a1f2012-03-31 11:31:33 -07005315 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5316 setup->sync_method =
5317 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5318 IEEE80211_SYNC_METHOD_VENDOR :
5319 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5320
Javier Cardonac80d5452010-12-16 17:37:49 -08005321 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5322 setup->path_sel_proto =
5323 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5324 IEEE80211_PATH_PROTOCOL_VENDOR :
5325 IEEE80211_PATH_PROTOCOL_HWMP;
5326
5327 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5328 setup->path_metric =
5329 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5330 IEEE80211_PATH_METRIC_VENDOR :
5331 IEEE80211_PATH_METRIC_AIRTIME;
5332
Javier Cardona581a8b02011-04-07 15:08:27 -07005333
5334 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005335 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005336 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005337 if (!is_valid_ie_attr(ieattr))
5338 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005339 setup->ie = nla_data(ieattr);
5340 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005341 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005342 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5343 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5344 return -EINVAL;
5345 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005346 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5347 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005348 if (setup->is_secure)
5349 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005350
Colleen Twitty6e16d902013-05-08 11:45:59 -07005351 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5352 if (!setup->user_mpm)
5353 return -EINVAL;
5354 setup->auth_id =
5355 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5356 }
5357
Javier Cardonac80d5452010-12-16 17:37:49 -08005358 return 0;
5359}
5360
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005361static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005362 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005363{
5364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5365 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005366 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005367 struct mesh_config cfg;
5368 u32 mask;
5369 int err;
5370
Johannes Berg29cbe682010-12-03 09:20:44 +01005371 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5372 return -EOPNOTSUPP;
5373
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005374 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005375 return -EOPNOTSUPP;
5376
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005377 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005378 if (err)
5379 return err;
5380
Johannes Berg29cbe682010-12-03 09:20:44 +01005381 wdev_lock(wdev);
5382 if (!wdev->mesh_id_len)
5383 err = -ENOLINK;
5384
5385 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005386 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005387
5388 wdev_unlock(wdev);
5389
5390 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005391}
5392
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005393static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5394 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005395{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005396 struct nlattr *nl_reg_rules;
5397 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005398
Johannes Berg458f4f92012-12-06 15:47:38 +01005399 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5400 (regdom->dfs_region &&
5401 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005402 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005403
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005404 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5405 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005406 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005407
Johannes Berg458f4f92012-12-06 15:47:38 +01005408 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005409 struct nlattr *nl_reg_rule;
5410 const struct ieee80211_reg_rule *reg_rule;
5411 const struct ieee80211_freq_range *freq_range;
5412 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005413 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005414
Johannes Berg458f4f92012-12-06 15:47:38 +01005415 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005416 freq_range = &reg_rule->freq_range;
5417 power_rule = &reg_rule->power_rule;
5418
5419 nl_reg_rule = nla_nest_start(msg, i);
5420 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005421 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005422
Janusz Dziedzic97524822014-01-30 09:52:20 +01005423 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5424 if (!max_bandwidth_khz)
5425 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5426 reg_rule);
5427
David S. Miller9360ffd2012-03-29 04:41:26 -04005428 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5429 reg_rule->flags) ||
5430 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5431 freq_range->start_freq_khz) ||
5432 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5433 freq_range->end_freq_khz) ||
5434 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005435 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005436 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5437 power_rule->max_antenna_gain) ||
5438 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005439 power_rule->max_eirp) ||
5440 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5441 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005442 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005443
5444 nla_nest_end(msg, nl_reg_rule);
5445 }
5446
5447 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005448 return 0;
5449
5450nla_put_failure:
5451 return -EMSGSIZE;
5452}
5453
5454static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5455{
5456 const struct ieee80211_regdomain *regdom = NULL;
5457 struct cfg80211_registered_device *rdev;
5458 struct wiphy *wiphy = NULL;
5459 struct sk_buff *msg;
5460 void *hdr;
5461
5462 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5463 if (!msg)
5464 return -ENOBUFS;
5465
5466 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5467 NL80211_CMD_GET_REG);
5468 if (!hdr)
5469 goto put_failure;
5470
5471 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005472 bool self_managed;
5473
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005474 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5475 if (IS_ERR(rdev)) {
5476 nlmsg_free(msg);
5477 return PTR_ERR(rdev);
5478 }
5479
5480 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005481 self_managed = wiphy->regulatory_flags &
5482 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005483 regdom = get_wiphy_regdom(wiphy);
5484
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005485 /* a self-managed-reg device must have a private regdom */
5486 if (WARN_ON(!regdom && self_managed)) {
5487 nlmsg_free(msg);
5488 return -EINVAL;
5489 }
5490
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005491 if (regdom &&
5492 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5493 goto nla_put_failure;
5494 }
5495
5496 if (!wiphy && reg_last_request_cell_base() &&
5497 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5498 NL80211_USER_REG_HINT_CELL_BASE))
5499 goto nla_put_failure;
5500
5501 rcu_read_lock();
5502
5503 if (!regdom)
5504 regdom = rcu_dereference(cfg80211_regdomain);
5505
5506 if (nl80211_put_regdom(regdom, msg))
5507 goto nla_put_failure_rcu;
5508
5509 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005510
5511 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005512 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005513
Johannes Berg458f4f92012-12-06 15:47:38 +01005514nla_put_failure_rcu:
5515 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005516nla_put_failure:
5517 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005518put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005519 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005520 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005521}
5522
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005523static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5524 u32 seq, int flags, struct wiphy *wiphy,
5525 const struct ieee80211_regdomain *regdom)
5526{
5527 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5528 NL80211_CMD_GET_REG);
5529
5530 if (!hdr)
5531 return -1;
5532
5533 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5534
5535 if (nl80211_put_regdom(regdom, msg))
5536 goto nla_put_failure;
5537
5538 if (!wiphy && reg_last_request_cell_base() &&
5539 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5540 NL80211_USER_REG_HINT_CELL_BASE))
5541 goto nla_put_failure;
5542
5543 if (wiphy &&
5544 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5545 goto nla_put_failure;
5546
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005547 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5548 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5549 goto nla_put_failure;
5550
Johannes Berg053c0952015-01-16 22:09:00 +01005551 genlmsg_end(msg, hdr);
5552 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005553
5554nla_put_failure:
5555 genlmsg_cancel(msg, hdr);
5556 return -EMSGSIZE;
5557}
5558
5559static int nl80211_get_reg_dump(struct sk_buff *skb,
5560 struct netlink_callback *cb)
5561{
5562 const struct ieee80211_regdomain *regdom = NULL;
5563 struct cfg80211_registered_device *rdev;
5564 int err, reg_idx, start = cb->args[2];
5565
5566 rtnl_lock();
5567
5568 if (cfg80211_regdomain && start == 0) {
5569 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5570 NLM_F_MULTI, NULL,
5571 rtnl_dereference(cfg80211_regdomain));
5572 if (err < 0)
5573 goto out_err;
5574 }
5575
5576 /* the global regdom is idx 0 */
5577 reg_idx = 1;
5578 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5579 regdom = get_wiphy_regdom(&rdev->wiphy);
5580 if (!regdom)
5581 continue;
5582
5583 if (++reg_idx <= start)
5584 continue;
5585
5586 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5587 NLM_F_MULTI, &rdev->wiphy, regdom);
5588 if (err < 0) {
5589 reg_idx--;
5590 break;
5591 }
5592 }
5593
5594 cb->args[2] = reg_idx;
5595 err = skb->len;
5596out_err:
5597 rtnl_unlock();
5598 return err;
5599}
5600
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005601static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5602{
5603 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5604 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005605 char *alpha2;
5606 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005607 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005608 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005609 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005610
5611 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5612 return -EINVAL;
5613
5614 if (!info->attrs[NL80211_ATTR_REG_RULES])
5615 return -EINVAL;
5616
5617 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5618
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005619 if (info->attrs[NL80211_ATTR_DFS_REGION])
5620 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5621
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005622 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005623 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005624 num_rules++;
5625 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005626 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005627 }
5628
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005629 if (!reg_is_valid_request(alpha2))
5630 return -EINVAL;
5631
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005632 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005633 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005634
5635 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005636 if (!rd)
5637 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005638
5639 rd->n_reg_rules = num_rules;
5640 rd->alpha2[0] = alpha2[0];
5641 rd->alpha2[1] = alpha2[1];
5642
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005643 /*
5644 * Disable DFS master mode if the DFS region was
5645 * not supported or known on this kernel.
5646 */
5647 if (reg_supported_dfs_region(dfs_region))
5648 rd->dfs_region = dfs_region;
5649
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005650 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005651 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005652 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5653 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5654 reg_rule_policy);
5655 if (r)
5656 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005657 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5658 if (r)
5659 goto bad_reg;
5660
5661 rule_idx++;
5662
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005663 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5664 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005665 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005666 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005667 }
5668
Ilan peerc37722b2015-03-30 15:15:49 +03005669 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005670 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005671 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005672
Johannes Bergd2372b32008-10-24 20:32:20 +02005673 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005674 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005675 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005676}
5677
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005678static int validate_scan_freqs(struct nlattr *freqs)
5679{
5680 struct nlattr *attr1, *attr2;
5681 int n_channels = 0, tmp1, tmp2;
5682
5683 nla_for_each_nested(attr1, freqs, tmp1) {
5684 n_channels++;
5685 /*
5686 * Some hardware has a limited channel list for
5687 * scanning, and it is pretty much nonsensical
5688 * to scan for a channel twice, so disallow that
5689 * and don't require drivers to check that the
5690 * channel list they get isn't longer than what
5691 * they can scan, as long as they can scan all
5692 * the channels they registered at once.
5693 */
5694 nla_for_each_nested(attr2, freqs, tmp2)
5695 if (attr1 != attr2 &&
5696 nla_get_u32(attr1) == nla_get_u32(attr2))
5697 return 0;
5698 }
5699
5700 return n_channels;
5701}
5702
Johannes Bergad2b26a2014-06-12 21:39:05 +02005703static int nl80211_parse_random_mac(struct nlattr **attrs,
5704 u8 *mac_addr, u8 *mac_addr_mask)
5705{
5706 int i;
5707
5708 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005709 eth_zero_addr(mac_addr);
5710 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005711 mac_addr[0] = 0x2;
5712 mac_addr_mask[0] = 0x3;
5713
5714 return 0;
5715 }
5716
5717 /* need both or none */
5718 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5719 return -EINVAL;
5720
5721 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5722 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5723
5724 /* don't allow or configure an mcast address */
5725 if (!is_multicast_ether_addr(mac_addr_mask) ||
5726 is_multicast_ether_addr(mac_addr))
5727 return -EINVAL;
5728
5729 /*
5730 * allow users to pass a MAC address that has bits set outside
5731 * of the mask, but don't bother drivers with having to deal
5732 * with such bits
5733 */
5734 for (i = 0; i < ETH_ALEN; i++)
5735 mac_addr[i] &= mac_addr_mask[i];
5736
5737 return 0;
5738}
5739
Johannes Berg2a519312009-02-10 21:25:55 +01005740static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5741{
Johannes Berg4c476992010-10-04 21:36:35 +02005742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005743 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005744 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005745 struct nlattr *attr;
5746 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005747 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005748 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005749
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005750 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5751 return -EINVAL;
5752
Johannes Berg79c97e92009-07-07 03:56:12 +02005753 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005754
Johannes Berg4c476992010-10-04 21:36:35 +02005755 if (!rdev->ops->scan)
5756 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005757
Johannes Bergf9d15d12014-01-22 11:14:19 +02005758 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005759 err = -EBUSY;
5760 goto unlock;
5761 }
Johannes Berg2a519312009-02-10 21:25:55 +01005762
5763 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005764 n_channels = validate_scan_freqs(
5765 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005766 if (!n_channels) {
5767 err = -EINVAL;
5768 goto unlock;
5769 }
Johannes Berg2a519312009-02-10 21:25:55 +01005770 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005771 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005772 }
5773
5774 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5775 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5776 n_ssids++;
5777
Johannes Bergf9f47522013-03-19 15:04:07 +01005778 if (n_ssids > wiphy->max_scan_ssids) {
5779 err = -EINVAL;
5780 goto unlock;
5781 }
Johannes Berg2a519312009-02-10 21:25:55 +01005782
Jouni Malinen70692ad2009-02-16 19:39:13 +02005783 if (info->attrs[NL80211_ATTR_IE])
5784 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5785 else
5786 ie_len = 0;
5787
Johannes Bergf9f47522013-03-19 15:04:07 +01005788 if (ie_len > wiphy->max_scan_ie_len) {
5789 err = -EINVAL;
5790 goto unlock;
5791 }
Johannes Berg18a83652009-03-31 12:12:05 +02005792
Johannes Berg2a519312009-02-10 21:25:55 +01005793 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005794 + sizeof(*request->ssids) * n_ssids
5795 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005796 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005797 if (!request) {
5798 err = -ENOMEM;
5799 goto unlock;
5800 }
Johannes Berg2a519312009-02-10 21:25:55 +01005801
Johannes Berg2a519312009-02-10 21:25:55 +01005802 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005803 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005804 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005805 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005806 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005807 request->ie = (void *)(request->ssids + n_ssids);
5808 else
5809 request->ie = (void *)(request->channels + n_channels);
5810 }
Johannes Berg2a519312009-02-10 21:25:55 +01005811
Johannes Berg584991d2009-11-02 13:32:03 +01005812 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005813 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5814 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005815 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005816 struct ieee80211_channel *chan;
5817
5818 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5819
5820 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005821 err = -EINVAL;
5822 goto out_free;
5823 }
Johannes Berg584991d2009-11-02 13:32:03 +01005824
5825 /* ignore disabled channels */
5826 if (chan->flags & IEEE80211_CHAN_DISABLED)
5827 continue;
5828
5829 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005830 i++;
5831 }
5832 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005833 enum ieee80211_band band;
5834
Johannes Berg2a519312009-02-10 21:25:55 +01005835 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005836 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5837 int j;
5838 if (!wiphy->bands[band])
5839 continue;
5840 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005841 struct ieee80211_channel *chan;
5842
5843 chan = &wiphy->bands[band]->channels[j];
5844
5845 if (chan->flags & IEEE80211_CHAN_DISABLED)
5846 continue;
5847
5848 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005849 i++;
5850 }
5851 }
5852 }
5853
Johannes Berg584991d2009-11-02 13:32:03 +01005854 if (!i) {
5855 err = -EINVAL;
5856 goto out_free;
5857 }
5858
5859 request->n_channels = i;
5860
Johannes Berg2a519312009-02-10 21:25:55 +01005861 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005862 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005863 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005864 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005865 err = -EINVAL;
5866 goto out_free;
5867 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005868 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005869 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005870 i++;
5871 }
5872 }
5873
Jouni Malinen70692ad2009-02-16 19:39:13 +02005874 if (info->attrs[NL80211_ATTR_IE]) {
5875 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005876 memcpy((void *)request->ie,
5877 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005878 request->ie_len);
5879 }
5880
Johannes Berg34850ab2011-07-18 18:08:35 +02005881 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005882 if (wiphy->bands[i])
5883 request->rates[i] =
5884 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005885
5886 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5887 nla_for_each_nested(attr,
5888 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5889 tmp) {
5890 enum ieee80211_band band = nla_type(attr);
5891
Dan Carpenter84404622011-07-29 11:52:18 +03005892 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005893 err = -EINVAL;
5894 goto out_free;
5895 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005896
5897 if (!wiphy->bands[band])
5898 continue;
5899
Johannes Berg34850ab2011-07-18 18:08:35 +02005900 err = ieee80211_get_ratemask(wiphy->bands[band],
5901 nla_data(attr),
5902 nla_len(attr),
5903 &request->rates[band]);
5904 if (err)
5905 goto out_free;
5906 }
5907 }
5908
Sam Leffler46856bb2012-10-11 21:03:32 -07005909 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005910 request->flags = nla_get_u32(
5911 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005912 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5913 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005914 err = -EOPNOTSUPP;
5915 goto out_free;
5916 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005917
5918 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5919 if (!(wiphy->features &
5920 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5921 err = -EOPNOTSUPP;
5922 goto out_free;
5923 }
5924
5925 if (wdev->current_bss) {
5926 err = -EOPNOTSUPP;
5927 goto out_free;
5928 }
5929
5930 err = nl80211_parse_random_mac(info->attrs,
5931 request->mac_addr,
5932 request->mac_addr_mask);
5933 if (err)
5934 goto out_free;
5935 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005936 }
Sam Lefflered4737712012-10-11 21:03:31 -07005937
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305938 request->no_cck =
5939 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5940
Johannes Bergfd014282012-06-18 19:17:03 +02005941 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005942 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005943 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005944
Johannes Berg79c97e92009-07-07 03:56:12 +02005945 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005946 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005947
Johannes Berg463d0182009-07-14 00:33:35 +02005948 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005949 nl80211_send_scan_start(rdev, wdev);
5950 if (wdev->netdev)
5951 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005952 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005953 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005954 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005955 kfree(request);
5956 }
Johannes Berg3b858752009-03-12 09:55:09 +01005957
Johannes Bergf9f47522013-03-19 15:04:07 +01005958 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005959 return err;
5960}
5961
Luciano Coelho256da022014-11-10 16:13:46 +02005962static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005963nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005964 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005965{
5966 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005967 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005968 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005969 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005970 enum ieee80211_band band;
5971 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005972 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005973 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005974
Luciano Coelho256da022014-11-10 16:13:46 +02005975 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5976 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005977
Luciano Coelho256da022014-11-10 16:13:46 +02005978 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5979 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005980
Luciano Coelho256da022014-11-10 16:13:46 +02005981 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005982 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005983 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005984
Luciano Coelho256da022014-11-10 16:13:46 +02005985 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005986 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005987 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005988 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005989 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005990 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005991 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005992 }
5993
Luciano Coelho256da022014-11-10 16:13:46 +02005994 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5995 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005996 tmp)
5997 n_ssids++;
5998
Luciano Coelho93b6aa62011-07-13 14:57:28 +03005999 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006000 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006001
Johannes Bergea73cbc2014-01-24 10:53:53 +01006002 /*
6003 * First, count the number of 'real' matchsets. Due to an issue with
6004 * the old implementation, matchsets containing only the RSSI attribute
6005 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6006 * RSSI for all matchsets, rather than their own matchset for reporting
6007 * all APs with a strong RSSI. This is needed to be compatible with
6008 * older userspace that treated a matchset with only the RSSI as the
6009 * global RSSI for all other matchsets - if there are other matchsets.
6010 */
Luciano Coelho256da022014-11-10 16:13:46 +02006011 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006012 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006013 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006014 tmp) {
6015 struct nlattr *rssi;
6016
6017 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6018 nla_data(attr), nla_len(attr),
6019 nl80211_match_policy);
6020 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006021 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006022 /* add other standalone attributes here */
6023 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6024 n_match_sets++;
6025 continue;
6026 }
6027 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6028 if (rssi)
6029 default_match_rssi = nla_get_s32(rssi);
6030 }
6031 }
6032
6033 /* However, if there's no other matchset, add the RSSI one */
6034 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6035 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006036
6037 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006038 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006039
Luciano Coelho256da022014-11-10 16:13:46 +02006040 if (attrs[NL80211_ATTR_IE])
6041 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006042 else
6043 ie_len = 0;
6044
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006045 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006046 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006047
Luciano Coelho807f8a82011-05-11 17:09:35 +03006048 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006049 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006050 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006051 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006052 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006053 if (!request)
6054 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006055
6056 if (n_ssids)
6057 request->ssids = (void *)&request->channels[n_channels];
6058 request->n_ssids = n_ssids;
6059 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006060 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006061 request->ie = (void *)(request->ssids + n_ssids);
6062 else
6063 request->ie = (void *)(request->channels + n_channels);
6064 }
6065
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006066 if (n_match_sets) {
6067 if (request->ie)
6068 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006069 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006070 request->match_sets =
6071 (void *)(request->ssids + n_ssids);
6072 else
6073 request->match_sets =
6074 (void *)(request->channels + n_channels);
6075 }
6076 request->n_match_sets = n_match_sets;
6077
Luciano Coelho807f8a82011-05-11 17:09:35 +03006078 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006079 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006080 /* user specified, bail out if channel not found */
6081 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006082 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006083 tmp) {
6084 struct ieee80211_channel *chan;
6085
6086 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6087
6088 if (!chan) {
6089 err = -EINVAL;
6090 goto out_free;
6091 }
6092
6093 /* ignore disabled channels */
6094 if (chan->flags & IEEE80211_CHAN_DISABLED)
6095 continue;
6096
6097 request->channels[i] = chan;
6098 i++;
6099 }
6100 } else {
6101 /* all channels */
6102 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6103 int j;
6104 if (!wiphy->bands[band])
6105 continue;
6106 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6107 struct ieee80211_channel *chan;
6108
6109 chan = &wiphy->bands[band]->channels[j];
6110
6111 if (chan->flags & IEEE80211_CHAN_DISABLED)
6112 continue;
6113
6114 request->channels[i] = chan;
6115 i++;
6116 }
6117 }
6118 }
6119
6120 if (!i) {
6121 err = -EINVAL;
6122 goto out_free;
6123 }
6124
6125 request->n_channels = i;
6126
6127 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006128 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006129 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006130 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006131 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006132 err = -EINVAL;
6133 goto out_free;
6134 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006135 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006136 memcpy(request->ssids[i].ssid, nla_data(attr),
6137 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006138 i++;
6139 }
6140 }
6141
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006142 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006143 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006144 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006145 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006146 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006147 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006148
Johannes Bergae811e22014-01-24 10:17:47 +01006149 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6150 nla_data(attr), nla_len(attr),
6151 nl80211_match_policy);
6152 if (err)
6153 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006154 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006155 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006156 if (WARN_ON(i >= n_match_sets)) {
6157 /* this indicates a programming error,
6158 * the loop above should have verified
6159 * things properly
6160 */
6161 err = -EINVAL;
6162 goto out_free;
6163 }
6164
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006165 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6166 err = -EINVAL;
6167 goto out_free;
6168 }
6169 memcpy(request->match_sets[i].ssid.ssid,
6170 nla_data(ssid), nla_len(ssid));
6171 request->match_sets[i].ssid.ssid_len =
6172 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006173 /* special attribute - old implemenation w/a */
6174 request->match_sets[i].rssi_thold =
6175 default_match_rssi;
6176 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6177 if (rssi)
6178 request->match_sets[i].rssi_thold =
6179 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006180 }
6181 i++;
6182 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006183
6184 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006185 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006186 request->match_sets[0].rssi_thold = default_match_rssi;
6187
6188 request->min_rssi_thold = INT_MAX;
6189 for (i = 0; i < n_match_sets; i++)
6190 request->min_rssi_thold =
6191 min(request->match_sets[i].rssi_thold,
6192 request->min_rssi_thold);
6193 } else {
6194 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006195 }
6196
Johannes Berg9900e482014-02-04 21:01:25 +01006197 if (ie_len) {
6198 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006199 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006200 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006201 request->ie_len);
6202 }
6203
Luciano Coelho256da022014-11-10 16:13:46 +02006204 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006205 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006206 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006207 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6208 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006209 err = -EOPNOTSUPP;
6210 goto out_free;
6211 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006212
6213 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6214 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6215
6216 if (!wdev) /* must be net-detect */
6217 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6218
6219 if (!(wiphy->features & flg)) {
6220 err = -EOPNOTSUPP;
6221 goto out_free;
6222 }
6223
6224 if (wdev && wdev->current_bss) {
6225 err = -EOPNOTSUPP;
6226 goto out_free;
6227 }
6228
6229 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6230 request->mac_addr_mask);
6231 if (err)
6232 goto out_free;
6233 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006234 }
Sam Lefflered4737712012-10-11 21:03:31 -07006235
Luciano Coelho9c748932015-01-16 16:04:09 +02006236 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6237 request->delay =
6238 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6239
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006240 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006241 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006242
Luciano Coelho256da022014-11-10 16:13:46 +02006243 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006244
6245out_free:
6246 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006247 return ERR_PTR(err);
6248}
6249
6250static int nl80211_start_sched_scan(struct sk_buff *skb,
6251 struct genl_info *info)
6252{
6253 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6254 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006255 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006256 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006257 int err;
6258
6259 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6260 !rdev->ops->sched_scan_start)
6261 return -EOPNOTSUPP;
6262
6263 if (rdev->sched_scan_req)
6264 return -EINPROGRESS;
6265
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006266 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6267 info->attrs);
6268
6269 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006270 if (err)
6271 goto out_err;
6272
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006273 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006274 if (err)
6275 goto out_free;
6276
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006277 sched_scan_req->dev = dev;
6278 sched_scan_req->wiphy = &rdev->wiphy;
6279
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006280 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6281 sched_scan_req->owner_nlportid = info->snd_portid;
6282
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006283 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006284
6285 nl80211_send_sched_scan(rdev, dev,
6286 NL80211_CMD_START_SCHED_SCAN);
6287 return 0;
6288
6289out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006290 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006291out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006292 return err;
6293}
6294
6295static int nl80211_stop_sched_scan(struct sk_buff *skb,
6296 struct genl_info *info)
6297{
6298 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6299
6300 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6301 !rdev->ops->sched_scan_stop)
6302 return -EOPNOTSUPP;
6303
Johannes Berg5fe231e2013-05-08 21:45:15 +02006304 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006305}
6306
Simon Wunderlich04f39042013-02-08 18:16:19 +01006307static int nl80211_start_radar_detection(struct sk_buff *skb,
6308 struct genl_info *info)
6309{
6310 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6311 struct net_device *dev = info->user_ptr[1];
6312 struct wireless_dev *wdev = dev->ieee80211_ptr;
6313 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006314 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006315 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006316 int err;
6317
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006318 dfs_region = reg_get_dfs_region(wdev->wiphy);
6319 if (dfs_region == NL80211_DFS_UNSET)
6320 return -EINVAL;
6321
Simon Wunderlich04f39042013-02-08 18:16:19 +01006322 err = nl80211_parse_chandef(rdev, info, &chandef);
6323 if (err)
6324 return err;
6325
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006326 if (netif_carrier_ok(dev))
6327 return -EBUSY;
6328
Simon Wunderlich04f39042013-02-08 18:16:19 +01006329 if (wdev->cac_started)
6330 return -EBUSY;
6331
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006332 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006333 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006334 if (err < 0)
6335 return err;
6336
6337 if (err == 0)
6338 return -EINVAL;
6339
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006340 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006341 return -EINVAL;
6342
6343 if (!rdev->ops->start_radar_detection)
6344 return -EOPNOTSUPP;
6345
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006346 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6347 if (WARN_ON(!cac_time_ms))
6348 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6349
6350 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6351 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006352 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006353 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006354 wdev->cac_started = true;
6355 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006356 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006357 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006358 return err;
6359}
6360
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006361static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6362{
6363 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6364 struct net_device *dev = info->user_ptr[1];
6365 struct wireless_dev *wdev = dev->ieee80211_ptr;
6366 struct cfg80211_csa_settings params;
6367 /* csa_attrs is defined static to avoid waste of stack size - this
6368 * function is called under RTNL lock, so this should not be a problem.
6369 */
6370 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006371 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006372 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006373 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006374 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006375
6376 if (!rdev->ops->channel_switch ||
6377 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6378 return -EOPNOTSUPP;
6379
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006380 switch (dev->ieee80211_ptr->iftype) {
6381 case NL80211_IFTYPE_AP:
6382 case NL80211_IFTYPE_P2P_GO:
6383 need_new_beacon = true;
6384
6385 /* useless if AP is not running */
6386 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006387 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006388 break;
6389 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006390 if (!wdev->ssid_len)
6391 return -ENOTCONN;
6392 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006393 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006394 if (!wdev->mesh_id_len)
6395 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006396 break;
6397 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006398 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006399 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006400
6401 memset(&params, 0, sizeof(params));
6402
6403 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6404 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6405 return -EINVAL;
6406
6407 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006408 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006409 return -EINVAL;
6410
Luciano Coelho252e07c2014-10-08 09:48:34 +03006411 /* Even though the attribute is u32, the specification says
6412 * u8, so let's make sure we don't overflow.
6413 */
6414 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6415 if (cs_count > 255)
6416 return -EINVAL;
6417
6418 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006419
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006420 if (!need_new_beacon)
6421 goto skip_beacons;
6422
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006423 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6424 if (err)
6425 return err;
6426
6427 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6428 info->attrs[NL80211_ATTR_CSA_IES],
6429 nl80211_policy);
6430 if (err)
6431 return err;
6432
6433 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6434 if (err)
6435 return err;
6436
6437 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6438 return -EINVAL;
6439
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006440 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6441 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006442 return -EINVAL;
6443
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006444 params.n_counter_offsets_beacon = len / sizeof(u16);
6445 if (rdev->wiphy.max_num_csa_counters &&
6446 (params.n_counter_offsets_beacon >
6447 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006448 return -EINVAL;
6449
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006450 params.counter_offsets_beacon =
6451 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6452
6453 /* sanity checks - counters should fit and be the same */
6454 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6455 u16 offset = params.counter_offsets_beacon[i];
6456
6457 if (offset >= params.beacon_csa.tail_len)
6458 return -EINVAL;
6459
6460 if (params.beacon_csa.tail[offset] != params.count)
6461 return -EINVAL;
6462 }
6463
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006464 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006465 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6466 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006467 return -EINVAL;
6468
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006469 params.n_counter_offsets_presp = len / sizeof(u16);
6470 if (rdev->wiphy.max_num_csa_counters &&
6471 (params.n_counter_offsets_beacon >
6472 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006473 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006474
6475 params.counter_offsets_presp =
6476 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6477
6478 /* sanity checks - counters should fit and be the same */
6479 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6480 u16 offset = params.counter_offsets_presp[i];
6481
6482 if (offset >= params.beacon_csa.probe_resp_len)
6483 return -EINVAL;
6484
6485 if (params.beacon_csa.probe_resp[offset] !=
6486 params.count)
6487 return -EINVAL;
6488 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006489 }
6490
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006491skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006492 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6493 if (err)
6494 return err;
6495
Arik Nemtsov923b3522015-07-08 15:41:44 +03006496 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6497 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006498 return -EINVAL;
6499
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006500 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6501 &params.chandef,
6502 wdev->iftype);
6503 if (err < 0)
6504 return err;
6505
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006506 if (err > 0)
Luciano Coelho2beb6dab2014-02-18 11:40:36 +02006507 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006508
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006509 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6510 params.block_tx = true;
6511
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006512 wdev_lock(wdev);
6513 err = rdev_channel_switch(rdev, dev, &params);
6514 wdev_unlock(wdev);
6515
6516 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006517}
6518
Johannes Berg9720bb32011-06-21 09:45:33 +02006519static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6520 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006521 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006522 struct wireless_dev *wdev,
6523 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006524{
Johannes Berg48ab9052009-07-10 18:42:31 +02006525 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006526 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006527 void *hdr;
6528 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006529
6530 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006531
Eric W. Biederman15e47302012-09-07 20:12:54 +00006532 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006533 NL80211_CMD_NEW_SCAN_RESULTS);
6534 if (!hdr)
6535 return -1;
6536
Johannes Berg9720bb32011-06-21 09:45:33 +02006537 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6538
Johannes Berg97990a02013-04-19 01:02:55 +02006539 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6540 goto nla_put_failure;
6541 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006542 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6543 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006544 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6545 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006546
6547 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6548 if (!bss)
6549 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006550 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006551 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006552 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006553
6554 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006555 /* indicate whether we have probe response data or not */
6556 if (rcu_access_pointer(res->proberesp_ies) &&
6557 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6558 goto fail_unlock_rcu;
6559
6560 /* this pointer prefers to be pointed to probe response data
6561 * but is always valid
6562 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006563 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006564 if (ies) {
6565 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6566 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006567 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6568 ies->len, ies->data))
6569 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006570 }
Johannes Berg0e227082014-08-12 20:34:30 +02006571
6572 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006573 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006574 if (ies && ies->from_beacon) {
6575 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006576 goto fail_unlock_rcu;
6577 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6578 ies->len, ies->data))
6579 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006580 }
6581 rcu_read_unlock();
6582
David S. Miller9360ffd2012-03-29 04:41:26 -04006583 if (res->beacon_interval &&
6584 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6585 goto nla_put_failure;
6586 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6587 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006588 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006589 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6590 jiffies_to_msecs(jiffies - intbss->ts)))
6591 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006592
Johannes Berg77965c92009-02-18 18:45:06 +01006593 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006594 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006595 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6596 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006597 break;
6598 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006599 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6600 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006601 break;
6602 default:
6603 break;
6604 }
6605
Johannes Berg48ab9052009-07-10 18:42:31 +02006606 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006607 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006608 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006609 if (intbss == wdev->current_bss &&
6610 nla_put_u32(msg, NL80211_BSS_STATUS,
6611 NL80211_BSS_STATUS_ASSOCIATED))
6612 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006613 break;
6614 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006615 if (intbss == wdev->current_bss &&
6616 nla_put_u32(msg, NL80211_BSS_STATUS,
6617 NL80211_BSS_STATUS_IBSS_JOINED))
6618 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006619 break;
6620 default:
6621 break;
6622 }
6623
Johannes Berg2a519312009-02-10 21:25:55 +01006624 nla_nest_end(msg, bss);
6625
Johannes Berg053c0952015-01-16 22:09:00 +01006626 genlmsg_end(msg, hdr);
6627 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006628
Johannes Berg8cef2c92013-02-05 16:54:31 +01006629 fail_unlock_rcu:
6630 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006631 nla_put_failure:
6632 genlmsg_cancel(msg, hdr);
6633 return -EMSGSIZE;
6634}
6635
Johannes Berg97990a02013-04-19 01:02:55 +02006636static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006637{
Johannes Berg48ab9052009-07-10 18:42:31 +02006638 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006639 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006640 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006641 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006642 int err;
6643
Johannes Berg97990a02013-04-19 01:02:55 +02006644 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006645 if (err)
6646 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006647
Johannes Berg48ab9052009-07-10 18:42:31 +02006648 wdev_lock(wdev);
6649 spin_lock_bh(&rdev->bss_lock);
6650 cfg80211_bss_expire(rdev);
6651
Johannes Berg9720bb32011-06-21 09:45:33 +02006652 cb->seq = rdev->bss_generation;
6653
Johannes Berg48ab9052009-07-10 18:42:31 +02006654 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006655 if (++idx <= start)
6656 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006657 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006658 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006659 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006660 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006661 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006662 }
6663 }
6664
Johannes Berg48ab9052009-07-10 18:42:31 +02006665 spin_unlock_bh(&rdev->bss_lock);
6666 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006667
Johannes Berg97990a02013-04-19 01:02:55 +02006668 cb->args[2] = idx;
6669 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006670
Johannes Berg67748892010-10-04 21:14:06 +02006671 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006672}
6673
Eric W. Biederman15e47302012-09-07 20:12:54 +00006674static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006675 int flags, struct net_device *dev,
6676 bool allow_radio_stats,
6677 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006678{
6679 void *hdr;
6680 struct nlattr *infoattr;
6681
Johannes Berg11f78ac2014-11-14 16:43:50 +01006682 /* skip radio stats if userspace didn't request them */
6683 if (!survey->channel && !allow_radio_stats)
6684 return 0;
6685
Eric W. Biederman15e47302012-09-07 20:12:54 +00006686 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006687 NL80211_CMD_NEW_SURVEY_RESULTS);
6688 if (!hdr)
6689 return -ENOMEM;
6690
David S. Miller9360ffd2012-03-29 04:41:26 -04006691 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6692 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006693
6694 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6695 if (!infoattr)
6696 goto nla_put_failure;
6697
Johannes Berg11f78ac2014-11-14 16:43:50 +01006698 if (survey->channel &&
6699 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006700 survey->channel->center_freq))
6701 goto nla_put_failure;
6702
6703 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6704 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6705 goto nla_put_failure;
6706 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6707 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6708 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006709 if ((survey->filled & SURVEY_INFO_TIME) &&
6710 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6711 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006712 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006713 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6714 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6715 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006716 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006717 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6718 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6719 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006720 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006721 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6722 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6723 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006724 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006725 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6726 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6727 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006728 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006729 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6730 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6731 survey->time_scan))
6732 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006733
6734 nla_nest_end(msg, infoattr);
6735
Johannes Berg053c0952015-01-16 22:09:00 +01006736 genlmsg_end(msg, hdr);
6737 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006738
6739 nla_put_failure:
6740 genlmsg_cancel(msg, hdr);
6741 return -EMSGSIZE;
6742}
6743
Johannes Berg11f78ac2014-11-14 16:43:50 +01006744static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006745{
6746 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006747 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006748 struct wireless_dev *wdev;
6749 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006750 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006751 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006752
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006753 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006754 if (res)
6755 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006756
Johannes Berg11f78ac2014-11-14 16:43:50 +01006757 /* prepare_wdev_dump parsed the attributes */
6758 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6759
Johannes Berg97990a02013-04-19 01:02:55 +02006760 if (!wdev->netdev) {
6761 res = -EINVAL;
6762 goto out_err;
6763 }
6764
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006765 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006766 res = -EOPNOTSUPP;
6767 goto out_err;
6768 }
6769
6770 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006771 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006772 if (res == -ENOENT)
6773 break;
6774 if (res)
6775 goto out_err;
6776
Johannes Berg11f78ac2014-11-14 16:43:50 +01006777 /* don't send disabled channels, but do send non-channel data */
6778 if (survey.channel &&
6779 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006780 survey_idx++;
6781 continue;
6782 }
6783
Holger Schurig61fa7132009-11-11 12:25:40 +01006784 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006785 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006786 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006787 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006788 goto out;
6789 survey_idx++;
6790 }
6791
6792 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006793 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006794 res = skb->len;
6795 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006796 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006797 return res;
6798}
6799
Samuel Ortizb23aa672009-07-01 21:26:54 +02006800static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6801{
6802 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6803 NL80211_WPA_VERSION_2));
6804}
6805
Jouni Malinen636a5d32009-03-19 13:39:22 +02006806static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6807{
Johannes Berg4c476992010-10-04 21:36:35 +02006808 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6809 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006810 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006811 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6812 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006813 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006814 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006815 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006816
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006817 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6818 return -EINVAL;
6819
6820 if (!info->attrs[NL80211_ATTR_MAC])
6821 return -EINVAL;
6822
Jouni Malinen17780922009-03-27 20:52:47 +02006823 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6824 return -EINVAL;
6825
Johannes Berg19957bb2009-07-02 17:20:43 +02006826 if (!info->attrs[NL80211_ATTR_SSID])
6827 return -EINVAL;
6828
6829 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6830 return -EINVAL;
6831
Johannes Bergfffd0932009-07-08 14:22:54 +02006832 err = nl80211_parse_key(info, &key);
6833 if (err)
6834 return err;
6835
6836 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006837 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6838 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006839 if (!key.p.key || !key.p.key_len)
6840 return -EINVAL;
6841 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6842 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6843 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6844 key.p.key_len != WLAN_KEY_LEN_WEP104))
6845 return -EINVAL;
6846 if (key.idx > 4)
6847 return -EINVAL;
6848 } else {
6849 key.p.key_len = 0;
6850 key.p.key = NULL;
6851 }
6852
Johannes Bergafea0b72010-08-10 09:46:42 +02006853 if (key.idx >= 0) {
6854 int i;
6855 bool ok = false;
6856 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6857 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6858 ok = true;
6859 break;
6860 }
6861 }
Johannes Berg4c476992010-10-04 21:36:35 +02006862 if (!ok)
6863 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006864 }
6865
Johannes Berg4c476992010-10-04 21:36:35 +02006866 if (!rdev->ops->auth)
6867 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006868
Johannes Berg074ac8d2010-09-16 14:58:22 +02006869 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006870 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6871 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006872
Johannes Berg19957bb2009-07-02 17:20:43 +02006873 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006874 chan = nl80211_get_valid_chan(&rdev->wiphy,
6875 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6876 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006877 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006878
Johannes Berg19957bb2009-07-02 17:20:43 +02006879 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6880 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6881
6882 if (info->attrs[NL80211_ATTR_IE]) {
6883 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6884 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6885 }
6886
6887 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006888 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006889 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006890
Jouni Malinene39e5b52012-09-30 19:29:39 +03006891 if (auth_type == NL80211_AUTHTYPE_SAE &&
6892 !info->attrs[NL80211_ATTR_SAE_DATA])
6893 return -EINVAL;
6894
6895 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6896 if (auth_type != NL80211_AUTHTYPE_SAE)
6897 return -EINVAL;
6898 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6899 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6900 /* need to include at least Auth Transaction and Status Code */
6901 if (sae_data_len < 4)
6902 return -EINVAL;
6903 }
6904
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006905 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6906
Johannes Berg95de8172012-01-20 13:55:25 +01006907 /*
6908 * Since we no longer track auth state, ignore
6909 * requests to only change local state.
6910 */
6911 if (local_state_change)
6912 return 0;
6913
Johannes Berg91bf9b22013-05-15 17:44:01 +02006914 wdev_lock(dev->ieee80211_ptr);
6915 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6916 ssid, ssid_len, ie, ie_len,
6917 key.p.key, key.p.key_len, key.idx,
6918 sae_data, sae_data_len);
6919 wdev_unlock(dev->ieee80211_ptr);
6920 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006921}
6922
Johannes Bergc0692b82010-08-27 14:26:53 +03006923static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6924 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006925 struct cfg80211_crypto_settings *settings,
6926 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006927{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006928 memset(settings, 0, sizeof(*settings));
6929
Samuel Ortizb23aa672009-07-01 21:26:54 +02006930 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6931
Johannes Bergc0692b82010-08-27 14:26:53 +03006932 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6933 u16 proto;
6934 proto = nla_get_u16(
6935 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6936 settings->control_port_ethertype = cpu_to_be16(proto);
6937 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6938 proto != ETH_P_PAE)
6939 return -EINVAL;
6940 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6941 settings->control_port_no_encrypt = true;
6942 } else
6943 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6944
Samuel Ortizb23aa672009-07-01 21:26:54 +02006945 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6946 void *data;
6947 int len, i;
6948
6949 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6950 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6951 settings->n_ciphers_pairwise = len / sizeof(u32);
6952
6953 if (len % sizeof(u32))
6954 return -EINVAL;
6955
Johannes Berg3dc27d22009-07-02 21:36:37 +02006956 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006957 return -EINVAL;
6958
6959 memcpy(settings->ciphers_pairwise, data, len);
6960
6961 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006962 if (!cfg80211_supported_cipher_suite(
6963 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006964 settings->ciphers_pairwise[i]))
6965 return -EINVAL;
6966 }
6967
6968 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6969 settings->cipher_group =
6970 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006971 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6972 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006973 return -EINVAL;
6974 }
6975
6976 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6977 settings->wpa_versions =
6978 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6979 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6980 return -EINVAL;
6981 }
6982
6983 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6984 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006985 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006986
6987 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6988 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6989 settings->n_akm_suites = len / sizeof(u32);
6990
6991 if (len % sizeof(u32))
6992 return -EINVAL;
6993
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006994 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6995 return -EINVAL;
6996
Samuel Ortizb23aa672009-07-01 21:26:54 +02006997 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006998 }
6999
7000 return 0;
7001}
7002
Jouni Malinen636a5d32009-03-19 13:39:22 +02007003static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7004{
Johannes Berg4c476992010-10-04 21:36:35 +02007005 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7006 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007007 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007008 struct cfg80211_assoc_request req = {};
7009 const u8 *bssid, *ssid;
7010 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007011
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007012 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7013 return -EINVAL;
7014
7015 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007016 !info->attrs[NL80211_ATTR_SSID] ||
7017 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007018 return -EINVAL;
7019
Johannes Berg4c476992010-10-04 21:36:35 +02007020 if (!rdev->ops->assoc)
7021 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007022
Johannes Berg074ac8d2010-09-16 14:58:22 +02007023 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007024 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7025 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007026
Johannes Berg19957bb2009-07-02 17:20:43 +02007027 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007028
Jouni Malinen664834d2014-01-15 00:01:44 +02007029 chan = nl80211_get_valid_chan(&rdev->wiphy,
7030 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7031 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007032 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007033
Johannes Berg19957bb2009-07-02 17:20:43 +02007034 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7035 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007036
7037 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007038 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7039 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007040 }
7041
Jouni Malinendc6382c2009-05-06 22:09:37 +03007042 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007043 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007044 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007045 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007046 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007047 else if (mfp != NL80211_MFP_NO)
7048 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007049 }
7050
Johannes Berg3e5d7642009-07-07 14:37:26 +02007051 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007052 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007053
Ben Greear7e7c8922011-11-18 11:31:59 -08007054 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007055 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007056
7057 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007058 memcpy(&req.ht_capa_mask,
7059 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7060 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007061
7062 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007063 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007064 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007065 memcpy(&req.ht_capa,
7066 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7067 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007068 }
7069
Johannes Bergee2aca32013-02-21 17:36:01 +01007070 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007071 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007072
7073 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007074 memcpy(&req.vht_capa_mask,
7075 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7076 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007077
7078 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007079 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007080 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007081 memcpy(&req.vht_capa,
7082 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7083 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007084 }
7085
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007086 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7087 if (!(rdev->wiphy.features &
7088 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7089 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7090 return -EINVAL;
7091 req.flags |= ASSOC_REQ_USE_RRM;
7092 }
7093
Johannes Bergf62fab72013-02-21 20:09:09 +01007094 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007095 if (!err) {
7096 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007097 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7098 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007099 wdev_unlock(dev->ieee80211_ptr);
7100 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007101
Jouni Malinen636a5d32009-03-19 13:39:22 +02007102 return err;
7103}
7104
7105static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7106{
Johannes Berg4c476992010-10-04 21:36:35 +02007107 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7108 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007109 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007110 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007111 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007112 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007113
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007114 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7115 return -EINVAL;
7116
7117 if (!info->attrs[NL80211_ATTR_MAC])
7118 return -EINVAL;
7119
7120 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7121 return -EINVAL;
7122
Johannes Berg4c476992010-10-04 21:36:35 +02007123 if (!rdev->ops->deauth)
7124 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007125
Johannes Berg074ac8d2010-09-16 14:58:22 +02007126 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007127 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7128 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007129
Johannes Berg19957bb2009-07-02 17:20:43 +02007130 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007131
Johannes Berg19957bb2009-07-02 17:20:43 +02007132 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7133 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007134 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007135 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007136 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007137
7138 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007139 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7140 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007141 }
7142
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007143 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7144
Johannes Berg91bf9b22013-05-15 17:44:01 +02007145 wdev_lock(dev->ieee80211_ptr);
7146 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7147 local_state_change);
7148 wdev_unlock(dev->ieee80211_ptr);
7149 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007150}
7151
7152static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7153{
Johannes Berg4c476992010-10-04 21:36:35 +02007154 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7155 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007156 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007157 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007158 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007159 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007160
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007161 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7162 return -EINVAL;
7163
7164 if (!info->attrs[NL80211_ATTR_MAC])
7165 return -EINVAL;
7166
7167 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7168 return -EINVAL;
7169
Johannes Berg4c476992010-10-04 21:36:35 +02007170 if (!rdev->ops->disassoc)
7171 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007172
Johannes Berg074ac8d2010-09-16 14:58:22 +02007173 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007174 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7175 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007176
Johannes Berg19957bb2009-07-02 17:20:43 +02007177 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007178
Johannes Berg19957bb2009-07-02 17:20:43 +02007179 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7180 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007181 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007182 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007183 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007184
7185 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007186 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7187 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007188 }
7189
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007190 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7191
Johannes Berg91bf9b22013-05-15 17:44:01 +02007192 wdev_lock(dev->ieee80211_ptr);
7193 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7194 local_state_change);
7195 wdev_unlock(dev->ieee80211_ptr);
7196 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007197}
7198
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007199static bool
7200nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7201 int mcast_rate[IEEE80211_NUM_BANDS],
7202 int rateval)
7203{
7204 struct wiphy *wiphy = &rdev->wiphy;
7205 bool found = false;
7206 int band, i;
7207
7208 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7209 struct ieee80211_supported_band *sband;
7210
7211 sband = wiphy->bands[band];
7212 if (!sband)
7213 continue;
7214
7215 for (i = 0; i < sband->n_bitrates; i++) {
7216 if (sband->bitrates[i].bitrate == rateval) {
7217 mcast_rate[band] = i + 1;
7218 found = true;
7219 break;
7220 }
7221 }
7222 }
7223
7224 return found;
7225}
7226
Johannes Berg04a773a2009-04-19 21:24:32 +02007227static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7228{
Johannes Berg4c476992010-10-04 21:36:35 +02007229 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7230 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007231 struct cfg80211_ibss_params ibss;
7232 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007233 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007234 int err;
7235
Johannes Berg8e30bc52009-04-22 17:45:38 +02007236 memset(&ibss, 0, sizeof(ibss));
7237
Johannes Berg04a773a2009-04-19 21:24:32 +02007238 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7239 return -EINVAL;
7240
Johannes Berg683b6d32012-11-08 21:25:48 +01007241 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007242 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7243 return -EINVAL;
7244
Johannes Berg8e30bc52009-04-22 17:45:38 +02007245 ibss.beacon_interval = 100;
7246
7247 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7248 ibss.beacon_interval =
7249 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7250 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7251 return -EINVAL;
7252 }
7253
Johannes Berg4c476992010-10-04 21:36:35 +02007254 if (!rdev->ops->join_ibss)
7255 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007256
Johannes Berg4c476992010-10-04 21:36:35 +02007257 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7258 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007259
Johannes Berg79c97e92009-07-07 03:56:12 +02007260 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007261
Johannes Berg39193492011-09-16 13:45:25 +02007262 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007263 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007264
7265 if (!is_valid_ether_addr(ibss.bssid))
7266 return -EINVAL;
7267 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007268 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7269 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7270
7271 if (info->attrs[NL80211_ATTR_IE]) {
7272 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7273 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7274 }
7275
Johannes Berg683b6d32012-11-08 21:25:48 +01007276 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7277 if (err)
7278 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007279
Ilan Peer174e0cd2014-02-23 09:13:01 +02007280 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7281 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007282 return -EINVAL;
7283
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007284 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007285 case NL80211_CHAN_WIDTH_5:
7286 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007287 case NL80211_CHAN_WIDTH_20_NOHT:
7288 break;
7289 case NL80211_CHAN_WIDTH_20:
7290 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007291 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7292 return -EINVAL;
7293 break;
7294 case NL80211_CHAN_WIDTH_80:
7295 case NL80211_CHAN_WIDTH_80P80:
7296 case NL80211_CHAN_WIDTH_160:
7297 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7298 return -EINVAL;
7299 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7300 NL80211_EXT_FEATURE_VHT_IBSS))
7301 return -EINVAL;
7302 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007303 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007304 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007305 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007306
Johannes Berg04a773a2009-04-19 21:24:32 +02007307 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007308 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007309
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007310 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7311 u8 *rates =
7312 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7313 int n_rates =
7314 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7315 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007316 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007317
Johannes Berg34850ab2011-07-18 18:08:35 +02007318 err = ieee80211_get_ratemask(sband, rates, n_rates,
7319 &ibss.basic_rates);
7320 if (err)
7321 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007322 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007323
Simon Wunderlich803768f2013-06-28 10:39:58 +02007324 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7325 memcpy(&ibss.ht_capa_mask,
7326 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7327 sizeof(ibss.ht_capa_mask));
7328
7329 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7330 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7331 return -EINVAL;
7332 memcpy(&ibss.ht_capa,
7333 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7334 sizeof(ibss.ht_capa));
7335 }
7336
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007337 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7338 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7339 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7340 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007341
Johannes Berg4c476992010-10-04 21:36:35 +02007342 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307343 bool no_ht = false;
7344
Johannes Berg4c476992010-10-04 21:36:35 +02007345 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307346 info->attrs[NL80211_ATTR_KEYS],
7347 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007348 if (IS_ERR(connkeys))
7349 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307350
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007351 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7352 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307353 kfree(connkeys);
7354 return -EINVAL;
7355 }
Johannes Berg4c476992010-10-04 21:36:35 +02007356 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007357
Antonio Quartulli267335d2012-01-31 20:25:47 +01007358 ibss.control_port =
7359 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7360
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007361 ibss.userspace_handles_dfs =
7362 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7363
Johannes Berg4c476992010-10-04 21:36:35 +02007364 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007365 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007366 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007367 return err;
7368}
7369
7370static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7371{
Johannes Berg4c476992010-10-04 21:36:35 +02007372 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7373 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007374
Johannes Berg4c476992010-10-04 21:36:35 +02007375 if (!rdev->ops->leave_ibss)
7376 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007377
Johannes Berg4c476992010-10-04 21:36:35 +02007378 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7379 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007380
Johannes Berg4c476992010-10-04 21:36:35 +02007381 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007382}
7383
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007384static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7385{
7386 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7387 struct net_device *dev = info->user_ptr[1];
7388 int mcast_rate[IEEE80211_NUM_BANDS];
7389 u32 nla_rate;
7390 int err;
7391
7392 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
7393 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
7394 return -EOPNOTSUPP;
7395
7396 if (!rdev->ops->set_mcast_rate)
7397 return -EOPNOTSUPP;
7398
7399 memset(mcast_rate, 0, sizeof(mcast_rate));
7400
7401 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7402 return -EINVAL;
7403
7404 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7405 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7406 return -EINVAL;
7407
7408 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7409
7410 return err;
7411}
7412
Johannes Bergad7e7182013-11-13 13:37:47 +01007413static struct sk_buff *
7414__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007415 struct wireless_dev *wdev, int approxlen,
7416 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007417 enum nl80211_attrs attr,
7418 const struct nl80211_vendor_cmd_info *info,
7419 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007420{
7421 struct sk_buff *skb;
7422 void *hdr;
7423 struct nlattr *data;
7424
7425 skb = nlmsg_new(approxlen + 100, gfp);
7426 if (!skb)
7427 return NULL;
7428
7429 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7430 if (!hdr) {
7431 kfree_skb(skb);
7432 return NULL;
7433 }
7434
7435 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7436 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007437
7438 if (info) {
7439 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7440 info->vendor_id))
7441 goto nla_put_failure;
7442 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7443 info->subcmd))
7444 goto nla_put_failure;
7445 }
7446
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007447 if (wdev) {
7448 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7449 wdev_id(wdev)))
7450 goto nla_put_failure;
7451 if (wdev->netdev &&
7452 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7453 wdev->netdev->ifindex))
7454 goto nla_put_failure;
7455 }
7456
Johannes Bergad7e7182013-11-13 13:37:47 +01007457 data = nla_nest_start(skb, attr);
7458
7459 ((void **)skb->cb)[0] = rdev;
7460 ((void **)skb->cb)[1] = hdr;
7461 ((void **)skb->cb)[2] = data;
7462
7463 return skb;
7464
7465 nla_put_failure:
7466 kfree_skb(skb);
7467 return NULL;
7468}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007469
Johannes Berge03ad6e2014-01-01 17:22:30 +01007470struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007471 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007472 enum nl80211_commands cmd,
7473 enum nl80211_attrs attr,
7474 int vendor_event_idx,
7475 int approxlen, gfp_t gfp)
7476{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007477 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007478 const struct nl80211_vendor_cmd_info *info;
7479
7480 switch (cmd) {
7481 case NL80211_CMD_TESTMODE:
7482 if (WARN_ON(vendor_event_idx != -1))
7483 return NULL;
7484 info = NULL;
7485 break;
7486 case NL80211_CMD_VENDOR:
7487 if (WARN_ON(vendor_event_idx < 0 ||
7488 vendor_event_idx >= wiphy->n_vendor_events))
7489 return NULL;
7490 info = &wiphy->vendor_events[vendor_event_idx];
7491 break;
7492 default:
7493 WARN_ON(1);
7494 return NULL;
7495 }
7496
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007497 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007498 cmd, attr, info, gfp);
7499}
7500EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7501
7502void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7503{
7504 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7505 void *hdr = ((void **)skb->cb)[1];
7506 struct nlattr *data = ((void **)skb->cb)[2];
7507 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7508
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007509 /* clear CB data for netlink core to own from now on */
7510 memset(skb->cb, 0, sizeof(skb->cb));
7511
Johannes Berge03ad6e2014-01-01 17:22:30 +01007512 nla_nest_end(skb, data);
7513 genlmsg_end(skb, hdr);
7514
7515 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7516 mcgrp = NL80211_MCGRP_VENDOR;
7517
7518 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7519 mcgrp, gfp);
7520}
7521EXPORT_SYMBOL(__cfg80211_send_event_skb);
7522
Johannes Bergaff89a92009-07-01 21:26:51 +02007523#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007524static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7525{
Johannes Berg4c476992010-10-04 21:36:35 +02007526 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007527 struct wireless_dev *wdev =
7528 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007529 int err;
7530
David Spinadelfc73f112013-07-31 18:04:15 +03007531 if (!rdev->ops->testmode_cmd)
7532 return -EOPNOTSUPP;
7533
7534 if (IS_ERR(wdev)) {
7535 err = PTR_ERR(wdev);
7536 if (err != -EINVAL)
7537 return err;
7538 wdev = NULL;
7539 } else if (wdev->wiphy != &rdev->wiphy) {
7540 return -EINVAL;
7541 }
7542
Johannes Bergaff89a92009-07-01 21:26:51 +02007543 if (!info->attrs[NL80211_ATTR_TESTDATA])
7544 return -EINVAL;
7545
Johannes Bergad7e7182013-11-13 13:37:47 +01007546 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007547 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007548 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7549 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007550 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007551
Johannes Bergaff89a92009-07-01 21:26:51 +02007552 return err;
7553}
7554
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007555static int nl80211_testmode_dump(struct sk_buff *skb,
7556 struct netlink_callback *cb)
7557{
Johannes Berg00918d32011-12-13 17:22:05 +01007558 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007559 int err;
7560 long phy_idx;
7561 void *data = NULL;
7562 int data_len = 0;
7563
Johannes Berg5fe231e2013-05-08 21:45:15 +02007564 rtnl_lock();
7565
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007566 if (cb->args[0]) {
7567 /*
7568 * 0 is a valid index, but not valid for args[0],
7569 * so we need to offset by 1.
7570 */
7571 phy_idx = cb->args[0] - 1;
7572 } else {
7573 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7574 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7575 nl80211_policy);
7576 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007577 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007578
Johannes Berg2bd7e352012-06-15 14:23:16 +02007579 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7580 nl80211_fam.attrbuf);
7581 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007582 err = PTR_ERR(rdev);
7583 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007584 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007585 phy_idx = rdev->wiphy_idx;
7586 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007587
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007588 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7589 cb->args[1] =
7590 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7591 }
7592
7593 if (cb->args[1]) {
7594 data = nla_data((void *)cb->args[1]);
7595 data_len = nla_len((void *)cb->args[1]);
7596 }
7597
Johannes Berg00918d32011-12-13 17:22:05 +01007598 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7599 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007600 err = -ENOENT;
7601 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007602 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007603
Johannes Berg00918d32011-12-13 17:22:05 +01007604 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007605 err = -EOPNOTSUPP;
7606 goto out_err;
7607 }
7608
7609 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007610 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007611 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7612 NL80211_CMD_TESTMODE);
7613 struct nlattr *tmdata;
7614
Dan Carpentercb35fba2013-08-14 14:50:01 +03007615 if (!hdr)
7616 break;
7617
David S. Miller9360ffd2012-03-29 04:41:26 -04007618 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007619 genlmsg_cancel(skb, hdr);
7620 break;
7621 }
7622
7623 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7624 if (!tmdata) {
7625 genlmsg_cancel(skb, hdr);
7626 break;
7627 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007628 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007629 nla_nest_end(skb, tmdata);
7630
7631 if (err == -ENOBUFS || err == -ENOENT) {
7632 genlmsg_cancel(skb, hdr);
7633 break;
7634 } else if (err) {
7635 genlmsg_cancel(skb, hdr);
7636 goto out_err;
7637 }
7638
7639 genlmsg_end(skb, hdr);
7640 }
7641
7642 err = skb->len;
7643 /* see above */
7644 cb->args[0] = phy_idx + 1;
7645 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007646 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007647 return err;
7648}
Johannes Bergaff89a92009-07-01 21:26:51 +02007649#endif
7650
Samuel Ortizb23aa672009-07-01 21:26:54 +02007651static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7652{
Johannes Berg4c476992010-10-04 21:36:35 +02007653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7654 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007655 struct cfg80211_connect_params connect;
7656 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007657 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007658 int err;
7659
7660 memset(&connect, 0, sizeof(connect));
7661
7662 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7663 return -EINVAL;
7664
7665 if (!info->attrs[NL80211_ATTR_SSID] ||
7666 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7667 return -EINVAL;
7668
7669 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7670 connect.auth_type =
7671 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007672 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7673 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007674 return -EINVAL;
7675 } else
7676 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7677
7678 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7679
Johannes Bergc0692b82010-08-27 14:26:53 +03007680 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007681 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007682 if (err)
7683 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007684
Johannes Berg074ac8d2010-09-16 14:58:22 +02007685 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007686 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7687 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007688
Johannes Berg79c97e92009-07-07 03:56:12 +02007689 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007690
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307691 connect.bg_scan_period = -1;
7692 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7693 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7694 connect.bg_scan_period =
7695 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7696 }
7697
Samuel Ortizb23aa672009-07-01 21:26:54 +02007698 if (info->attrs[NL80211_ATTR_MAC])
7699 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007700 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7701 connect.bssid_hint =
7702 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007703 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7704 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7705
7706 if (info->attrs[NL80211_ATTR_IE]) {
7707 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7708 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7709 }
7710
Jouni Malinencee00a92013-01-15 17:15:57 +02007711 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7712 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7713 if (connect.mfp != NL80211_MFP_REQUIRED &&
7714 connect.mfp != NL80211_MFP_NO)
7715 return -EINVAL;
7716 } else {
7717 connect.mfp = NL80211_MFP_NO;
7718 }
7719
Samuel Ortizb23aa672009-07-01 21:26:54 +02007720 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007721 connect.channel = nl80211_get_valid_chan(
7722 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7723 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007724 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007725 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007726 connect.channel_hint = nl80211_get_valid_chan(
7727 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7728 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007729 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007730 }
7731
Johannes Bergfffd0932009-07-08 14:22:54 +02007732 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7733 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307734 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007735 if (IS_ERR(connkeys))
7736 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007737 }
7738
Ben Greear7e7c8922011-11-18 11:31:59 -08007739 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7740 connect.flags |= ASSOC_REQ_DISABLE_HT;
7741
7742 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7743 memcpy(&connect.ht_capa_mask,
7744 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7745 sizeof(connect.ht_capa_mask));
7746
7747 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007748 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007749 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007750 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007751 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007752 memcpy(&connect.ht_capa,
7753 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7754 sizeof(connect.ht_capa));
7755 }
7756
Johannes Bergee2aca32013-02-21 17:36:01 +01007757 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7758 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7759
7760 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7761 memcpy(&connect.vht_capa_mask,
7762 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7763 sizeof(connect.vht_capa_mask));
7764
7765 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7766 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007767 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007768 return -EINVAL;
7769 }
7770 memcpy(&connect.vht_capa,
7771 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7772 sizeof(connect.vht_capa));
7773 }
7774
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007775 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7776 if (!(rdev->wiphy.features &
7777 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7778 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7779 return -EINVAL;
7780 connect.flags |= ASSOC_REQ_USE_RRM;
7781 }
7782
Johannes Berg83739b02013-05-15 17:44:01 +02007783 wdev_lock(dev->ieee80211_ptr);
7784 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7785 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007786 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007787 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007788 return err;
7789}
7790
7791static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7792{
Johannes Berg4c476992010-10-04 21:36:35 +02007793 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7794 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007795 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007796 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007797
7798 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7799 reason = WLAN_REASON_DEAUTH_LEAVING;
7800 else
7801 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7802
7803 if (reason == 0)
7804 return -EINVAL;
7805
Johannes Berg074ac8d2010-09-16 14:58:22 +02007806 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007807 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7808 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007809
Johannes Berg83739b02013-05-15 17:44:01 +02007810 wdev_lock(dev->ieee80211_ptr);
7811 ret = cfg80211_disconnect(rdev, dev, reason, true);
7812 wdev_unlock(dev->ieee80211_ptr);
7813 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007814}
7815
Johannes Berg463d0182009-07-14 00:33:35 +02007816static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7817{
Johannes Berg4c476992010-10-04 21:36:35 +02007818 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007819 struct net *net;
7820 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007821
Vadim Kochan4b681c82015-01-12 16:34:05 +02007822 if (info->attrs[NL80211_ATTR_PID]) {
7823 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7824
7825 net = get_net_ns_by_pid(pid);
7826 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7827 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7828
7829 net = get_net_ns_by_fd(fd);
7830 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007831 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007832 }
Johannes Berg463d0182009-07-14 00:33:35 +02007833
Johannes Berg4c476992010-10-04 21:36:35 +02007834 if (IS_ERR(net))
7835 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007836
7837 err = 0;
7838
7839 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007840 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7841 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007842
Johannes Berg463d0182009-07-14 00:33:35 +02007843 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007844 return err;
7845}
7846
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007847static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7848{
Johannes Berg4c476992010-10-04 21:36:35 +02007849 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007850 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7851 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007852 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007853 struct cfg80211_pmksa pmksa;
7854
7855 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7856
7857 if (!info->attrs[NL80211_ATTR_MAC])
7858 return -EINVAL;
7859
7860 if (!info->attrs[NL80211_ATTR_PMKID])
7861 return -EINVAL;
7862
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007863 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7864 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7865
Johannes Berg074ac8d2010-09-16 14:58:22 +02007866 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007867 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7868 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007869
7870 switch (info->genlhdr->cmd) {
7871 case NL80211_CMD_SET_PMKSA:
7872 rdev_ops = rdev->ops->set_pmksa;
7873 break;
7874 case NL80211_CMD_DEL_PMKSA:
7875 rdev_ops = rdev->ops->del_pmksa;
7876 break;
7877 default:
7878 WARN_ON(1);
7879 break;
7880 }
7881
Johannes Berg4c476992010-10-04 21:36:35 +02007882 if (!rdev_ops)
7883 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007884
Johannes Berg4c476992010-10-04 21:36:35 +02007885 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007886}
7887
7888static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7889{
Johannes Berg4c476992010-10-04 21:36:35 +02007890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7891 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007892
Johannes Berg074ac8d2010-09-16 14:58:22 +02007893 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007894 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7895 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007896
Johannes Berg4c476992010-10-04 21:36:35 +02007897 if (!rdev->ops->flush_pmksa)
7898 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007899
Hila Gonene35e4d22012-06-27 17:19:42 +03007900 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007901}
7902
Arik Nemtsov109086c2011-09-28 14:12:50 +03007903static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7904{
7905 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7906 struct net_device *dev = info->user_ptr[1];
7907 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307908 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007909 u16 status_code;
7910 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007911 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007912
7913 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7914 !rdev->ops->tdls_mgmt)
7915 return -EOPNOTSUPP;
7916
7917 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7918 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7919 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7920 !info->attrs[NL80211_ATTR_IE] ||
7921 !info->attrs[NL80211_ATTR_MAC])
7922 return -EINVAL;
7923
7924 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7925 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7926 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7927 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007928 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307929 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7930 peer_capability =
7931 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007932
Hila Gonene35e4d22012-06-27 17:19:42 +03007933 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307934 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007935 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007936 nla_data(info->attrs[NL80211_ATTR_IE]),
7937 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007938}
7939
7940static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7941{
7942 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7943 struct net_device *dev = info->user_ptr[1];
7944 enum nl80211_tdls_operation operation;
7945 u8 *peer;
7946
7947 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7948 !rdev->ops->tdls_oper)
7949 return -EOPNOTSUPP;
7950
7951 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7952 !info->attrs[NL80211_ATTR_MAC])
7953 return -EINVAL;
7954
7955 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7956 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7957
Hila Gonene35e4d22012-06-27 17:19:42 +03007958 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007959}
7960
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007961static int nl80211_remain_on_channel(struct sk_buff *skb,
7962 struct genl_info *info)
7963{
Johannes Berg4c476992010-10-04 21:36:35 +02007964 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007965 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007966 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007967 struct sk_buff *msg;
7968 void *hdr;
7969 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007970 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007971 int err;
7972
7973 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7974 !info->attrs[NL80211_ATTR_DURATION])
7975 return -EINVAL;
7976
7977 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7978
Johannes Berg7c4ef712011-11-18 15:33:48 +01007979 if (!rdev->ops->remain_on_channel ||
7980 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007981 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007982
Johannes Bergebf348f2012-06-01 12:50:54 +02007983 /*
7984 * We should be on that channel for at least a minimum amount of
7985 * time (10ms) but no longer than the driver supports.
7986 */
7987 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7988 duration > rdev->wiphy.max_remain_on_channel_duration)
7989 return -EINVAL;
7990
Johannes Berg683b6d32012-11-08 21:25:48 +01007991 err = nl80211_parse_chandef(rdev, info, &chandef);
7992 if (err)
7993 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007994
7995 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007996 if (!msg)
7997 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007998
Eric W. Biederman15e47302012-09-07 20:12:54 +00007999 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008000 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008001 if (!hdr) {
8002 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008003 goto free_msg;
8004 }
8005
Johannes Berg683b6d32012-11-08 21:25:48 +01008006 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8007 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008008
8009 if (err)
8010 goto free_msg;
8011
David S. Miller9360ffd2012-03-29 04:41:26 -04008012 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8013 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008014
8015 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008016
8017 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008018
8019 nla_put_failure:
8020 err = -ENOBUFS;
8021 free_msg:
8022 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008023 return err;
8024}
8025
8026static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8027 struct genl_info *info)
8028{
Johannes Berg4c476992010-10-04 21:36:35 +02008029 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008030 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008031 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008032
8033 if (!info->attrs[NL80211_ATTR_COOKIE])
8034 return -EINVAL;
8035
Johannes Berg4c476992010-10-04 21:36:35 +02008036 if (!rdev->ops->cancel_remain_on_channel)
8037 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008038
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008039 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8040
Hila Gonene35e4d22012-06-27 17:19:42 +03008041 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008042}
8043
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008044static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8045 u8 *rates, u8 rates_len)
8046{
8047 u8 i;
8048 u32 mask = 0;
8049
8050 for (i = 0; i < rates_len; i++) {
8051 int rate = (rates[i] & 0x7f) * 5;
8052 int ridx;
8053 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8054 struct ieee80211_rate *srate =
8055 &sband->bitrates[ridx];
8056 if (rate == srate->bitrate) {
8057 mask |= 1 << ridx;
8058 break;
8059 }
8060 }
8061 if (ridx == sband->n_bitrates)
8062 return 0; /* rate not found */
8063 }
8064
8065 return mask;
8066}
8067
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008068static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8069 u8 *rates, u8 rates_len,
8070 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8071{
8072 u8 i;
8073
8074 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8075
8076 for (i = 0; i < rates_len; i++) {
8077 int ridx, rbit;
8078
8079 ridx = rates[i] / 8;
8080 rbit = BIT(rates[i] % 8);
8081
8082 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008083 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008084 return false;
8085
8086 /* check availability */
8087 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8088 mcs[ridx] |= rbit;
8089 else
8090 return false;
8091 }
8092
8093 return true;
8094}
8095
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008096static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8097{
8098 u16 mcs_mask = 0;
8099
8100 switch (vht_mcs_map) {
8101 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8102 break;
8103 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8104 mcs_mask = 0x00FF;
8105 break;
8106 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8107 mcs_mask = 0x01FF;
8108 break;
8109 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8110 mcs_mask = 0x03FF;
8111 break;
8112 default:
8113 break;
8114 }
8115
8116 return mcs_mask;
8117}
8118
8119static void vht_build_mcs_mask(u16 vht_mcs_map,
8120 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8121{
8122 u8 nss;
8123
8124 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8125 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8126 vht_mcs_map >>= 2;
8127 }
8128}
8129
8130static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8131 struct nl80211_txrate_vht *txrate,
8132 u16 mcs[NL80211_VHT_NSS_MAX])
8133{
8134 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8135 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8136 u8 i;
8137
8138 if (!sband->vht_cap.vht_supported)
8139 return false;
8140
8141 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8142
8143 /* Build vht_mcs_mask from VHT capabilities */
8144 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8145
8146 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8147 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8148 mcs[i] = txrate->mcs[i];
8149 else
8150 return false;
8151 }
8152
8153 return true;
8154}
8155
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008156static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008157 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8158 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008159 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8160 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008161 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008162 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008163};
8164
8165static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8166 struct genl_info *info)
8167{
8168 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008169 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008170 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008171 int rem, i;
8172 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008173 struct nlattr *tx_rates;
8174 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008175 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008176
Johannes Berg4c476992010-10-04 21:36:35 +02008177 if (!rdev->ops->set_bitrate_mask)
8178 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008179
8180 memset(&mask, 0, sizeof(mask));
8181 /* Default to all rates enabled */
8182 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8183 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008184
8185 if (!sband)
8186 continue;
8187
8188 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008189 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008190 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008191 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008192
8193 if (!sband->vht_cap.vht_supported)
8194 continue;
8195
8196 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8197 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008198 }
8199
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008200 /* if no rates are given set it back to the defaults */
8201 if (!info->attrs[NL80211_ATTR_TX_RATES])
8202 goto out;
8203
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008204 /*
8205 * The nested attribute uses enum nl80211_band as the index. This maps
8206 * directly to the enum ieee80211_band values used in cfg80211.
8207 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008208 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008209 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008210 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008211 int err;
8212
Johannes Berg4c476992010-10-04 21:36:35 +02008213 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8214 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008215 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008216 if (sband == NULL)
8217 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008218 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8219 nla_len(tx_rates), nl80211_txattr_policy);
8220 if (err)
8221 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008222 if (tb[NL80211_TXRATE_LEGACY]) {
8223 mask.control[band].legacy = rateset_to_mask(
8224 sband,
8225 nla_data(tb[NL80211_TXRATE_LEGACY]),
8226 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308227 if ((mask.control[band].legacy == 0) &&
8228 nla_len(tb[NL80211_TXRATE_LEGACY]))
8229 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008230 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008231 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008232 if (!ht_rateset_to_mask(
8233 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008234 nla_data(tb[NL80211_TXRATE_HT]),
8235 nla_len(tb[NL80211_TXRATE_HT]),
8236 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008237 return -EINVAL;
8238 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008239 if (tb[NL80211_TXRATE_VHT]) {
8240 if (!vht_set_mcs_mask(
8241 sband,
8242 nla_data(tb[NL80211_TXRATE_VHT]),
8243 mask.control[band].vht_mcs))
8244 return -EINVAL;
8245 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008246 if (tb[NL80211_TXRATE_GI]) {
8247 mask.control[band].gi =
8248 nla_get_u8(tb[NL80211_TXRATE_GI]);
8249 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8250 return -EINVAL;
8251 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008252
8253 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008254 /* don't allow empty legacy rates if HT or VHT
8255 * are not even supported.
8256 */
8257 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8258 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008259 return -EINVAL;
8260
8261 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008262 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008263 goto out;
8264
8265 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8266 if (mask.control[band].vht_mcs[i])
8267 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008268
8269 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008270 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008271 }
8272 }
8273
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008274out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008275 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008276}
8277
Johannes Berg2e161f72010-08-12 15:38:38 +02008278static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008279{
Johannes Berg4c476992010-10-04 21:36:35 +02008280 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008281 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008282 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008283
8284 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8285 return -EINVAL;
8286
Johannes Berg2e161f72010-08-12 15:38:38 +02008287 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8288 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008289
Johannes Berg71bbc992012-06-15 15:30:18 +02008290 switch (wdev->iftype) {
8291 case NL80211_IFTYPE_STATION:
8292 case NL80211_IFTYPE_ADHOC:
8293 case NL80211_IFTYPE_P2P_CLIENT:
8294 case NL80211_IFTYPE_AP:
8295 case NL80211_IFTYPE_AP_VLAN:
8296 case NL80211_IFTYPE_MESH_POINT:
8297 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008298 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008299 break;
8300 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008301 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008302 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008303
8304 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008305 if (!rdev->ops->mgmt_tx)
8306 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008307
Eric W. Biederman15e47302012-09-07 20:12:54 +00008308 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008309 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8310 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008311}
8312
Johannes Berg2e161f72010-08-12 15:38:38 +02008313static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008314{
Johannes Berg4c476992010-10-04 21:36:35 +02008315 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008316 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008317 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008318 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008319 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008320 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008321 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008322 struct cfg80211_mgmt_tx_params params = {
8323 .dont_wait_for_ack =
8324 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8325 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008326
Johannes Berg683b6d32012-11-08 21:25:48 +01008327 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008328 return -EINVAL;
8329
Johannes Berg4c476992010-10-04 21:36:35 +02008330 if (!rdev->ops->mgmt_tx)
8331 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008332
Johannes Berg71bbc992012-06-15 15:30:18 +02008333 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008334 case NL80211_IFTYPE_P2P_DEVICE:
8335 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8336 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008337 case NL80211_IFTYPE_STATION:
8338 case NL80211_IFTYPE_ADHOC:
8339 case NL80211_IFTYPE_P2P_CLIENT:
8340 case NL80211_IFTYPE_AP:
8341 case NL80211_IFTYPE_AP_VLAN:
8342 case NL80211_IFTYPE_MESH_POINT:
8343 case NL80211_IFTYPE_P2P_GO:
8344 break;
8345 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008346 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008347 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008348
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008349 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008350 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008351 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008352 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008353
8354 /*
8355 * We should wait on the channel for at least a minimum amount
8356 * of time (10ms) but no longer than the driver supports.
8357 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008358 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8359 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008360 return -EINVAL;
8361
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008362 }
8363
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008364 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008365
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008366 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008367 return -EINVAL;
8368
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008369 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308370
Antonio Quartulliea141b752013-06-11 14:20:03 +02008371 /* get the channel if any has been specified, otherwise pass NULL to
8372 * the driver. The latter will use the current one
8373 */
8374 chandef.chan = NULL;
8375 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8376 err = nl80211_parse_chandef(rdev, info, &chandef);
8377 if (err)
8378 return err;
8379 }
8380
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008381 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008382 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008383
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008384 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8385 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8386
8387 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8388 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8389 int i;
8390
8391 if (len % sizeof(u16))
8392 return -EINVAL;
8393
8394 params.n_csa_offsets = len / sizeof(u16);
8395 params.csa_offsets =
8396 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8397
8398 /* check that all the offsets fit the frame */
8399 for (i = 0; i < params.n_csa_offsets; i++) {
8400 if (params.csa_offsets[i] >= params.len)
8401 return -EINVAL;
8402 }
8403 }
8404
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008405 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008406 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8407 if (!msg)
8408 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008409
Eric W. Biederman15e47302012-09-07 20:12:54 +00008410 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008411 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008412 if (!hdr) {
8413 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008414 goto free_msg;
8415 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008416 }
Johannes Berge247bd902011-11-04 11:18:21 +01008417
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008418 params.chan = chandef.chan;
8419 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008420 if (err)
8421 goto free_msg;
8422
Johannes Berge247bd902011-11-04 11:18:21 +01008423 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008424 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8425 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008426
Johannes Berge247bd902011-11-04 11:18:21 +01008427 genlmsg_end(msg, hdr);
8428 return genlmsg_reply(msg, info);
8429 }
8430
8431 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008432
8433 nla_put_failure:
8434 err = -ENOBUFS;
8435 free_msg:
8436 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008437 return err;
8438}
8439
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008440static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8441{
8442 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008443 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008444 u64 cookie;
8445
8446 if (!info->attrs[NL80211_ATTR_COOKIE])
8447 return -EINVAL;
8448
8449 if (!rdev->ops->mgmt_tx_cancel_wait)
8450 return -EOPNOTSUPP;
8451
Johannes Berg71bbc992012-06-15 15:30:18 +02008452 switch (wdev->iftype) {
8453 case NL80211_IFTYPE_STATION:
8454 case NL80211_IFTYPE_ADHOC:
8455 case NL80211_IFTYPE_P2P_CLIENT:
8456 case NL80211_IFTYPE_AP:
8457 case NL80211_IFTYPE_AP_VLAN:
8458 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008459 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008460 break;
8461 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008462 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008463 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008464
8465 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8466
Hila Gonene35e4d22012-06-27 17:19:42 +03008467 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008468}
8469
Kalle Valoffb9eb32010-02-17 17:58:10 +02008470static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8471{
Johannes Berg4c476992010-10-04 21:36:35 +02008472 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008473 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008474 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008475 u8 ps_state;
8476 bool state;
8477 int err;
8478
Johannes Berg4c476992010-10-04 21:36:35 +02008479 if (!info->attrs[NL80211_ATTR_PS_STATE])
8480 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008481
8482 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8483
Johannes Berg4c476992010-10-04 21:36:35 +02008484 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8485 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008486
8487 wdev = dev->ieee80211_ptr;
8488
Johannes Berg4c476992010-10-04 21:36:35 +02008489 if (!rdev->ops->set_power_mgmt)
8490 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008491
8492 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8493
8494 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008495 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008496
Hila Gonene35e4d22012-06-27 17:19:42 +03008497 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008498 if (!err)
8499 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008500 return err;
8501}
8502
8503static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8504{
Johannes Berg4c476992010-10-04 21:36:35 +02008505 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008506 enum nl80211_ps_state ps_state;
8507 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008508 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008509 struct sk_buff *msg;
8510 void *hdr;
8511 int err;
8512
Kalle Valoffb9eb32010-02-17 17:58:10 +02008513 wdev = dev->ieee80211_ptr;
8514
Johannes Berg4c476992010-10-04 21:36:35 +02008515 if (!rdev->ops->set_power_mgmt)
8516 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008517
8518 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008519 if (!msg)
8520 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008521
Eric W. Biederman15e47302012-09-07 20:12:54 +00008522 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008523 NL80211_CMD_GET_POWER_SAVE);
8524 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008525 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008526 goto free_msg;
8527 }
8528
8529 if (wdev->ps)
8530 ps_state = NL80211_PS_ENABLED;
8531 else
8532 ps_state = NL80211_PS_DISABLED;
8533
David S. Miller9360ffd2012-03-29 04:41:26 -04008534 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8535 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008536
8537 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008538 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008539
Johannes Berg4c476992010-10-04 21:36:35 +02008540 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008541 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008542 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008543 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008544 return err;
8545}
8546
Johannes Berg94e860f2014-01-20 23:58:15 +01008547static const struct nla_policy
8548nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008549 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8550 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8551 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008552 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8553 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8554 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008555};
8556
Thomas Pedersen84f10702012-07-12 16:17:33 -07008557static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008558 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008559{
8560 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008561 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008562 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008563
Johannes Bergd9d8b012012-11-26 12:51:52 +01008564 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008565 return -EINVAL;
8566
Thomas Pedersen84f10702012-07-12 16:17:33 -07008567 if (!rdev->ops->set_cqm_txe_config)
8568 return -EOPNOTSUPP;
8569
8570 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8571 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8572 return -EOPNOTSUPP;
8573
Hila Gonene35e4d22012-06-27 17:19:42 +03008574 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008575}
8576
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008577static int nl80211_set_cqm_rssi(struct genl_info *info,
8578 s32 threshold, u32 hysteresis)
8579{
Johannes Berg4c476992010-10-04 21:36:35 +02008580 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008581 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008582 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008583
8584 if (threshold > 0)
8585 return -EINVAL;
8586
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008587 /* disabling - hysteresis should also be zero then */
8588 if (threshold == 0)
8589 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008590
Johannes Berg4c476992010-10-04 21:36:35 +02008591 if (!rdev->ops->set_cqm_rssi_config)
8592 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008593
Johannes Berg074ac8d2010-09-16 14:58:22 +02008594 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008595 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8596 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008597
Hila Gonene35e4d22012-06-27 17:19:42 +03008598 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008599}
8600
8601static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8602{
8603 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8604 struct nlattr *cqm;
8605 int err;
8606
8607 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008608 if (!cqm)
8609 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008610
8611 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8612 nl80211_attr_cqm_policy);
8613 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008614 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008615
8616 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8617 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008618 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8619 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008620
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008621 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8622 }
8623
8624 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8625 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8626 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8627 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8628 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8629 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8630
8631 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8632 }
8633
8634 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008635}
8636
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008637static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8638{
8639 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8640 struct net_device *dev = info->user_ptr[1];
8641 struct ocb_setup setup = {};
8642 int err;
8643
8644 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8645 if (err)
8646 return err;
8647
8648 return cfg80211_join_ocb(rdev, dev, &setup);
8649}
8650
8651static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8652{
8653 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8654 struct net_device *dev = info->user_ptr[1];
8655
8656 return cfg80211_leave_ocb(rdev, dev);
8657}
8658
Johannes Berg29cbe682010-12-03 09:20:44 +01008659static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8660{
8661 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8662 struct net_device *dev = info->user_ptr[1];
8663 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008664 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008665 int err;
8666
8667 /* start with default */
8668 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008669 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008670
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008671 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008672 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008673 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008674 if (err)
8675 return err;
8676 }
8677
8678 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8679 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8680 return -EINVAL;
8681
Javier Cardonac80d5452010-12-16 17:37:49 -08008682 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8683 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8684
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008685 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8686 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8687 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8688 return -EINVAL;
8689
Marco Porsch9bdbf042013-01-07 16:04:51 +01008690 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8691 setup.beacon_interval =
8692 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8693 if (setup.beacon_interval < 10 ||
8694 setup.beacon_interval > 10000)
8695 return -EINVAL;
8696 }
8697
8698 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8699 setup.dtim_period =
8700 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8701 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8702 return -EINVAL;
8703 }
8704
Javier Cardonac80d5452010-12-16 17:37:49 -08008705 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8706 /* parse additional setup parameters if given */
8707 err = nl80211_parse_mesh_setup(info, &setup);
8708 if (err)
8709 return err;
8710 }
8711
Thomas Pedersend37bb182013-03-04 13:06:13 -08008712 if (setup.user_mpm)
8713 cfg.auto_open_plinks = false;
8714
Johannes Bergcc1d2802012-05-16 23:50:20 +02008715 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008716 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8717 if (err)
8718 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008719 } else {
8720 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008721 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008722 }
8723
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008724 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8725 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8726 int n_rates =
8727 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8728 struct ieee80211_supported_band *sband;
8729
8730 if (!setup.chandef.chan)
8731 return -EINVAL;
8732
8733 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8734
8735 err = ieee80211_get_ratemask(sband, rates, n_rates,
8736 &setup.basic_rates);
8737 if (err)
8738 return err;
8739 }
8740
Javier Cardonac80d5452010-12-16 17:37:49 -08008741 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008742}
8743
8744static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8745{
8746 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8747 struct net_device *dev = info->user_ptr[1];
8748
8749 return cfg80211_leave_mesh(rdev, dev);
8750}
8751
Johannes Bergdfb89c52012-06-27 09:23:48 +02008752#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008753static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8754 struct cfg80211_registered_device *rdev)
8755{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008756 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008757 struct nlattr *nl_pats, *nl_pat;
8758 int i, pat_len;
8759
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008760 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008761 return 0;
8762
8763 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8764 if (!nl_pats)
8765 return -ENOBUFS;
8766
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008767 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008768 nl_pat = nla_nest_start(msg, i + 1);
8769 if (!nl_pat)
8770 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008771 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008772 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008773 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008774 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8775 wowlan->patterns[i].pattern) ||
8776 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008777 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008778 return -ENOBUFS;
8779 nla_nest_end(msg, nl_pat);
8780 }
8781 nla_nest_end(msg, nl_pats);
8782
8783 return 0;
8784}
8785
Johannes Berg2a0e0472013-01-23 22:57:40 +01008786static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8787 struct cfg80211_wowlan_tcp *tcp)
8788{
8789 struct nlattr *nl_tcp;
8790
8791 if (!tcp)
8792 return 0;
8793
8794 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8795 if (!nl_tcp)
8796 return -ENOBUFS;
8797
Jiri Benc930345e2015-03-29 16:59:25 +02008798 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8799 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01008800 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8801 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8802 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8803 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8804 tcp->payload_len, tcp->payload) ||
8805 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8806 tcp->data_interval) ||
8807 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8808 tcp->wake_len, tcp->wake_data) ||
8809 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8810 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8811 return -ENOBUFS;
8812
8813 if (tcp->payload_seq.len &&
8814 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8815 sizeof(tcp->payload_seq), &tcp->payload_seq))
8816 return -ENOBUFS;
8817
8818 if (tcp->payload_tok.len &&
8819 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8820 sizeof(tcp->payload_tok) + tcp->tokens_size,
8821 &tcp->payload_tok))
8822 return -ENOBUFS;
8823
Johannes Berge248ad32013-05-16 10:24:28 +02008824 nla_nest_end(msg, nl_tcp);
8825
Johannes Berg2a0e0472013-01-23 22:57:40 +01008826 return 0;
8827}
8828
Luciano Coelho75453cc2015-01-09 14:06:37 +02008829static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8830 struct cfg80211_sched_scan_request *req)
8831{
8832 struct nlattr *nd, *freqs, *matches, *match;
8833 int i;
8834
8835 if (!req)
8836 return 0;
8837
8838 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
8839 if (!nd)
8840 return -ENOBUFS;
8841
8842 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval))
8843 return -ENOBUFS;
8844
Luciano Coelho21fea562015-03-17 16:36:01 +02008845 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
8846 return -ENOBUFS;
8847
Luciano Coelho75453cc2015-01-09 14:06:37 +02008848 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8849 if (!freqs)
8850 return -ENOBUFS;
8851
8852 for (i = 0; i < req->n_channels; i++)
8853 nla_put_u32(msg, i, req->channels[i]->center_freq);
8854
8855 nla_nest_end(msg, freqs);
8856
8857 if (req->n_match_sets) {
8858 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
8859 for (i = 0; i < req->n_match_sets; i++) {
8860 match = nla_nest_start(msg, i);
8861 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
8862 req->match_sets[i].ssid.ssid_len,
8863 req->match_sets[i].ssid.ssid);
8864 nla_nest_end(msg, match);
8865 }
8866 nla_nest_end(msg, matches);
8867 }
8868
8869 nla_nest_end(msg, nd);
8870
8871 return 0;
8872}
8873
Johannes Bergff1b6e62011-05-04 15:37:28 +02008874static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8875{
8876 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8877 struct sk_buff *msg;
8878 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008879 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008880
Johannes Berg964dc9e2013-06-03 17:25:34 +02008881 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008882 return -EOPNOTSUPP;
8883
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008884 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008885 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008886 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8887 rdev->wiphy.wowlan_config->tcp->payload_len +
8888 rdev->wiphy.wowlan_config->tcp->wake_len +
8889 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008890 }
8891
8892 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008893 if (!msg)
8894 return -ENOMEM;
8895
Eric W. Biederman15e47302012-09-07 20:12:54 +00008896 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008897 NL80211_CMD_GET_WOWLAN);
8898 if (!hdr)
8899 goto nla_put_failure;
8900
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008901 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008902 struct nlattr *nl_wowlan;
8903
8904 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8905 if (!nl_wowlan)
8906 goto nla_put_failure;
8907
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008908 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008909 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008910 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008911 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008912 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008913 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008914 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008915 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008916 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008917 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008918 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008919 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008920 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008921 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8922 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008923
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008924 if (nl80211_send_wowlan_patterns(msg, rdev))
8925 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008926
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008927 if (nl80211_send_wowlan_tcp(msg,
8928 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008929 goto nla_put_failure;
8930
Luciano Coelho75453cc2015-01-09 14:06:37 +02008931 if (nl80211_send_wowlan_nd(
8932 msg,
8933 rdev->wiphy.wowlan_config->nd_config))
8934 goto nla_put_failure;
8935
Johannes Bergff1b6e62011-05-04 15:37:28 +02008936 nla_nest_end(msg, nl_wowlan);
8937 }
8938
8939 genlmsg_end(msg, hdr);
8940 return genlmsg_reply(msg, info);
8941
8942nla_put_failure:
8943 nlmsg_free(msg);
8944 return -ENOBUFS;
8945}
8946
Johannes Berg2a0e0472013-01-23 22:57:40 +01008947static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8948 struct nlattr *attr,
8949 struct cfg80211_wowlan *trig)
8950{
8951 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8952 struct cfg80211_wowlan_tcp *cfg;
8953 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8954 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8955 u32 size;
8956 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8957 int err, port;
8958
Johannes Berg964dc9e2013-06-03 17:25:34 +02008959 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008960 return -EINVAL;
8961
8962 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8963 nla_data(attr), nla_len(attr),
8964 nl80211_wowlan_tcp_policy);
8965 if (err)
8966 return err;
8967
8968 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8969 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8970 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8971 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8972 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8973 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8974 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8975 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8976 return -EINVAL;
8977
8978 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008979 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008980 return -EINVAL;
8981
8982 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008983 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008984 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008985 return -EINVAL;
8986
8987 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008988 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008989 return -EINVAL;
8990
8991 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8992 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8993 return -EINVAL;
8994
8995 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8996 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8997
8998 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8999 tokens_size = tokln - sizeof(*tok);
9000
9001 if (!tok->len || tokens_size % tok->len)
9002 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009003 if (!rdev->wiphy.wowlan->tcp->tok)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009004 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009005 if (tok->len > rdev->wiphy.wowlan->tcp->tok->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009006 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009007 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009008 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009009 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009010 return -EINVAL;
9011 if (tok->offset + tok->len > data_size)
9012 return -EINVAL;
9013 }
9014
9015 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9016 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009017 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009018 return -EINVAL;
9019 if (seq->len == 0 || seq->len > 4)
9020 return -EINVAL;
9021 if (seq->len + seq->offset > data_size)
9022 return -EINVAL;
9023 }
9024
9025 size = sizeof(*cfg);
9026 size += data_size;
9027 size += wake_size + wake_mask_size;
9028 size += tokens_size;
9029
9030 cfg = kzalloc(size, GFP_KERNEL);
9031 if (!cfg)
9032 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009033 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9034 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009035 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9036 ETH_ALEN);
9037 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9038 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9039 else
9040 port = 0;
9041#ifdef CONFIG_INET
9042 /* allocate a socket and port for it and use it */
9043 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9044 IPPROTO_TCP, &cfg->sock, 1);
9045 if (err) {
9046 kfree(cfg);
9047 return err;
9048 }
9049 if (inet_csk_get_port(cfg->sock->sk, port)) {
9050 sock_release(cfg->sock);
9051 kfree(cfg);
9052 return -EADDRINUSE;
9053 }
9054 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9055#else
9056 if (!port) {
9057 kfree(cfg);
9058 return -EINVAL;
9059 }
9060 cfg->src_port = port;
9061#endif
9062
9063 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9064 cfg->payload_len = data_size;
9065 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9066 memcpy((void *)cfg->payload,
9067 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9068 data_size);
9069 if (seq)
9070 cfg->payload_seq = *seq;
9071 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9072 cfg->wake_len = wake_size;
9073 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9074 memcpy((void *)cfg->wake_data,
9075 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9076 wake_size);
9077 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9078 data_size + wake_size;
9079 memcpy((void *)cfg->wake_mask,
9080 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9081 wake_mask_size);
9082 if (tok) {
9083 cfg->tokens_size = tokens_size;
9084 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9085 }
9086
9087 trig->tcp = cfg;
9088
9089 return 0;
9090}
9091
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009092static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9093 const struct wiphy_wowlan_support *wowlan,
9094 struct nlattr *attr,
9095 struct cfg80211_wowlan *trig)
9096{
9097 struct nlattr **tb;
9098 int err;
9099
9100 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9101 if (!tb)
9102 return -ENOMEM;
9103
9104 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9105 err = -EOPNOTSUPP;
9106 goto out;
9107 }
9108
9109 err = nla_parse(tb, NL80211_ATTR_MAX,
9110 nla_data(attr), nla_len(attr),
9111 nl80211_policy);
9112 if (err)
9113 goto out;
9114
Johannes Bergad2b26a2014-06-12 21:39:05 +02009115 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009116 err = PTR_ERR_OR_ZERO(trig->nd_config);
9117 if (err)
9118 trig->nd_config = NULL;
9119
9120out:
9121 kfree(tb);
9122 return err;
9123}
9124
Johannes Bergff1b6e62011-05-04 15:37:28 +02009125static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9126{
9127 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9128 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009129 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009130 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009131 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009132 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009133 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009134 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009135
Johannes Berg964dc9e2013-06-03 17:25:34 +02009136 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009137 return -EOPNOTSUPP;
9138
Johannes Bergae33bd82012-07-12 16:25:02 +02009139 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9140 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009141 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009142 goto set_wakeup;
9143 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009144
9145 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9146 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9147 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9148 nl80211_wowlan_policy);
9149 if (err)
9150 return err;
9151
9152 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9153 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9154 return -EINVAL;
9155 new_triggers.any = true;
9156 }
9157
9158 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9159 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9160 return -EINVAL;
9161 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009162 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009163 }
9164
9165 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9166 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9167 return -EINVAL;
9168 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009169 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009170 }
9171
Johannes Berg77dbbb12011-07-13 10:48:55 +02009172 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9173 return -EINVAL;
9174
9175 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9176 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9177 return -EINVAL;
9178 new_triggers.gtk_rekey_failure = 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_EAP_IDENT_REQUEST]) {
9183 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9184 return -EINVAL;
9185 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009186 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009187 }
9188
9189 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9190 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9191 return -EINVAL;
9192 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009193 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009194 }
9195
9196 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9197 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9198 return -EINVAL;
9199 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009200 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009201 }
9202
Johannes Bergff1b6e62011-05-04 15:37:28 +02009203 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9204 struct nlattr *pat;
9205 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009206 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009207 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009208
Johannes Berg98fc4382015-03-01 09:10:13 +02009209 regular = true;
9210
Johannes Bergff1b6e62011-05-04 15:37:28 +02009211 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9212 rem)
9213 n_patterns++;
9214 if (n_patterns > wowlan->n_patterns)
9215 return -EINVAL;
9216
9217 new_triggers.patterns = kcalloc(n_patterns,
9218 sizeof(new_triggers.patterns[0]),
9219 GFP_KERNEL);
9220 if (!new_triggers.patterns)
9221 return -ENOMEM;
9222
9223 new_triggers.n_patterns = n_patterns;
9224 i = 0;
9225
9226 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9227 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009228 u8 *mask_pat;
9229
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009230 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9231 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009232 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009233 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9234 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009235 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009236 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009237 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009238 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009239 goto error;
9240 if (pat_len > wowlan->pattern_max_len ||
9241 pat_len < wowlan->pattern_min_len)
9242 goto error;
9243
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009244 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009245 pkt_offset = 0;
9246 else
9247 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009248 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009249 if (pkt_offset > wowlan->max_pkt_offset)
9250 goto error;
9251 new_triggers.patterns[i].pkt_offset = pkt_offset;
9252
Johannes Berg922bd802014-05-19 17:59:50 +02009253 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9254 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009255 err = -ENOMEM;
9256 goto error;
9257 }
Johannes Berg922bd802014-05-19 17:59:50 +02009258 new_triggers.patterns[i].mask = mask_pat;
9259 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009260 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009261 mask_pat += mask_len;
9262 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009263 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009264 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009265 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009266 pat_len);
9267 i++;
9268 }
9269 }
9270
Johannes Berg2a0e0472013-01-23 22:57:40 +01009271 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009272 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009273 err = nl80211_parse_wowlan_tcp(
9274 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9275 &new_triggers);
9276 if (err)
9277 goto error;
9278 }
9279
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009280 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009281 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009282 err = nl80211_parse_wowlan_nd(
9283 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9284 &new_triggers);
9285 if (err)
9286 goto error;
9287 }
9288
Johannes Berg98fc4382015-03-01 09:10:13 +02009289 /* The 'any' trigger means the device continues operating more or less
9290 * as in its normal operation mode and wakes up the host on most of the
9291 * normal interrupts (like packet RX, ...)
9292 * It therefore makes little sense to combine with the more constrained
9293 * wakeup trigger modes.
9294 */
9295 if (new_triggers.any && regular) {
9296 err = -EINVAL;
9297 goto error;
9298 }
9299
Johannes Bergae33bd82012-07-12 16:25:02 +02009300 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9301 if (!ntrig) {
9302 err = -ENOMEM;
9303 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009304 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009305 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009306 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009307
Johannes Bergae33bd82012-07-12 16:25:02 +02009308 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009309 if (rdev->ops->set_wakeup &&
9310 prev_enabled != !!rdev->wiphy.wowlan_config)
9311 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009312
Johannes Bergff1b6e62011-05-04 15:37:28 +02009313 return 0;
9314 error:
9315 for (i = 0; i < new_triggers.n_patterns; i++)
9316 kfree(new_triggers.patterns[i].mask);
9317 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009318 if (new_triggers.tcp && new_triggers.tcp->sock)
9319 sock_release(new_triggers.tcp->sock);
9320 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009321 return err;
9322}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009323#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009324
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009325static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9326 struct cfg80211_registered_device *rdev)
9327{
9328 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9329 int i, j, pat_len;
9330 struct cfg80211_coalesce_rules *rule;
9331
9332 if (!rdev->coalesce->n_rules)
9333 return 0;
9334
9335 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9336 if (!nl_rules)
9337 return -ENOBUFS;
9338
9339 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9340 nl_rule = nla_nest_start(msg, i + 1);
9341 if (!nl_rule)
9342 return -ENOBUFS;
9343
9344 rule = &rdev->coalesce->rules[i];
9345 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9346 rule->delay))
9347 return -ENOBUFS;
9348
9349 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9350 rule->condition))
9351 return -ENOBUFS;
9352
9353 nl_pats = nla_nest_start(msg,
9354 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9355 if (!nl_pats)
9356 return -ENOBUFS;
9357
9358 for (j = 0; j < rule->n_patterns; j++) {
9359 nl_pat = nla_nest_start(msg, j + 1);
9360 if (!nl_pat)
9361 return -ENOBUFS;
9362 pat_len = rule->patterns[j].pattern_len;
9363 if (nla_put(msg, NL80211_PKTPAT_MASK,
9364 DIV_ROUND_UP(pat_len, 8),
9365 rule->patterns[j].mask) ||
9366 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9367 rule->patterns[j].pattern) ||
9368 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9369 rule->patterns[j].pkt_offset))
9370 return -ENOBUFS;
9371 nla_nest_end(msg, nl_pat);
9372 }
9373 nla_nest_end(msg, nl_pats);
9374 nla_nest_end(msg, nl_rule);
9375 }
9376 nla_nest_end(msg, nl_rules);
9377
9378 return 0;
9379}
9380
9381static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9382{
9383 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9384 struct sk_buff *msg;
9385 void *hdr;
9386
9387 if (!rdev->wiphy.coalesce)
9388 return -EOPNOTSUPP;
9389
9390 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9391 if (!msg)
9392 return -ENOMEM;
9393
9394 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9395 NL80211_CMD_GET_COALESCE);
9396 if (!hdr)
9397 goto nla_put_failure;
9398
9399 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9400 goto nla_put_failure;
9401
9402 genlmsg_end(msg, hdr);
9403 return genlmsg_reply(msg, info);
9404
9405nla_put_failure:
9406 nlmsg_free(msg);
9407 return -ENOBUFS;
9408}
9409
9410void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9411{
9412 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9413 int i, j;
9414 struct cfg80211_coalesce_rules *rule;
9415
9416 if (!coalesce)
9417 return;
9418
9419 for (i = 0; i < coalesce->n_rules; i++) {
9420 rule = &coalesce->rules[i];
9421 for (j = 0; j < rule->n_patterns; j++)
9422 kfree(rule->patterns[j].mask);
9423 kfree(rule->patterns);
9424 }
9425 kfree(coalesce->rules);
9426 kfree(coalesce);
9427 rdev->coalesce = NULL;
9428}
9429
9430static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9431 struct nlattr *rule,
9432 struct cfg80211_coalesce_rules *new_rule)
9433{
9434 int err, i;
9435 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9436 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9437 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9438 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9439
9440 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9441 nla_len(rule), nl80211_coalesce_policy);
9442 if (err)
9443 return err;
9444
9445 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9446 new_rule->delay =
9447 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9448 if (new_rule->delay > coalesce->max_delay)
9449 return -EINVAL;
9450
9451 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9452 new_rule->condition =
9453 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9454 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9455 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9456 return -EINVAL;
9457
9458 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9459 return -EINVAL;
9460
9461 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9462 rem)
9463 n_patterns++;
9464 if (n_patterns > coalesce->n_patterns)
9465 return -EINVAL;
9466
9467 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9468 GFP_KERNEL);
9469 if (!new_rule->patterns)
9470 return -ENOMEM;
9471
9472 new_rule->n_patterns = n_patterns;
9473 i = 0;
9474
9475 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9476 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009477 u8 *mask_pat;
9478
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009479 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9480 nla_len(pat), NULL);
9481 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9482 !pat_tb[NL80211_PKTPAT_PATTERN])
9483 return -EINVAL;
9484 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9485 mask_len = DIV_ROUND_UP(pat_len, 8);
9486 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9487 return -EINVAL;
9488 if (pat_len > coalesce->pattern_max_len ||
9489 pat_len < coalesce->pattern_min_len)
9490 return -EINVAL;
9491
9492 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9493 pkt_offset = 0;
9494 else
9495 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9496 if (pkt_offset > coalesce->max_pkt_offset)
9497 return -EINVAL;
9498 new_rule->patterns[i].pkt_offset = pkt_offset;
9499
Johannes Berg922bd802014-05-19 17:59:50 +02009500 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9501 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009502 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009503
9504 new_rule->patterns[i].mask = mask_pat;
9505 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9506 mask_len);
9507
9508 mask_pat += mask_len;
9509 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009510 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009511 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9512 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009513 i++;
9514 }
9515
9516 return 0;
9517}
9518
9519static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9520{
9521 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9522 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9523 struct cfg80211_coalesce new_coalesce = {};
9524 struct cfg80211_coalesce *n_coalesce;
9525 int err, rem_rule, n_rules = 0, i, j;
9526 struct nlattr *rule;
9527 struct cfg80211_coalesce_rules *tmp_rule;
9528
9529 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9530 return -EOPNOTSUPP;
9531
9532 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9533 cfg80211_rdev_free_coalesce(rdev);
9534 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9535 return 0;
9536 }
9537
9538 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9539 rem_rule)
9540 n_rules++;
9541 if (n_rules > coalesce->n_rules)
9542 return -EINVAL;
9543
9544 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9545 GFP_KERNEL);
9546 if (!new_coalesce.rules)
9547 return -ENOMEM;
9548
9549 new_coalesce.n_rules = n_rules;
9550 i = 0;
9551
9552 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9553 rem_rule) {
9554 err = nl80211_parse_coalesce_rule(rdev, rule,
9555 &new_coalesce.rules[i]);
9556 if (err)
9557 goto error;
9558
9559 i++;
9560 }
9561
9562 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9563 if (err)
9564 goto error;
9565
9566 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9567 if (!n_coalesce) {
9568 err = -ENOMEM;
9569 goto error;
9570 }
9571 cfg80211_rdev_free_coalesce(rdev);
9572 rdev->coalesce = n_coalesce;
9573
9574 return 0;
9575error:
9576 for (i = 0; i < new_coalesce.n_rules; i++) {
9577 tmp_rule = &new_coalesce.rules[i];
9578 for (j = 0; j < tmp_rule->n_patterns; j++)
9579 kfree(tmp_rule->patterns[j].mask);
9580 kfree(tmp_rule->patterns);
9581 }
9582 kfree(new_coalesce.rules);
9583
9584 return err;
9585}
9586
Johannes Berge5497d72011-07-05 16:35:40 +02009587static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9588{
9589 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9590 struct net_device *dev = info->user_ptr[1];
9591 struct wireless_dev *wdev = dev->ieee80211_ptr;
9592 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9593 struct cfg80211_gtk_rekey_data rekey_data;
9594 int err;
9595
9596 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9597 return -EINVAL;
9598
9599 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9600 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9601 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9602 nl80211_rekey_policy);
9603 if (err)
9604 return err;
9605
9606 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9607 return -ERANGE;
9608 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9609 return -ERANGE;
9610 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9611 return -ERANGE;
9612
Johannes Berg78f686c2014-09-10 22:28:06 +03009613 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9614 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9615 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009616
9617 wdev_lock(wdev);
9618 if (!wdev->current_bss) {
9619 err = -ENOTCONN;
9620 goto out;
9621 }
9622
9623 if (!rdev->ops->set_rekey_data) {
9624 err = -EOPNOTSUPP;
9625 goto out;
9626 }
9627
Hila Gonene35e4d22012-06-27 17:19:42 +03009628 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009629 out:
9630 wdev_unlock(wdev);
9631 return err;
9632}
9633
Johannes Berg28946da2011-11-04 11:18:12 +01009634static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9635 struct genl_info *info)
9636{
9637 struct net_device *dev = info->user_ptr[1];
9638 struct wireless_dev *wdev = dev->ieee80211_ptr;
9639
9640 if (wdev->iftype != NL80211_IFTYPE_AP &&
9641 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9642 return -EINVAL;
9643
Eric W. Biederman15e47302012-09-07 20:12:54 +00009644 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009645 return -EBUSY;
9646
Eric W. Biederman15e47302012-09-07 20:12:54 +00009647 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009648 return 0;
9649}
9650
Johannes Berg7f6cf312011-11-04 11:18:15 +01009651static int nl80211_probe_client(struct sk_buff *skb,
9652 struct genl_info *info)
9653{
9654 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9655 struct net_device *dev = info->user_ptr[1];
9656 struct wireless_dev *wdev = dev->ieee80211_ptr;
9657 struct sk_buff *msg;
9658 void *hdr;
9659 const u8 *addr;
9660 u64 cookie;
9661 int err;
9662
9663 if (wdev->iftype != NL80211_IFTYPE_AP &&
9664 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9665 return -EOPNOTSUPP;
9666
9667 if (!info->attrs[NL80211_ATTR_MAC])
9668 return -EINVAL;
9669
9670 if (!rdev->ops->probe_client)
9671 return -EOPNOTSUPP;
9672
9673 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9674 if (!msg)
9675 return -ENOMEM;
9676
Eric W. Biederman15e47302012-09-07 20:12:54 +00009677 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009678 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009679 if (!hdr) {
9680 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009681 goto free_msg;
9682 }
9683
9684 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9685
Hila Gonene35e4d22012-06-27 17:19:42 +03009686 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009687 if (err)
9688 goto free_msg;
9689
David S. Miller9360ffd2012-03-29 04:41:26 -04009690 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9691 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009692
9693 genlmsg_end(msg, hdr);
9694
9695 return genlmsg_reply(msg, info);
9696
9697 nla_put_failure:
9698 err = -ENOBUFS;
9699 free_msg:
9700 nlmsg_free(msg);
9701 return err;
9702}
9703
Johannes Berg5e7602302011-11-04 11:18:17 +01009704static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9705{
9706 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009707 struct cfg80211_beacon_registration *reg, *nreg;
9708 int rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009709
9710 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9711 return -EOPNOTSUPP;
9712
Ben Greear37c73b52012-10-26 14:49:25 -07009713 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9714 if (!nreg)
9715 return -ENOMEM;
Johannes Berg5e7602302011-11-04 11:18:17 +01009716
Ben Greear37c73b52012-10-26 14:49:25 -07009717 /* First, check if already registered. */
9718 spin_lock_bh(&rdev->beacon_registrations_lock);
9719 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9720 if (reg->nlportid == info->snd_portid) {
9721 rv = -EALREADY;
9722 goto out_err;
9723 }
9724 }
9725 /* Add it to the list */
9726 nreg->nlportid = info->snd_portid;
9727 list_add(&nreg->list, &rdev->beacon_registrations);
9728
9729 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +01009730
9731 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009732out_err:
9733 spin_unlock_bh(&rdev->beacon_registrations_lock);
9734 kfree(nreg);
9735 return rv;
Johannes Berg5e7602302011-11-04 11:18:17 +01009736}
9737
Johannes Berg98104fde2012-06-16 00:19:54 +02009738static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9739{
9740 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9741 struct wireless_dev *wdev = info->user_ptr[1];
9742 int err;
9743
9744 if (!rdev->ops->start_p2p_device)
9745 return -EOPNOTSUPP;
9746
9747 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9748 return -EOPNOTSUPP;
9749
9750 if (wdev->p2p_started)
9751 return 0;
9752
Luciano Coelhob6a55012014-02-27 11:07:21 +02009753 if (rfkill_blocked(rdev->rfkill))
9754 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009755
Johannes Bergeeb126e2012-10-23 15:16:50 +02009756 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009757 if (err)
9758 return err;
9759
9760 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009761 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009762
9763 return 0;
9764}
9765
9766static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9767{
9768 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9769 struct wireless_dev *wdev = info->user_ptr[1];
9770
9771 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9772 return -EOPNOTSUPP;
9773
9774 if (!rdev->ops->stop_p2p_device)
9775 return -EOPNOTSUPP;
9776
Johannes Bergf9f47522013-03-19 15:04:07 +01009777 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009778
9779 return 0;
9780}
9781
Johannes Berg3713b4e2013-02-14 16:19:38 +01009782static int nl80211_get_protocol_features(struct sk_buff *skb,
9783 struct genl_info *info)
9784{
9785 void *hdr;
9786 struct sk_buff *msg;
9787
9788 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9789 if (!msg)
9790 return -ENOMEM;
9791
9792 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9793 NL80211_CMD_GET_PROTOCOL_FEATURES);
9794 if (!hdr)
9795 goto nla_put_failure;
9796
9797 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9798 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9799 goto nla_put_failure;
9800
9801 genlmsg_end(msg, hdr);
9802 return genlmsg_reply(msg, info);
9803
9804 nla_put_failure:
9805 kfree_skb(msg);
9806 return -ENOBUFS;
9807}
9808
Jouni Malinen355199e2013-02-27 17:14:27 +02009809static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9810{
9811 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9812 struct cfg80211_update_ft_ies_params ft_params;
9813 struct net_device *dev = info->user_ptr[1];
9814
9815 if (!rdev->ops->update_ft_ies)
9816 return -EOPNOTSUPP;
9817
9818 if (!info->attrs[NL80211_ATTR_MDID] ||
9819 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9820 return -EINVAL;
9821
9822 memset(&ft_params, 0, sizeof(ft_params));
9823 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9824 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9825 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9826
9827 return rdev_update_ft_ies(rdev, dev, &ft_params);
9828}
9829
Arend van Spriel5de17982013-04-18 15:49:00 +02009830static int nl80211_crit_protocol_start(struct sk_buff *skb,
9831 struct genl_info *info)
9832{
9833 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9834 struct wireless_dev *wdev = info->user_ptr[1];
9835 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9836 u16 duration;
9837 int ret;
9838
9839 if (!rdev->ops->crit_proto_start)
9840 return -EOPNOTSUPP;
9841
9842 if (WARN_ON(!rdev->ops->crit_proto_stop))
9843 return -EINVAL;
9844
9845 if (rdev->crit_proto_nlportid)
9846 return -EBUSY;
9847
9848 /* determine protocol if provided */
9849 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9850 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9851
9852 if (proto >= NUM_NL80211_CRIT_PROTO)
9853 return -EINVAL;
9854
9855 /* timeout must be provided */
9856 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9857 return -EINVAL;
9858
9859 duration =
9860 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9861
9862 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9863 return -ERANGE;
9864
9865 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9866 if (!ret)
9867 rdev->crit_proto_nlportid = info->snd_portid;
9868
9869 return ret;
9870}
9871
9872static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9873 struct genl_info *info)
9874{
9875 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9876 struct wireless_dev *wdev = info->user_ptr[1];
9877
9878 if (!rdev->ops->crit_proto_stop)
9879 return -EOPNOTSUPP;
9880
9881 if (rdev->crit_proto_nlportid) {
9882 rdev->crit_proto_nlportid = 0;
9883 rdev_crit_proto_stop(rdev, wdev);
9884 }
9885 return 0;
9886}
9887
Johannes Bergad7e7182013-11-13 13:37:47 +01009888static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9889{
9890 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9891 struct wireless_dev *wdev =
9892 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9893 int i, err;
9894 u32 vid, subcmd;
9895
9896 if (!rdev->wiphy.vendor_commands)
9897 return -EOPNOTSUPP;
9898
9899 if (IS_ERR(wdev)) {
9900 err = PTR_ERR(wdev);
9901 if (err != -EINVAL)
9902 return err;
9903 wdev = NULL;
9904 } else if (wdev->wiphy != &rdev->wiphy) {
9905 return -EINVAL;
9906 }
9907
9908 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9909 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9910 return -EINVAL;
9911
9912 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9913 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9914 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9915 const struct wiphy_vendor_command *vcmd;
9916 void *data = NULL;
9917 int len = 0;
9918
9919 vcmd = &rdev->wiphy.vendor_commands[i];
9920
9921 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9922 continue;
9923
9924 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9925 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9926 if (!wdev)
9927 return -EINVAL;
9928 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9929 !wdev->netdev)
9930 return -EINVAL;
9931
9932 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9933 if (wdev->netdev &&
9934 !netif_running(wdev->netdev))
9935 return -ENETDOWN;
9936 if (!wdev->netdev && !wdev->p2p_started)
9937 return -ENETDOWN;
9938 }
9939 } else {
9940 wdev = NULL;
9941 }
9942
9943 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9944 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9945 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9946 }
9947
9948 rdev->cur_cmd_info = info;
9949 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9950 data, len);
9951 rdev->cur_cmd_info = NULL;
9952 return err;
9953 }
9954
9955 return -EOPNOTSUPP;
9956}
9957
9958struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9959 enum nl80211_commands cmd,
9960 enum nl80211_attrs attr,
9961 int approxlen)
9962{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009963 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009964
9965 if (WARN_ON(!rdev->cur_cmd_info))
9966 return NULL;
9967
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009968 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +01009969 rdev->cur_cmd_info->snd_portid,
9970 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009971 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009972}
9973EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9974
9975int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9976{
9977 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9978 void *hdr = ((void **)skb->cb)[1];
9979 struct nlattr *data = ((void **)skb->cb)[2];
9980
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009981 /* clear CB data for netlink core to own from now on */
9982 memset(skb->cb, 0, sizeof(skb->cb));
9983
Johannes Bergad7e7182013-11-13 13:37:47 +01009984 if (WARN_ON(!rdev->cur_cmd_info)) {
9985 kfree_skb(skb);
9986 return -EINVAL;
9987 }
9988
9989 nla_nest_end(skb, data);
9990 genlmsg_end(skb, hdr);
9991 return genlmsg_reply(skb, rdev->cur_cmd_info);
9992}
9993EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9994
9995
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009996static int nl80211_set_qos_map(struct sk_buff *skb,
9997 struct genl_info *info)
9998{
9999 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10000 struct cfg80211_qos_map *qos_map = NULL;
10001 struct net_device *dev = info->user_ptr[1];
10002 u8 *pos, len, num_des, des_len, des;
10003 int ret;
10004
10005 if (!rdev->ops->set_qos_map)
10006 return -EOPNOTSUPP;
10007
10008 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10009 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10010 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10011
10012 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10013 len > IEEE80211_QOS_MAP_LEN_MAX)
10014 return -EINVAL;
10015
10016 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10017 if (!qos_map)
10018 return -ENOMEM;
10019
10020 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10021 if (num_des) {
10022 des_len = num_des *
10023 sizeof(struct cfg80211_dscp_exception);
10024 memcpy(qos_map->dscp_exception, pos, des_len);
10025 qos_map->num_des = num_des;
10026 for (des = 0; des < num_des; des++) {
10027 if (qos_map->dscp_exception[des].up > 7) {
10028 kfree(qos_map);
10029 return -EINVAL;
10030 }
10031 }
10032 pos += des_len;
10033 }
10034 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10035 }
10036
10037 wdev_lock(dev->ieee80211_ptr);
10038 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10039 if (!ret)
10040 ret = rdev_set_qos_map(rdev, dev, qos_map);
10041 wdev_unlock(dev->ieee80211_ptr);
10042
10043 kfree(qos_map);
10044 return ret;
10045}
10046
Johannes Berg960d01a2014-09-09 22:55:35 +030010047static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10048{
10049 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10050 struct net_device *dev = info->user_ptr[1];
10051 struct wireless_dev *wdev = dev->ieee80211_ptr;
10052 const u8 *peer;
10053 u8 tsid, up;
10054 u16 admitted_time = 0;
10055 int err;
10056
Johannes Berg723e73a2014-10-22 09:25:06 +020010057 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010058 return -EOPNOTSUPP;
10059
10060 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10061 !info->attrs[NL80211_ATTR_USER_PRIO])
10062 return -EINVAL;
10063
10064 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10065 if (tsid >= IEEE80211_NUM_TIDS)
10066 return -EINVAL;
10067
10068 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10069 if (up >= IEEE80211_NUM_UPS)
10070 return -EINVAL;
10071
10072 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010073 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010074 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010075 * need more attributes for that (e.g. BA session requirement);
10076 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010077 */
10078 return -EINVAL;
10079 }
10080
10081 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10082
10083 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10084 admitted_time =
10085 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10086 if (!admitted_time)
10087 return -EINVAL;
10088 }
10089
10090 wdev_lock(wdev);
10091 switch (wdev->iftype) {
10092 case NL80211_IFTYPE_STATION:
10093 case NL80211_IFTYPE_P2P_CLIENT:
10094 if (wdev->current_bss)
10095 break;
10096 err = -ENOTCONN;
10097 goto out;
10098 default:
10099 err = -EOPNOTSUPP;
10100 goto out;
10101 }
10102
10103 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10104
10105 out:
10106 wdev_unlock(wdev);
10107 return err;
10108}
10109
10110static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10111{
10112 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10113 struct net_device *dev = info->user_ptr[1];
10114 struct wireless_dev *wdev = dev->ieee80211_ptr;
10115 const u8 *peer;
10116 u8 tsid;
10117 int err;
10118
10119 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10120 return -EINVAL;
10121
10122 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10123 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10124
10125 wdev_lock(wdev);
10126 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10127 wdev_unlock(wdev);
10128
10129 return err;
10130}
10131
Arik Nemtsov1057d352014-11-19 12:54:26 +020010132static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10133 struct genl_info *info)
10134{
10135 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10136 struct net_device *dev = info->user_ptr[1];
10137 struct wireless_dev *wdev = dev->ieee80211_ptr;
10138 struct cfg80211_chan_def chandef = {};
10139 const u8 *addr;
10140 u8 oper_class;
10141 int err;
10142
10143 if (!rdev->ops->tdls_channel_switch ||
10144 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10145 return -EOPNOTSUPP;
10146
10147 switch (dev->ieee80211_ptr->iftype) {
10148 case NL80211_IFTYPE_STATION:
10149 case NL80211_IFTYPE_P2P_CLIENT:
10150 break;
10151 default:
10152 return -EOPNOTSUPP;
10153 }
10154
10155 if (!info->attrs[NL80211_ATTR_MAC] ||
10156 !info->attrs[NL80211_ATTR_OPER_CLASS])
10157 return -EINVAL;
10158
10159 err = nl80211_parse_chandef(rdev, info, &chandef);
10160 if (err)
10161 return err;
10162
10163 /*
10164 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10165 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10166 * specification is not defined for them.
10167 */
10168 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10169 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10170 chandef.width != NL80211_CHAN_WIDTH_20)
10171 return -EINVAL;
10172
10173 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010174 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10175 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010176 return -EINVAL;
10177
10178 /* don't allow switching to DFS channels */
10179 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10180 return -EINVAL;
10181
10182 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10183 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10184
10185 wdev_lock(wdev);
10186 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10187 wdev_unlock(wdev);
10188
10189 return err;
10190}
10191
10192static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10193 struct genl_info *info)
10194{
10195 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10196 struct net_device *dev = info->user_ptr[1];
10197 struct wireless_dev *wdev = dev->ieee80211_ptr;
10198 const u8 *addr;
10199
10200 if (!rdev->ops->tdls_channel_switch ||
10201 !rdev->ops->tdls_cancel_channel_switch ||
10202 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10203 return -EOPNOTSUPP;
10204
10205 switch (dev->ieee80211_ptr->iftype) {
10206 case NL80211_IFTYPE_STATION:
10207 case NL80211_IFTYPE_P2P_CLIENT:
10208 break;
10209 default:
10210 return -EOPNOTSUPP;
10211 }
10212
10213 if (!info->attrs[NL80211_ATTR_MAC])
10214 return -EINVAL;
10215
10216 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10217
10218 wdev_lock(wdev);
10219 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10220 wdev_unlock(wdev);
10221
10222 return 0;
10223}
10224
Johannes Berg4c476992010-10-04 21:36:35 +020010225#define NL80211_FLAG_NEED_WIPHY 0x01
10226#define NL80211_FLAG_NEED_NETDEV 0x02
10227#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010228#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10229#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10230 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010231#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010232/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010233#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10234 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010235#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010236
Johannes Bergf84f7712013-11-14 17:14:45 +010010237static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010238 struct genl_info *info)
10239{
10240 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010241 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010242 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010243 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10244
10245 if (rtnl)
10246 rtnl_lock();
10247
10248 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010249 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010250 if (IS_ERR(rdev)) {
10251 if (rtnl)
10252 rtnl_unlock();
10253 return PTR_ERR(rdev);
10254 }
10255 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010256 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10257 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010258 ASSERT_RTNL();
10259
Johannes Berg89a54e42012-06-15 14:33:17 +020010260 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10261 info->attrs);
10262 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010263 if (rtnl)
10264 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010265 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010266 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010267
Johannes Berg89a54e42012-06-15 14:33:17 +020010268 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010269 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010270
Johannes Berg1bf614e2012-06-15 15:23:36 +020010271 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10272 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010273 if (rtnl)
10274 rtnl_unlock();
10275 return -EINVAL;
10276 }
10277
10278 info->user_ptr[1] = dev;
10279 } else {
10280 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010281 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010282
Johannes Berg1bf614e2012-06-15 15:23:36 +020010283 if (dev) {
10284 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10285 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010286 if (rtnl)
10287 rtnl_unlock();
10288 return -ENETDOWN;
10289 }
10290
10291 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010292 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10293 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010294 if (rtnl)
10295 rtnl_unlock();
10296 return -ENETDOWN;
10297 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010298 }
10299
Johannes Berg4c476992010-10-04 21:36:35 +020010300 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010301 }
10302
10303 return 0;
10304}
10305
Johannes Bergf84f7712013-11-14 17:14:45 +010010306static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010307 struct genl_info *info)
10308{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010309 if (info->user_ptr[1]) {
10310 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10311 struct wireless_dev *wdev = info->user_ptr[1];
10312
10313 if (wdev->netdev)
10314 dev_put(wdev->netdev);
10315 } else {
10316 dev_put(info->user_ptr[1]);
10317 }
10318 }
Johannes Berg5393b912014-09-10 15:00:16 +030010319
Johannes Berg4c476992010-10-04 21:36:35 +020010320 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10321 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010322
10323 /* If needed, clear the netlink message payload from the SKB
10324 * as it might contain key data that shouldn't stick around on
10325 * the heap after the SKB is freed. The netlink message header
10326 * is still needed for further processing, so leave it intact.
10327 */
10328 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10329 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10330
10331 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10332 }
Johannes Berg4c476992010-10-04 21:36:35 +020010333}
10334
Johannes Berg4534de82013-11-14 17:14:46 +010010335static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010336 {
10337 .cmd = NL80211_CMD_GET_WIPHY,
10338 .doit = nl80211_get_wiphy,
10339 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010340 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010341 .policy = nl80211_policy,
10342 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010343 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10344 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010345 },
10346 {
10347 .cmd = NL80211_CMD_SET_WIPHY,
10348 .doit = nl80211_set_wiphy,
10349 .policy = nl80211_policy,
10350 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010351 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010352 },
10353 {
10354 .cmd = NL80211_CMD_GET_INTERFACE,
10355 .doit = nl80211_get_interface,
10356 .dumpit = nl80211_dump_interface,
10357 .policy = nl80211_policy,
10358 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010359 .internal_flags = NL80211_FLAG_NEED_WDEV |
10360 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010361 },
10362 {
10363 .cmd = NL80211_CMD_SET_INTERFACE,
10364 .doit = nl80211_set_interface,
10365 .policy = nl80211_policy,
10366 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010367 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10368 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010369 },
10370 {
10371 .cmd = NL80211_CMD_NEW_INTERFACE,
10372 .doit = nl80211_new_interface,
10373 .policy = nl80211_policy,
10374 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010375 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10376 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010377 },
10378 {
10379 .cmd = NL80211_CMD_DEL_INTERFACE,
10380 .doit = nl80211_del_interface,
10381 .policy = nl80211_policy,
10382 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010383 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010384 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010385 },
Johannes Berg41ade002007-12-19 02:03:29 +010010386 {
10387 .cmd = NL80211_CMD_GET_KEY,
10388 .doit = nl80211_get_key,
10389 .policy = nl80211_policy,
10390 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010391 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010392 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010393 },
10394 {
10395 .cmd = NL80211_CMD_SET_KEY,
10396 .doit = nl80211_set_key,
10397 .policy = nl80211_policy,
10398 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010399 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010400 NL80211_FLAG_NEED_RTNL |
10401 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010402 },
10403 {
10404 .cmd = NL80211_CMD_NEW_KEY,
10405 .doit = nl80211_new_key,
10406 .policy = nl80211_policy,
10407 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010408 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010409 NL80211_FLAG_NEED_RTNL |
10410 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010411 },
10412 {
10413 .cmd = NL80211_CMD_DEL_KEY,
10414 .doit = nl80211_del_key,
10415 .policy = nl80211_policy,
10416 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010417 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010418 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010419 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010420 {
10421 .cmd = NL80211_CMD_SET_BEACON,
10422 .policy = nl80211_policy,
10423 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010424 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010425 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010426 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010427 },
10428 {
Johannes Berg88600202012-02-13 15:17:18 +010010429 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010430 .policy = nl80211_policy,
10431 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010432 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010433 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010434 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010435 },
10436 {
Johannes Berg88600202012-02-13 15:17:18 +010010437 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010438 .policy = nl80211_policy,
10439 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010440 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010441 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010442 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010443 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010444 {
10445 .cmd = NL80211_CMD_GET_STATION,
10446 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010447 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010448 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010449 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10450 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010451 },
10452 {
10453 .cmd = NL80211_CMD_SET_STATION,
10454 .doit = nl80211_set_station,
10455 .policy = nl80211_policy,
10456 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010457 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010458 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010459 },
10460 {
10461 .cmd = NL80211_CMD_NEW_STATION,
10462 .doit = nl80211_new_station,
10463 .policy = nl80211_policy,
10464 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010465 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010466 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010467 },
10468 {
10469 .cmd = NL80211_CMD_DEL_STATION,
10470 .doit = nl80211_del_station,
10471 .policy = nl80211_policy,
10472 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010473 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010474 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010475 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010476 {
10477 .cmd = NL80211_CMD_GET_MPATH,
10478 .doit = nl80211_get_mpath,
10479 .dumpit = nl80211_dump_mpath,
10480 .policy = nl80211_policy,
10481 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010482 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010483 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010484 },
10485 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010486 .cmd = NL80211_CMD_GET_MPP,
10487 .doit = nl80211_get_mpp,
10488 .dumpit = nl80211_dump_mpp,
10489 .policy = nl80211_policy,
10490 .flags = GENL_ADMIN_PERM,
10491 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10492 NL80211_FLAG_NEED_RTNL,
10493 },
10494 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010495 .cmd = NL80211_CMD_SET_MPATH,
10496 .doit = nl80211_set_mpath,
10497 .policy = nl80211_policy,
10498 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010499 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010500 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010501 },
10502 {
10503 .cmd = NL80211_CMD_NEW_MPATH,
10504 .doit = nl80211_new_mpath,
10505 .policy = nl80211_policy,
10506 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010507 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010508 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010509 },
10510 {
10511 .cmd = NL80211_CMD_DEL_MPATH,
10512 .doit = nl80211_del_mpath,
10513 .policy = nl80211_policy,
10514 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010515 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010516 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010517 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010518 {
10519 .cmd = NL80211_CMD_SET_BSS,
10520 .doit = nl80211_set_bss,
10521 .policy = nl80211_policy,
10522 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010523 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010524 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010525 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010526 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010527 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010528 .doit = nl80211_get_reg_do,
10529 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010530 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010531 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010532 /* can be retrieved by unprivileged users */
10533 },
10534 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010535 .cmd = NL80211_CMD_SET_REG,
10536 .doit = nl80211_set_reg,
10537 .policy = nl80211_policy,
10538 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010539 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010540 },
10541 {
10542 .cmd = NL80211_CMD_REQ_SET_REG,
10543 .doit = nl80211_req_set_reg,
10544 .policy = nl80211_policy,
10545 .flags = GENL_ADMIN_PERM,
10546 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010547 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010548 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10549 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010550 .policy = nl80211_policy,
10551 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010552 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010553 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010554 },
10555 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010556 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10557 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010558 .policy = nl80211_policy,
10559 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010560 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010561 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010562 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010563 {
Johannes Berg2a519312009-02-10 21:25:55 +010010564 .cmd = NL80211_CMD_TRIGGER_SCAN,
10565 .doit = nl80211_trigger_scan,
10566 .policy = nl80211_policy,
10567 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010568 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010569 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010570 },
10571 {
10572 .cmd = NL80211_CMD_GET_SCAN,
10573 .policy = nl80211_policy,
10574 .dumpit = nl80211_dump_scan,
10575 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010576 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010577 .cmd = NL80211_CMD_START_SCHED_SCAN,
10578 .doit = nl80211_start_sched_scan,
10579 .policy = nl80211_policy,
10580 .flags = GENL_ADMIN_PERM,
10581 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10582 NL80211_FLAG_NEED_RTNL,
10583 },
10584 {
10585 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10586 .doit = nl80211_stop_sched_scan,
10587 .policy = nl80211_policy,
10588 .flags = GENL_ADMIN_PERM,
10589 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10590 NL80211_FLAG_NEED_RTNL,
10591 },
10592 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010593 .cmd = NL80211_CMD_AUTHENTICATE,
10594 .doit = nl80211_authenticate,
10595 .policy = nl80211_policy,
10596 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010597 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010598 NL80211_FLAG_NEED_RTNL |
10599 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010600 },
10601 {
10602 .cmd = NL80211_CMD_ASSOCIATE,
10603 .doit = nl80211_associate,
10604 .policy = nl80211_policy,
10605 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010606 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010607 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010608 },
10609 {
10610 .cmd = NL80211_CMD_DEAUTHENTICATE,
10611 .doit = nl80211_deauthenticate,
10612 .policy = nl80211_policy,
10613 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010614 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010615 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010616 },
10617 {
10618 .cmd = NL80211_CMD_DISASSOCIATE,
10619 .doit = nl80211_disassociate,
10620 .policy = nl80211_policy,
10621 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010622 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010623 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010624 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010625 {
10626 .cmd = NL80211_CMD_JOIN_IBSS,
10627 .doit = nl80211_join_ibss,
10628 .policy = nl80211_policy,
10629 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010630 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010631 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010632 },
10633 {
10634 .cmd = NL80211_CMD_LEAVE_IBSS,
10635 .doit = nl80211_leave_ibss,
10636 .policy = nl80211_policy,
10637 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010638 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010639 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010640 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010641#ifdef CONFIG_NL80211_TESTMODE
10642 {
10643 .cmd = NL80211_CMD_TESTMODE,
10644 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010645 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010646 .policy = nl80211_policy,
10647 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010648 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10649 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010650 },
10651#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010652 {
10653 .cmd = NL80211_CMD_CONNECT,
10654 .doit = nl80211_connect,
10655 .policy = nl80211_policy,
10656 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010657 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010658 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010659 },
10660 {
10661 .cmd = NL80211_CMD_DISCONNECT,
10662 .doit = nl80211_disconnect,
10663 .policy = nl80211_policy,
10664 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010665 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010666 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010667 },
Johannes Berg463d0182009-07-14 00:33:35 +020010668 {
10669 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10670 .doit = nl80211_wiphy_netns,
10671 .policy = nl80211_policy,
10672 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010673 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10674 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010675 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010676 {
10677 .cmd = NL80211_CMD_GET_SURVEY,
10678 .policy = nl80211_policy,
10679 .dumpit = nl80211_dump_survey,
10680 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010681 {
10682 .cmd = NL80211_CMD_SET_PMKSA,
10683 .doit = nl80211_setdel_pmksa,
10684 .policy = nl80211_policy,
10685 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010686 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010687 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010688 },
10689 {
10690 .cmd = NL80211_CMD_DEL_PMKSA,
10691 .doit = nl80211_setdel_pmksa,
10692 .policy = nl80211_policy,
10693 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010694 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010695 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010696 },
10697 {
10698 .cmd = NL80211_CMD_FLUSH_PMKSA,
10699 .doit = nl80211_flush_pmksa,
10700 .policy = nl80211_policy,
10701 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010702 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010703 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010704 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010705 {
10706 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10707 .doit = nl80211_remain_on_channel,
10708 .policy = nl80211_policy,
10709 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010710 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010711 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010712 },
10713 {
10714 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10715 .doit = nl80211_cancel_remain_on_channel,
10716 .policy = nl80211_policy,
10717 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010718 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010719 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010720 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010721 {
10722 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10723 .doit = nl80211_set_tx_bitrate_mask,
10724 .policy = nl80211_policy,
10725 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010726 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10727 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010728 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010729 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010730 .cmd = NL80211_CMD_REGISTER_FRAME,
10731 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010732 .policy = nl80211_policy,
10733 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010734 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010735 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010736 },
10737 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010738 .cmd = NL80211_CMD_FRAME,
10739 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010740 .policy = nl80211_policy,
10741 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010742 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010743 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010744 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010745 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010746 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10747 .doit = nl80211_tx_mgmt_cancel_wait,
10748 .policy = nl80211_policy,
10749 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010750 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010751 NL80211_FLAG_NEED_RTNL,
10752 },
10753 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010754 .cmd = NL80211_CMD_SET_POWER_SAVE,
10755 .doit = nl80211_set_power_save,
10756 .policy = nl80211_policy,
10757 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010758 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10759 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010760 },
10761 {
10762 .cmd = NL80211_CMD_GET_POWER_SAVE,
10763 .doit = nl80211_get_power_save,
10764 .policy = nl80211_policy,
10765 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010766 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10767 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010768 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010769 {
10770 .cmd = NL80211_CMD_SET_CQM,
10771 .doit = nl80211_set_cqm,
10772 .policy = nl80211_policy,
10773 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010774 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10775 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010776 },
Johannes Bergf444de02010-05-05 15:25:02 +020010777 {
10778 .cmd = NL80211_CMD_SET_CHANNEL,
10779 .doit = nl80211_set_channel,
10780 .policy = nl80211_policy,
10781 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010782 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10783 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010784 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010785 {
10786 .cmd = NL80211_CMD_SET_WDS_PEER,
10787 .doit = nl80211_set_wds_peer,
10788 .policy = nl80211_policy,
10789 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010790 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10791 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010792 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010793 {
10794 .cmd = NL80211_CMD_JOIN_MESH,
10795 .doit = nl80211_join_mesh,
10796 .policy = nl80211_policy,
10797 .flags = GENL_ADMIN_PERM,
10798 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10799 NL80211_FLAG_NEED_RTNL,
10800 },
10801 {
10802 .cmd = NL80211_CMD_LEAVE_MESH,
10803 .doit = nl80211_leave_mesh,
10804 .policy = nl80211_policy,
10805 .flags = GENL_ADMIN_PERM,
10806 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10807 NL80211_FLAG_NEED_RTNL,
10808 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010809 {
10810 .cmd = NL80211_CMD_JOIN_OCB,
10811 .doit = nl80211_join_ocb,
10812 .policy = nl80211_policy,
10813 .flags = GENL_ADMIN_PERM,
10814 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10815 NL80211_FLAG_NEED_RTNL,
10816 },
10817 {
10818 .cmd = NL80211_CMD_LEAVE_OCB,
10819 .doit = nl80211_leave_ocb,
10820 .policy = nl80211_policy,
10821 .flags = GENL_ADMIN_PERM,
10822 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10823 NL80211_FLAG_NEED_RTNL,
10824 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010825#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010826 {
10827 .cmd = NL80211_CMD_GET_WOWLAN,
10828 .doit = nl80211_get_wowlan,
10829 .policy = nl80211_policy,
10830 /* can be retrieved by unprivileged users */
10831 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10832 NL80211_FLAG_NEED_RTNL,
10833 },
10834 {
10835 .cmd = NL80211_CMD_SET_WOWLAN,
10836 .doit = nl80211_set_wowlan,
10837 .policy = nl80211_policy,
10838 .flags = GENL_ADMIN_PERM,
10839 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10840 NL80211_FLAG_NEED_RTNL,
10841 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010842#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010843 {
10844 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10845 .doit = nl80211_set_rekey_data,
10846 .policy = nl80211_policy,
10847 .flags = GENL_ADMIN_PERM,
10848 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010849 NL80211_FLAG_NEED_RTNL |
10850 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010851 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010852 {
10853 .cmd = NL80211_CMD_TDLS_MGMT,
10854 .doit = nl80211_tdls_mgmt,
10855 .policy = nl80211_policy,
10856 .flags = GENL_ADMIN_PERM,
10857 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10858 NL80211_FLAG_NEED_RTNL,
10859 },
10860 {
10861 .cmd = NL80211_CMD_TDLS_OPER,
10862 .doit = nl80211_tdls_oper,
10863 .policy = nl80211_policy,
10864 .flags = GENL_ADMIN_PERM,
10865 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10866 NL80211_FLAG_NEED_RTNL,
10867 },
Johannes Berg28946da2011-11-04 11:18:12 +010010868 {
10869 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10870 .doit = nl80211_register_unexpected_frame,
10871 .policy = nl80211_policy,
10872 .flags = GENL_ADMIN_PERM,
10873 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10874 NL80211_FLAG_NEED_RTNL,
10875 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010876 {
10877 .cmd = NL80211_CMD_PROBE_CLIENT,
10878 .doit = nl80211_probe_client,
10879 .policy = nl80211_policy,
10880 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010881 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010882 NL80211_FLAG_NEED_RTNL,
10883 },
Johannes Berg5e7602302011-11-04 11:18:17 +010010884 {
10885 .cmd = NL80211_CMD_REGISTER_BEACONS,
10886 .doit = nl80211_register_beacons,
10887 .policy = nl80211_policy,
10888 .flags = GENL_ADMIN_PERM,
10889 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10890 NL80211_FLAG_NEED_RTNL,
10891 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010892 {
10893 .cmd = NL80211_CMD_SET_NOACK_MAP,
10894 .doit = nl80211_set_noack_map,
10895 .policy = nl80211_policy,
10896 .flags = GENL_ADMIN_PERM,
10897 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10898 NL80211_FLAG_NEED_RTNL,
10899 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010900 {
10901 .cmd = NL80211_CMD_START_P2P_DEVICE,
10902 .doit = nl80211_start_p2p_device,
10903 .policy = nl80211_policy,
10904 .flags = GENL_ADMIN_PERM,
10905 .internal_flags = NL80211_FLAG_NEED_WDEV |
10906 NL80211_FLAG_NEED_RTNL,
10907 },
10908 {
10909 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10910 .doit = nl80211_stop_p2p_device,
10911 .policy = nl80211_policy,
10912 .flags = GENL_ADMIN_PERM,
10913 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10914 NL80211_FLAG_NEED_RTNL,
10915 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010916 {
10917 .cmd = NL80211_CMD_SET_MCAST_RATE,
10918 .doit = nl80211_set_mcast_rate,
10919 .policy = nl80211_policy,
10920 .flags = GENL_ADMIN_PERM,
10921 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10922 NL80211_FLAG_NEED_RTNL,
10923 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010924 {
10925 .cmd = NL80211_CMD_SET_MAC_ACL,
10926 .doit = nl80211_set_mac_acl,
10927 .policy = nl80211_policy,
10928 .flags = GENL_ADMIN_PERM,
10929 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10930 NL80211_FLAG_NEED_RTNL,
10931 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010932 {
10933 .cmd = NL80211_CMD_RADAR_DETECT,
10934 .doit = nl80211_start_radar_detection,
10935 .policy = nl80211_policy,
10936 .flags = GENL_ADMIN_PERM,
10937 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10938 NL80211_FLAG_NEED_RTNL,
10939 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010940 {
10941 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10942 .doit = nl80211_get_protocol_features,
10943 .policy = nl80211_policy,
10944 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010945 {
10946 .cmd = NL80211_CMD_UPDATE_FT_IES,
10947 .doit = nl80211_update_ft_ies,
10948 .policy = nl80211_policy,
10949 .flags = GENL_ADMIN_PERM,
10950 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10951 NL80211_FLAG_NEED_RTNL,
10952 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010953 {
10954 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10955 .doit = nl80211_crit_protocol_start,
10956 .policy = nl80211_policy,
10957 .flags = GENL_ADMIN_PERM,
10958 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10959 NL80211_FLAG_NEED_RTNL,
10960 },
10961 {
10962 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10963 .doit = nl80211_crit_protocol_stop,
10964 .policy = nl80211_policy,
10965 .flags = GENL_ADMIN_PERM,
10966 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10967 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010968 },
10969 {
10970 .cmd = NL80211_CMD_GET_COALESCE,
10971 .doit = nl80211_get_coalesce,
10972 .policy = nl80211_policy,
10973 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10974 NL80211_FLAG_NEED_RTNL,
10975 },
10976 {
10977 .cmd = NL80211_CMD_SET_COALESCE,
10978 .doit = nl80211_set_coalesce,
10979 .policy = nl80211_policy,
10980 .flags = GENL_ADMIN_PERM,
10981 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10982 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010983 },
10984 {
10985 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10986 .doit = nl80211_channel_switch,
10987 .policy = nl80211_policy,
10988 .flags = GENL_ADMIN_PERM,
10989 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10990 NL80211_FLAG_NEED_RTNL,
10991 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010992 {
10993 .cmd = NL80211_CMD_VENDOR,
10994 .doit = nl80211_vendor_cmd,
10995 .policy = nl80211_policy,
10996 .flags = GENL_ADMIN_PERM,
10997 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10998 NL80211_FLAG_NEED_RTNL,
10999 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011000 {
11001 .cmd = NL80211_CMD_SET_QOS_MAP,
11002 .doit = nl80211_set_qos_map,
11003 .policy = nl80211_policy,
11004 .flags = GENL_ADMIN_PERM,
11005 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11006 NL80211_FLAG_NEED_RTNL,
11007 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011008 {
11009 .cmd = NL80211_CMD_ADD_TX_TS,
11010 .doit = nl80211_add_tx_ts,
11011 .policy = nl80211_policy,
11012 .flags = GENL_ADMIN_PERM,
11013 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11014 NL80211_FLAG_NEED_RTNL,
11015 },
11016 {
11017 .cmd = NL80211_CMD_DEL_TX_TS,
11018 .doit = nl80211_del_tx_ts,
11019 .policy = nl80211_policy,
11020 .flags = GENL_ADMIN_PERM,
11021 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11022 NL80211_FLAG_NEED_RTNL,
11023 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011024 {
11025 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11026 .doit = nl80211_tdls_channel_switch,
11027 .policy = nl80211_policy,
11028 .flags = GENL_ADMIN_PERM,
11029 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11030 NL80211_FLAG_NEED_RTNL,
11031 },
11032 {
11033 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11034 .doit = nl80211_tdls_cancel_channel_switch,
11035 .policy = nl80211_policy,
11036 .flags = GENL_ADMIN_PERM,
11037 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11038 NL80211_FLAG_NEED_RTNL,
11039 },
Johannes Berg55682962007-09-20 13:09:35 -040011040};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011041
Johannes Berg55682962007-09-20 13:09:35 -040011042/* notification functions */
11043
Johannes Berg3bb20552014-05-26 13:52:25 +020011044void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11045 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011046{
11047 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011048 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011049
Johannes Berg3bb20552014-05-26 13:52:25 +020011050 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11051 cmd != NL80211_CMD_DEL_WIPHY);
11052
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011053 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011054 if (!msg)
11055 return;
11056
Johannes Berg3bb20552014-05-26 13:52:25 +020011057 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011058 nlmsg_free(msg);
11059 return;
11060 }
11061
Johannes Berg68eb5502013-11-19 15:19:38 +010011062 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011063 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011064}
11065
Johannes Berg362a4152009-05-24 16:43:15 +020011066static int nl80211_add_scan_req(struct sk_buff *msg,
11067 struct cfg80211_registered_device *rdev)
11068{
11069 struct cfg80211_scan_request *req = rdev->scan_req;
11070 struct nlattr *nest;
11071 int i;
11072
11073 if (WARN_ON(!req))
11074 return 0;
11075
11076 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11077 if (!nest)
11078 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011079 for (i = 0; i < req->n_ssids; i++) {
11080 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11081 goto nla_put_failure;
11082 }
Johannes Berg362a4152009-05-24 16:43:15 +020011083 nla_nest_end(msg, nest);
11084
11085 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11086 if (!nest)
11087 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011088 for (i = 0; i < req->n_channels; i++) {
11089 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11090 goto nla_put_failure;
11091 }
Johannes Berg362a4152009-05-24 16:43:15 +020011092 nla_nest_end(msg, nest);
11093
David S. Miller9360ffd2012-03-29 04:41:26 -040011094 if (req->ie &&
11095 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11096 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011097
Johannes Bergae917c92013-10-25 11:05:22 +020011098 if (req->flags &&
11099 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11100 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011101
Johannes Berg362a4152009-05-24 16:43:15 +020011102 return 0;
11103 nla_put_failure:
11104 return -ENOBUFS;
11105}
11106
Johannes Berga538e2d2009-06-16 19:56:42 +020011107static int nl80211_send_scan_msg(struct sk_buff *msg,
11108 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011109 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011110 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011111 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011112{
11113 void *hdr;
11114
Eric W. Biederman15e47302012-09-07 20:12:54 +000011115 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011116 if (!hdr)
11117 return -1;
11118
David S. Miller9360ffd2012-03-29 04:41:26 -040011119 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011120 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11121 wdev->netdev->ifindex)) ||
11122 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011123 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011124
Johannes Berg362a4152009-05-24 16:43:15 +020011125 /* ignore errors and send incomplete event anyway */
11126 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011127
Johannes Berg053c0952015-01-16 22:09:00 +010011128 genlmsg_end(msg, hdr);
11129 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011130
11131 nla_put_failure:
11132 genlmsg_cancel(msg, hdr);
11133 return -EMSGSIZE;
11134}
11135
Luciano Coelho807f8a82011-05-11 17:09:35 +030011136static int
11137nl80211_send_sched_scan_msg(struct sk_buff *msg,
11138 struct cfg80211_registered_device *rdev,
11139 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011140 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011141{
11142 void *hdr;
11143
Eric W. Biederman15e47302012-09-07 20:12:54 +000011144 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011145 if (!hdr)
11146 return -1;
11147
David S. Miller9360ffd2012-03-29 04:41:26 -040011148 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11149 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11150 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011151
Johannes Berg053c0952015-01-16 22:09:00 +010011152 genlmsg_end(msg, hdr);
11153 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011154
11155 nla_put_failure:
11156 genlmsg_cancel(msg, hdr);
11157 return -EMSGSIZE;
11158}
11159
Johannes Berga538e2d2009-06-16 19:56:42 +020011160void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011161 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011162{
11163 struct sk_buff *msg;
11164
Thomas Graf58050fc2012-06-28 03:57:45 +000011165 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011166 if (!msg)
11167 return;
11168
Johannes Bergfd014282012-06-18 19:17:03 +020011169 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011170 NL80211_CMD_TRIGGER_SCAN) < 0) {
11171 nlmsg_free(msg);
11172 return;
11173 }
11174
Johannes Berg68eb5502013-11-19 15:19:38 +010011175 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011176 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011177}
11178
Johannes Bergf9d15d12014-01-22 11:14:19 +020011179struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11180 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011181{
11182 struct sk_buff *msg;
11183
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011184 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011185 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011186 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011187
Johannes Bergfd014282012-06-18 19:17:03 +020011188 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011189 aborted ? NL80211_CMD_SCAN_ABORTED :
11190 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011191 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011192 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011193 }
11194
Johannes Bergf9d15d12014-01-22 11:14:19 +020011195 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011196}
11197
Johannes Bergf9d15d12014-01-22 11:14:19 +020011198void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11199 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011200{
Johannes Berg2a519312009-02-10 21:25:55 +010011201 if (!msg)
11202 return;
11203
Johannes Berg68eb5502013-11-19 15:19:38 +010011204 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011205 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011206}
11207
Luciano Coelho807f8a82011-05-11 17:09:35 +030011208void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11209 struct net_device *netdev)
11210{
11211 struct sk_buff *msg;
11212
11213 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11214 if (!msg)
11215 return;
11216
11217 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11218 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11219 nlmsg_free(msg);
11220 return;
11221 }
11222
Johannes Berg68eb5502013-11-19 15:19:38 +010011223 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011224 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011225}
11226
11227void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11228 struct net_device *netdev, u32 cmd)
11229{
11230 struct sk_buff *msg;
11231
Thomas Graf58050fc2012-06-28 03:57:45 +000011232 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011233 if (!msg)
11234 return;
11235
11236 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11237 nlmsg_free(msg);
11238 return;
11239 }
11240
Johannes Berg68eb5502013-11-19 15:19:38 +010011241 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011242 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011243}
11244
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011245static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11246 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011247{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011248 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011249 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11250 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011251
David S. Miller9360ffd2012-03-29 04:41:26 -040011252 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11253 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11254 NL80211_REGDOM_TYPE_WORLD))
11255 goto nla_put_failure;
11256 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11257 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11258 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11259 goto nla_put_failure;
11260 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11261 request->intersect) {
11262 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11263 NL80211_REGDOM_TYPE_INTERSECTION))
11264 goto nla_put_failure;
11265 } else {
11266 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11267 NL80211_REGDOM_TYPE_COUNTRY) ||
11268 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11269 request->alpha2))
11270 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011271 }
11272
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011273 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11274 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11275
11276 if (wiphy &&
11277 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11278 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011279
11280 if (wiphy &&
11281 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11282 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11283 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011284 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011285
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011286 return true;
11287
11288nla_put_failure:
11289 return false;
11290}
11291
11292/*
11293 * This can happen on global regulatory changes or device specific settings
11294 * based on custom regulatory domains.
11295 */
11296void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11297 struct regulatory_request *request)
11298{
11299 struct sk_buff *msg;
11300 void *hdr;
11301
11302 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11303 if (!msg)
11304 return;
11305
11306 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11307 if (!hdr) {
11308 nlmsg_free(msg);
11309 return;
11310 }
11311
11312 if (nl80211_reg_change_event_fill(msg, request) == false)
11313 goto nla_put_failure;
11314
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011315 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011316
Johannes Bergbc43b282009-07-25 10:54:13 +020011317 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011318 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011319 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011320 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011321
11322 return;
11323
11324nla_put_failure:
11325 genlmsg_cancel(msg, hdr);
11326 nlmsg_free(msg);
11327}
11328
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011329static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11330 struct net_device *netdev,
11331 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011332 enum nl80211_commands cmd, gfp_t gfp,
11333 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011334{
11335 struct sk_buff *msg;
11336 void *hdr;
11337
Johannes Berge6d6e342009-07-01 21:26:47 +020011338 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011339 if (!msg)
11340 return;
11341
11342 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11343 if (!hdr) {
11344 nlmsg_free(msg);
11345 return;
11346 }
11347
David S. Miller9360ffd2012-03-29 04:41:26 -040011348 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11349 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11350 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11351 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011352
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011353 if (uapsd_queues >= 0) {
11354 struct nlattr *nla_wmm =
11355 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11356 if (!nla_wmm)
11357 goto nla_put_failure;
11358
11359 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11360 uapsd_queues))
11361 goto nla_put_failure;
11362
11363 nla_nest_end(msg, nla_wmm);
11364 }
11365
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011366 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011367
Johannes Berg68eb5502013-11-19 15:19:38 +010011368 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011369 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011370 return;
11371
11372 nla_put_failure:
11373 genlmsg_cancel(msg, hdr);
11374 nlmsg_free(msg);
11375}
11376
11377void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011378 struct net_device *netdev, const u8 *buf,
11379 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011380{
11381 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011382 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011383}
11384
11385void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11386 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011387 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011388{
Johannes Berge6d6e342009-07-01 21:26:47 +020011389 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011390 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011391}
11392
Jouni Malinen53b46b82009-03-27 20:53:56 +020011393void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011394 struct net_device *netdev, const u8 *buf,
11395 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011396{
11397 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011398 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011399}
11400
Jouni Malinen53b46b82009-03-27 20:53:56 +020011401void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11402 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011403 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011404{
11405 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011406 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011407}
11408
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011409void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11410 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011411{
Johannes Berg947add32013-02-22 22:05:20 +010011412 struct wireless_dev *wdev = dev->ieee80211_ptr;
11413 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011414 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011415 const struct ieee80211_mgmt *mgmt = (void *)buf;
11416 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011417
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011418 if (WARN_ON(len < 2))
11419 return;
11420
11421 if (ieee80211_is_deauth(mgmt->frame_control))
11422 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11423 else
11424 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11425
11426 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011427 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011428}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011429EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011430
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011431static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11432 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011433 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011434{
11435 struct sk_buff *msg;
11436 void *hdr;
11437
Johannes Berge6d6e342009-07-01 21:26:47 +020011438 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011439 if (!msg)
11440 return;
11441
11442 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11443 if (!hdr) {
11444 nlmsg_free(msg);
11445 return;
11446 }
11447
David S. Miller9360ffd2012-03-29 04:41:26 -040011448 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11449 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11450 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11451 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11452 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011453
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011454 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011455
Johannes Berg68eb5502013-11-19 15:19:38 +010011456 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011457 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011458 return;
11459
11460 nla_put_failure:
11461 genlmsg_cancel(msg, hdr);
11462 nlmsg_free(msg);
11463}
11464
11465void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011466 struct net_device *netdev, const u8 *addr,
11467 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011468{
11469 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011470 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011471}
11472
11473void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011474 struct net_device *netdev, const u8 *addr,
11475 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011476{
Johannes Berge6d6e342009-07-01 21:26:47 +020011477 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11478 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011479}
11480
Samuel Ortizb23aa672009-07-01 21:26:54 +020011481void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11482 struct net_device *netdev, const u8 *bssid,
11483 const u8 *req_ie, size_t req_ie_len,
11484 const u8 *resp_ie, size_t resp_ie_len,
11485 u16 status, gfp_t gfp)
11486{
11487 struct sk_buff *msg;
11488 void *hdr;
11489
Thomas Graf58050fc2012-06-28 03:57:45 +000011490 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011491 if (!msg)
11492 return;
11493
11494 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11495 if (!hdr) {
11496 nlmsg_free(msg);
11497 return;
11498 }
11499
David S. Miller9360ffd2012-03-29 04:41:26 -040011500 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11501 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11502 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11503 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11504 (req_ie &&
11505 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11506 (resp_ie &&
11507 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11508 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011509
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011510 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011511
Johannes Berg68eb5502013-11-19 15:19:38 +010011512 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011513 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011514 return;
11515
11516 nla_put_failure:
11517 genlmsg_cancel(msg, hdr);
11518 nlmsg_free(msg);
11519
11520}
11521
11522void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11523 struct net_device *netdev, const u8 *bssid,
11524 const u8 *req_ie, size_t req_ie_len,
11525 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11526{
11527 struct sk_buff *msg;
11528 void *hdr;
11529
Thomas Graf58050fc2012-06-28 03:57:45 +000011530 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011531 if (!msg)
11532 return;
11533
11534 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11535 if (!hdr) {
11536 nlmsg_free(msg);
11537 return;
11538 }
11539
David S. Miller9360ffd2012-03-29 04:41:26 -040011540 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11541 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11542 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11543 (req_ie &&
11544 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11545 (resp_ie &&
11546 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11547 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011548
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011549 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011550
Johannes Berg68eb5502013-11-19 15:19:38 +010011551 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011552 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011553 return;
11554
11555 nla_put_failure:
11556 genlmsg_cancel(msg, hdr);
11557 nlmsg_free(msg);
11558
11559}
11560
11561void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11562 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011563 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011564{
11565 struct sk_buff *msg;
11566 void *hdr;
11567
Thomas Graf58050fc2012-06-28 03:57:45 +000011568 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011569 if (!msg)
11570 return;
11571
11572 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11573 if (!hdr) {
11574 nlmsg_free(msg);
11575 return;
11576 }
11577
David S. Miller9360ffd2012-03-29 04:41:26 -040011578 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11579 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11580 (from_ap && reason &&
11581 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11582 (from_ap &&
11583 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11584 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11585 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011586
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011587 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011588
Johannes Berg68eb5502013-11-19 15:19:38 +010011589 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011590 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011591 return;
11592
11593 nla_put_failure:
11594 genlmsg_cancel(msg, hdr);
11595 nlmsg_free(msg);
11596
11597}
11598
Johannes Berg04a773a2009-04-19 21:24:32 +020011599void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11600 struct net_device *netdev, const u8 *bssid,
11601 gfp_t gfp)
11602{
11603 struct sk_buff *msg;
11604 void *hdr;
11605
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011606 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011607 if (!msg)
11608 return;
11609
11610 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11611 if (!hdr) {
11612 nlmsg_free(msg);
11613 return;
11614 }
11615
David S. Miller9360ffd2012-03-29 04:41:26 -040011616 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11617 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11618 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11619 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011620
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011621 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011622
Johannes Berg68eb5502013-11-19 15:19:38 +010011623 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011624 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011625 return;
11626
11627 nla_put_failure:
11628 genlmsg_cancel(msg, hdr);
11629 nlmsg_free(msg);
11630}
11631
Johannes Berg947add32013-02-22 22:05:20 +010011632void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11633 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011634{
Johannes Berg947add32013-02-22 22:05:20 +010011635 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011636 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011637 struct sk_buff *msg;
11638 void *hdr;
11639
Johannes Berg947add32013-02-22 22:05:20 +010011640 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11641 return;
11642
11643 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11644
Javier Cardonac93b5e72011-04-07 15:08:34 -070011645 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11646 if (!msg)
11647 return;
11648
11649 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11650 if (!hdr) {
11651 nlmsg_free(msg);
11652 return;
11653 }
11654
David S. Miller9360ffd2012-03-29 04:41:26 -040011655 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011656 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11657 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011658 (ie_len && ie &&
11659 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11660 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011661
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011662 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011663
Johannes Berg68eb5502013-11-19 15:19:38 +010011664 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011665 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011666 return;
11667
11668 nla_put_failure:
11669 genlmsg_cancel(msg, hdr);
11670 nlmsg_free(msg);
11671}
Johannes Berg947add32013-02-22 22:05:20 +010011672EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011673
Jouni Malinena3b8b052009-03-27 21:59:49 +020011674void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11675 struct net_device *netdev, const u8 *addr,
11676 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011677 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011678{
11679 struct sk_buff *msg;
11680 void *hdr;
11681
Johannes Berge6d6e342009-07-01 21:26:47 +020011682 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011683 if (!msg)
11684 return;
11685
11686 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11687 if (!hdr) {
11688 nlmsg_free(msg);
11689 return;
11690 }
11691
David S. Miller9360ffd2012-03-29 04:41:26 -040011692 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11693 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11694 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11695 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11696 (key_id != -1 &&
11697 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11698 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11699 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011700
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011701 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011702
Johannes Berg68eb5502013-11-19 15:19:38 +010011703 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011704 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011705 return;
11706
11707 nla_put_failure:
11708 genlmsg_cancel(msg, hdr);
11709 nlmsg_free(msg);
11710}
11711
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011712void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11713 struct ieee80211_channel *channel_before,
11714 struct ieee80211_channel *channel_after)
11715{
11716 struct sk_buff *msg;
11717 void *hdr;
11718 struct nlattr *nl_freq;
11719
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011720 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011721 if (!msg)
11722 return;
11723
11724 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11725 if (!hdr) {
11726 nlmsg_free(msg);
11727 return;
11728 }
11729
11730 /*
11731 * Since we are applying the beacon hint to a wiphy we know its
11732 * wiphy_idx is valid
11733 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011734 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11735 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011736
11737 /* Before */
11738 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11739 if (!nl_freq)
11740 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011741 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011742 goto nla_put_failure;
11743 nla_nest_end(msg, nl_freq);
11744
11745 /* After */
11746 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11747 if (!nl_freq)
11748 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011749 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011750 goto nla_put_failure;
11751 nla_nest_end(msg, nl_freq);
11752
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011753 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011754
Johannes Berg463d0182009-07-14 00:33:35 +020011755 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011756 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011757 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011758 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011759
11760 return;
11761
11762nla_put_failure:
11763 genlmsg_cancel(msg, hdr);
11764 nlmsg_free(msg);
11765}
11766
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011767static void nl80211_send_remain_on_chan_event(
11768 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011769 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011770 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011771 unsigned int duration, gfp_t gfp)
11772{
11773 struct sk_buff *msg;
11774 void *hdr;
11775
11776 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11777 if (!msg)
11778 return;
11779
11780 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11781 if (!hdr) {
11782 nlmsg_free(msg);
11783 return;
11784 }
11785
David S. Miller9360ffd2012-03-29 04:41:26 -040011786 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011787 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11788 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011789 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011790 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011791 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11792 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011793 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11794 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011795
David S. Miller9360ffd2012-03-29 04:41:26 -040011796 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11797 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11798 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011799
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011800 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011801
Johannes Berg68eb5502013-11-19 15:19:38 +010011802 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011803 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011804 return;
11805
11806 nla_put_failure:
11807 genlmsg_cancel(msg, hdr);
11808 nlmsg_free(msg);
11809}
11810
Johannes Berg947add32013-02-22 22:05:20 +010011811void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11812 struct ieee80211_channel *chan,
11813 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011814{
Johannes Berg947add32013-02-22 22:05:20 +010011815 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011816 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011817
11818 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011819 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011820 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011821 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011822}
Johannes Berg947add32013-02-22 22:05:20 +010011823EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011824
Johannes Berg947add32013-02-22 22:05:20 +010011825void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11826 struct ieee80211_channel *chan,
11827 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011828{
Johannes Berg947add32013-02-22 22:05:20 +010011829 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011830 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011831
11832 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011833 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011834 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011835}
Johannes Berg947add32013-02-22 22:05:20 +010011836EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011837
Johannes Berg947add32013-02-22 22:05:20 +010011838void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11839 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011840{
Johannes Berg947add32013-02-22 22:05:20 +010011841 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011842 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011843 struct sk_buff *msg;
11844
Johannes Berg947add32013-02-22 22:05:20 +010011845 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11846
Thomas Graf58050fc2012-06-28 03:57:45 +000011847 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011848 if (!msg)
11849 return;
11850
Johannes Bergcf5ead82014-11-14 17:14:00 +010011851 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040011852 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011853 nlmsg_free(msg);
11854 return;
11855 }
11856
Johannes Berg68eb5502013-11-19 15:19:38 +010011857 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011858 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011859}
Johannes Berg947add32013-02-22 22:05:20 +010011860EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011861
Johannes Bergcf5ead82014-11-14 17:14:00 +010011862void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
11863 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011864{
Johannes Berg947add32013-02-22 22:05:20 +010011865 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011866 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011867 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010011868 struct station_info empty_sinfo = {};
11869
11870 if (!sinfo)
11871 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020011872
Johannes Berg947add32013-02-22 22:05:20 +010011873 trace_cfg80211_del_sta(dev, mac_addr);
11874
Thomas Graf58050fc2012-06-28 03:57:45 +000011875 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011876 if (!msg)
11877 return;
11878
Johannes Bergcf5ead82014-11-14 17:14:00 +010011879 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010011880 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020011881 nlmsg_free(msg);
11882 return;
11883 }
11884
Johannes Berg68eb5502013-11-19 15:19:38 +010011885 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011886 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011887}
Johannes Bergcf5ead82014-11-14 17:14:00 +010011888EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020011889
Johannes Berg947add32013-02-22 22:05:20 +010011890void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11891 enum nl80211_connect_failed_reason reason,
11892 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011893{
Johannes Berg947add32013-02-22 22:05:20 +010011894 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011895 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011896 struct sk_buff *msg;
11897 void *hdr;
11898
11899 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11900 if (!msg)
11901 return;
11902
11903 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11904 if (!hdr) {
11905 nlmsg_free(msg);
11906 return;
11907 }
11908
11909 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11910 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11911 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11912 goto nla_put_failure;
11913
11914 genlmsg_end(msg, hdr);
11915
Johannes Berg68eb5502013-11-19 15:19:38 +010011916 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011917 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011918 return;
11919
11920 nla_put_failure:
11921 genlmsg_cancel(msg, hdr);
11922 nlmsg_free(msg);
11923}
Johannes Berg947add32013-02-22 22:05:20 +010011924EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011925
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011926static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11927 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011928{
11929 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011930 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011931 struct sk_buff *msg;
11932 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011933 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011934
Eric W. Biederman15e47302012-09-07 20:12:54 +000011935 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011936 return false;
11937
11938 msg = nlmsg_new(100, gfp);
11939 if (!msg)
11940 return true;
11941
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011942 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011943 if (!hdr) {
11944 nlmsg_free(msg);
11945 return true;
11946 }
11947
David S. Miller9360ffd2012-03-29 04:41:26 -040011948 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11949 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11950 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11951 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011952
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011953 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011954 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011955 return true;
11956
11957 nla_put_failure:
11958 genlmsg_cancel(msg, hdr);
11959 nlmsg_free(msg);
11960 return true;
11961}
11962
Johannes Berg947add32013-02-22 22:05:20 +010011963bool cfg80211_rx_spurious_frame(struct net_device *dev,
11964 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011965{
Johannes Berg947add32013-02-22 22:05:20 +010011966 struct wireless_dev *wdev = dev->ieee80211_ptr;
11967 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011968
Johannes Berg947add32013-02-22 22:05:20 +010011969 trace_cfg80211_rx_spurious_frame(dev, addr);
11970
11971 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11972 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11973 trace_cfg80211_return_bool(false);
11974 return false;
11975 }
11976 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11977 addr, gfp);
11978 trace_cfg80211_return_bool(ret);
11979 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011980}
Johannes Berg947add32013-02-22 22:05:20 +010011981EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11982
11983bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11984 const u8 *addr, gfp_t gfp)
11985{
11986 struct wireless_dev *wdev = dev->ieee80211_ptr;
11987 bool ret;
11988
11989 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11990
11991 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11992 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11993 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11994 trace_cfg80211_return_bool(false);
11995 return false;
11996 }
11997 ret = __nl80211_unexpected_frame(dev,
11998 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
11999 addr, gfp);
12000 trace_cfg80211_return_bool(ret);
12001 return ret;
12002}
12003EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012004
Johannes Berg2e161f72010-08-12 15:38:38 +020012005int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012006 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012007 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012008 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012009{
Johannes Berg71bbc992012-06-15 15:30:18 +020012010 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012011 struct sk_buff *msg;
12012 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012013
12014 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12015 if (!msg)
12016 return -ENOMEM;
12017
Johannes Berg2e161f72010-08-12 15:38:38 +020012018 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012019 if (!hdr) {
12020 nlmsg_free(msg);
12021 return -ENOMEM;
12022 }
12023
David S. Miller9360ffd2012-03-29 04:41:26 -040012024 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012025 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12026 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012027 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012028 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12029 (sig_dbm &&
12030 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012031 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12032 (flags &&
12033 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012034 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012035
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012036 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012037
Eric W. Biederman15e47302012-09-07 20:12:54 +000012038 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012039
12040 nla_put_failure:
12041 genlmsg_cancel(msg, hdr);
12042 nlmsg_free(msg);
12043 return -ENOBUFS;
12044}
12045
Johannes Berg947add32013-02-22 22:05:20 +010012046void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12047 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012048{
Johannes Berg947add32013-02-22 22:05:20 +010012049 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012050 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012051 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012052 struct sk_buff *msg;
12053 void *hdr;
12054
Johannes Berg947add32013-02-22 22:05:20 +010012055 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12056
Jouni Malinen026331c2010-02-15 12:53:10 +020012057 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12058 if (!msg)
12059 return;
12060
Johannes Berg2e161f72010-08-12 15:38:38 +020012061 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012062 if (!hdr) {
12063 nlmsg_free(msg);
12064 return;
12065 }
12066
David S. Miller9360ffd2012-03-29 04:41:26 -040012067 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012068 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12069 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012070 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012071 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12072 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12073 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12074 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012075
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012076 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012077
Johannes Berg68eb5502013-11-19 15:19:38 +010012078 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012079 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012080 return;
12081
12082 nla_put_failure:
12083 genlmsg_cancel(msg, hdr);
12084 nlmsg_free(msg);
12085}
Johannes Berg947add32013-02-22 22:05:20 +010012086EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012087
Johannes Berg5b97f492014-11-26 12:37:43 +010012088static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12089 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012090{
Johannes Berg947add32013-02-22 22:05:20 +010012091 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012092 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12093 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12094 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012095
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012096 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012097 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012098
Johannes Berg5b97f492014-11-26 12:37:43 +010012099 cb = (void **)msg->cb;
12100
12101 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12102 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012103 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012104 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012105 }
12106
David S. Miller9360ffd2012-03-29 04:41:26 -040012107 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012108 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012109 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012110
Johannes Berg5b97f492014-11-26 12:37:43 +010012111 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012112 goto nla_put_failure;
12113
Johannes Berg5b97f492014-11-26 12:37:43 +010012114 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12115 if (!cb[1])
12116 goto nla_put_failure;
12117
12118 cb[2] = rdev;
12119
12120 return msg;
12121 nla_put_failure:
12122 nlmsg_free(msg);
12123 return NULL;
12124}
12125
12126static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12127{
12128 void **cb = (void **)msg->cb;
12129 struct cfg80211_registered_device *rdev = cb[2];
12130
12131 nla_nest_end(msg, cb[1]);
12132 genlmsg_end(msg, cb[0]);
12133
12134 memset(msg->cb, 0, sizeof(msg->cb));
12135
12136 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12137 NL80211_MCGRP_MLME, gfp);
12138}
12139
12140void cfg80211_cqm_rssi_notify(struct net_device *dev,
12141 enum nl80211_cqm_rssi_threshold_event rssi_event,
12142 gfp_t gfp)
12143{
12144 struct sk_buff *msg;
12145
12146 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12147
Johannes Berg98f03342014-11-26 12:42:02 +010012148 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12149 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12150 return;
12151
Johannes Berg5b97f492014-11-26 12:37:43 +010012152 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12153 if (!msg)
12154 return;
12155
David S. Miller9360ffd2012-03-29 04:41:26 -040012156 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12157 rssi_event))
12158 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012159
Johannes Berg5b97f492014-11-26 12:37:43 +010012160 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012161
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012162 return;
12163
12164 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012165 nlmsg_free(msg);
12166}
Johannes Berg947add32013-02-22 22:05:20 +010012167EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012168
Johannes Berg5b97f492014-11-26 12:37:43 +010012169void cfg80211_cqm_txe_notify(struct net_device *dev,
12170 const u8 *peer, u32 num_packets,
12171 u32 rate, u32 intvl, gfp_t gfp)
12172{
12173 struct sk_buff *msg;
12174
12175 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12176 if (!msg)
12177 return;
12178
12179 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12180 goto nla_put_failure;
12181
12182 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12183 goto nla_put_failure;
12184
12185 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12186 goto nla_put_failure;
12187
12188 cfg80211_send_cqm(msg, gfp);
12189 return;
12190
12191 nla_put_failure:
12192 nlmsg_free(msg);
12193}
12194EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12195
12196void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12197 const u8 *peer, u32 num_packets, gfp_t gfp)
12198{
12199 struct sk_buff *msg;
12200
12201 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12202
12203 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12204 if (!msg)
12205 return;
12206
12207 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12208 goto nla_put_failure;
12209
12210 cfg80211_send_cqm(msg, gfp);
12211 return;
12212
12213 nla_put_failure:
12214 nlmsg_free(msg);
12215}
12216EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12217
Johannes Berg98f03342014-11-26 12:42:02 +010012218void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12219{
12220 struct sk_buff *msg;
12221
12222 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12223 if (!msg)
12224 return;
12225
12226 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12227 goto nla_put_failure;
12228
12229 cfg80211_send_cqm(msg, gfp);
12230 return;
12231
12232 nla_put_failure:
12233 nlmsg_free(msg);
12234}
12235EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12236
Johannes Berg947add32013-02-22 22:05:20 +010012237static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12238 struct net_device *netdev, const u8 *bssid,
12239 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012240{
12241 struct sk_buff *msg;
12242 struct nlattr *rekey_attr;
12243 void *hdr;
12244
Thomas Graf58050fc2012-06-28 03:57:45 +000012245 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012246 if (!msg)
12247 return;
12248
12249 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12250 if (!hdr) {
12251 nlmsg_free(msg);
12252 return;
12253 }
12254
David S. Miller9360ffd2012-03-29 04:41:26 -040012255 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12256 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12257 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12258 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012259
12260 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12261 if (!rekey_attr)
12262 goto nla_put_failure;
12263
David S. Miller9360ffd2012-03-29 04:41:26 -040012264 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12265 NL80211_REPLAY_CTR_LEN, replay_ctr))
12266 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012267
12268 nla_nest_end(msg, rekey_attr);
12269
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012270 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012271
Johannes Berg68eb5502013-11-19 15:19:38 +010012272 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012273 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012274 return;
12275
12276 nla_put_failure:
12277 genlmsg_cancel(msg, hdr);
12278 nlmsg_free(msg);
12279}
12280
Johannes Berg947add32013-02-22 22:05:20 +010012281void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12282 const u8 *replay_ctr, gfp_t gfp)
12283{
12284 struct wireless_dev *wdev = dev->ieee80211_ptr;
12285 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012286 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012287
12288 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12289 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12290}
12291EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12292
12293static void
12294nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12295 struct net_device *netdev, int index,
12296 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012297{
12298 struct sk_buff *msg;
12299 struct nlattr *attr;
12300 void *hdr;
12301
Thomas Graf58050fc2012-06-28 03:57:45 +000012302 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012303 if (!msg)
12304 return;
12305
12306 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12307 if (!hdr) {
12308 nlmsg_free(msg);
12309 return;
12310 }
12311
David S. Miller9360ffd2012-03-29 04:41:26 -040012312 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12313 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12314 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012315
12316 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12317 if (!attr)
12318 goto nla_put_failure;
12319
David S. Miller9360ffd2012-03-29 04:41:26 -040012320 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12321 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12322 (preauth &&
12323 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12324 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012325
12326 nla_nest_end(msg, attr);
12327
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012328 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012329
Johannes Berg68eb5502013-11-19 15:19:38 +010012330 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012331 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012332 return;
12333
12334 nla_put_failure:
12335 genlmsg_cancel(msg, hdr);
12336 nlmsg_free(msg);
12337}
12338
Johannes Berg947add32013-02-22 22:05:20 +010012339void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12340 const u8 *bssid, bool preauth, gfp_t gfp)
12341{
12342 struct wireless_dev *wdev = dev->ieee80211_ptr;
12343 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012344 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012345
12346 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12347 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12348}
12349EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12350
12351static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12352 struct net_device *netdev,
12353 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012354 gfp_t gfp,
12355 enum nl80211_commands notif,
12356 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012357{
12358 struct sk_buff *msg;
12359 void *hdr;
12360
Thomas Graf58050fc2012-06-28 03:57:45 +000012361 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012362 if (!msg)
12363 return;
12364
Luciano Coelhof8d75522014-11-07 14:31:35 +020012365 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012366 if (!hdr) {
12367 nlmsg_free(msg);
12368 return;
12369 }
12370
Johannes Berg683b6d32012-11-08 21:25:48 +010012371 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12372 goto nla_put_failure;
12373
12374 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012375 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012376
Luciano Coelhof8d75522014-11-07 14:31:35 +020012377 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12378 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12379 goto nla_put_failure;
12380
Thomas Pedersen53145262012-04-06 13:35:47 -070012381 genlmsg_end(msg, hdr);
12382
Johannes Berg68eb5502013-11-19 15:19:38 +010012383 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012384 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012385 return;
12386
12387 nla_put_failure:
12388 genlmsg_cancel(msg, hdr);
12389 nlmsg_free(msg);
12390}
12391
Johannes Berg947add32013-02-22 22:05:20 +010012392void cfg80211_ch_switch_notify(struct net_device *dev,
12393 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012394{
Johannes Berg947add32013-02-22 22:05:20 +010012395 struct wireless_dev *wdev = dev->ieee80211_ptr;
12396 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012397 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012398
Simon Wunderliche487eae2013-11-21 18:19:51 +010012399 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012400
Simon Wunderliche487eae2013-11-21 18:19:51 +010012401 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012402
Michal Kazior9e0e2962014-01-29 14:22:27 +010012403 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012404 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012405 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12406 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012407}
12408EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12409
Luciano Coelhof8d75522014-11-07 14:31:35 +020012410void cfg80211_ch_switch_started_notify(struct net_device *dev,
12411 struct cfg80211_chan_def *chandef,
12412 u8 count)
12413{
12414 struct wireless_dev *wdev = dev->ieee80211_ptr;
12415 struct wiphy *wiphy = wdev->wiphy;
12416 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12417
12418 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12419
12420 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12421 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12422}
12423EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12424
Thomas Pedersen84f10702012-07-12 16:17:33 -070012425void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012426nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012427 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012428 enum nl80211_radar_event event,
12429 struct net_device *netdev, gfp_t gfp)
12430{
12431 struct sk_buff *msg;
12432 void *hdr;
12433
12434 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12435 if (!msg)
12436 return;
12437
12438 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12439 if (!hdr) {
12440 nlmsg_free(msg);
12441 return;
12442 }
12443
12444 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12445 goto nla_put_failure;
12446
12447 /* NOP and radar events don't need a netdev parameter */
12448 if (netdev) {
12449 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12450
12451 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12452 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12453 goto nla_put_failure;
12454 }
12455
12456 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12457 goto nla_put_failure;
12458
12459 if (nl80211_send_chandef(msg, chandef))
12460 goto nla_put_failure;
12461
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012462 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012463
Johannes Berg68eb5502013-11-19 15:19:38 +010012464 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012465 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012466 return;
12467
12468 nla_put_failure:
12469 genlmsg_cancel(msg, hdr);
12470 nlmsg_free(msg);
12471}
12472
Johannes Berg7f6cf312011-11-04 11:18:15 +010012473void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12474 u64 cookie, bool acked, gfp_t gfp)
12475{
12476 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012477 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012478 struct sk_buff *msg;
12479 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012480
Beni Lev4ee3e062012-08-27 12:49:39 +030012481 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12482
Thomas Graf58050fc2012-06-28 03:57:45 +000012483 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012484
Johannes Berg7f6cf312011-11-04 11:18:15 +010012485 if (!msg)
12486 return;
12487
12488 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12489 if (!hdr) {
12490 nlmsg_free(msg);
12491 return;
12492 }
12493
David S. Miller9360ffd2012-03-29 04:41:26 -040012494 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12495 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12496 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12497 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12498 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12499 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012500
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012501 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012502
Johannes Berg68eb5502013-11-19 15:19:38 +010012503 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012504 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012505 return;
12506
12507 nla_put_failure:
12508 genlmsg_cancel(msg, hdr);
12509 nlmsg_free(msg);
12510}
12511EXPORT_SYMBOL(cfg80211_probe_status);
12512
Johannes Berg5e7602302011-11-04 11:18:17 +010012513void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12514 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012515 int freq, int sig_dbm)
Johannes Berg5e7602302011-11-04 11:18:17 +010012516{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012517 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e7602302011-11-04 11:18:17 +010012518 struct sk_buff *msg;
12519 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012520 struct cfg80211_beacon_registration *reg;
Johannes Berg5e7602302011-11-04 11:18:17 +010012521
Beni Lev4ee3e062012-08-27 12:49:39 +030012522 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12523
Ben Greear37c73b52012-10-26 14:49:25 -070012524 spin_lock_bh(&rdev->beacon_registrations_lock);
12525 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12526 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12527 if (!msg) {
12528 spin_unlock_bh(&rdev->beacon_registrations_lock);
12529 return;
12530 }
Johannes Berg5e7602302011-11-04 11:18:17 +010012531
Ben Greear37c73b52012-10-26 14:49:25 -070012532 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12533 if (!hdr)
12534 goto nla_put_failure;
Johannes Berg5e7602302011-11-04 11:18:17 +010012535
Ben Greear37c73b52012-10-26 14:49:25 -070012536 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12537 (freq &&
12538 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12539 (sig_dbm &&
12540 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12541 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12542 goto nla_put_failure;
12543
12544 genlmsg_end(msg, hdr);
12545
12546 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e7602302011-11-04 11:18:17 +010012547 }
Ben Greear37c73b52012-10-26 14:49:25 -070012548 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e7602302011-11-04 11:18:17 +010012549 return;
12550
12551 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012552 spin_unlock_bh(&rdev->beacon_registrations_lock);
12553 if (hdr)
12554 genlmsg_cancel(msg, hdr);
Johannes Berg5e7602302011-11-04 11:18:17 +010012555 nlmsg_free(msg);
12556}
12557EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12558
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012559#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012560static int cfg80211_net_detect_results(struct sk_buff *msg,
12561 struct cfg80211_wowlan_wakeup *wakeup)
12562{
12563 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12564 struct nlattr *nl_results, *nl_match, *nl_freqs;
12565 int i, j;
12566
12567 nl_results = nla_nest_start(
12568 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12569 if (!nl_results)
12570 return -EMSGSIZE;
12571
12572 for (i = 0; i < nd->n_matches; i++) {
12573 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12574
12575 nl_match = nla_nest_start(msg, i);
12576 if (!nl_match)
12577 break;
12578
12579 /* The SSID attribute is optional in nl80211, but for
12580 * simplicity reasons it's always present in the
12581 * cfg80211 structure. If a driver can't pass the
12582 * SSID, that needs to be changed. A zero length SSID
12583 * is still a valid SSID (wildcard), so it cannot be
12584 * used for this purpose.
12585 */
12586 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12587 match->ssid.ssid)) {
12588 nla_nest_cancel(msg, nl_match);
12589 goto out;
12590 }
12591
12592 if (match->n_channels) {
12593 nl_freqs = nla_nest_start(
12594 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12595 if (!nl_freqs) {
12596 nla_nest_cancel(msg, nl_match);
12597 goto out;
12598 }
12599
12600 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020012601 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012602 nla_nest_cancel(msg, nl_freqs);
12603 nla_nest_cancel(msg, nl_match);
12604 goto out;
12605 }
12606 }
12607
12608 nla_nest_end(msg, nl_freqs);
12609 }
12610
12611 nla_nest_end(msg, nl_match);
12612 }
12613
12614out:
12615 nla_nest_end(msg, nl_results);
12616 return 0;
12617}
12618
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012619void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12620 struct cfg80211_wowlan_wakeup *wakeup,
12621 gfp_t gfp)
12622{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012623 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012624 struct sk_buff *msg;
12625 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012626 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012627
12628 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12629
12630 if (wakeup)
12631 size += wakeup->packet_present_len;
12632
12633 msg = nlmsg_new(size, gfp);
12634 if (!msg)
12635 return;
12636
12637 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12638 if (!hdr)
12639 goto free_msg;
12640
12641 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12642 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12643 goto free_msg;
12644
12645 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12646 wdev->netdev->ifindex))
12647 goto free_msg;
12648
12649 if (wakeup) {
12650 struct nlattr *reasons;
12651
12652 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012653 if (!reasons)
12654 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012655
12656 if (wakeup->disconnect &&
12657 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12658 goto free_msg;
12659 if (wakeup->magic_pkt &&
12660 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12661 goto free_msg;
12662 if (wakeup->gtk_rekey_failure &&
12663 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12664 goto free_msg;
12665 if (wakeup->eap_identity_req &&
12666 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12667 goto free_msg;
12668 if (wakeup->four_way_handshake &&
12669 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12670 goto free_msg;
12671 if (wakeup->rfkill_release &&
12672 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12673 goto free_msg;
12674
12675 if (wakeup->pattern_idx >= 0 &&
12676 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12677 wakeup->pattern_idx))
12678 goto free_msg;
12679
Johannes Bergae917c92013-10-25 11:05:22 +020012680 if (wakeup->tcp_match &&
12681 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12682 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012683
Johannes Bergae917c92013-10-25 11:05:22 +020012684 if (wakeup->tcp_connlost &&
12685 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12686 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012687
Johannes Bergae917c92013-10-25 11:05:22 +020012688 if (wakeup->tcp_nomoretokens &&
12689 nla_put_flag(msg,
12690 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12691 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012692
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012693 if (wakeup->packet) {
12694 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12695 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12696
12697 if (!wakeup->packet_80211) {
12698 pkt_attr =
12699 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12700 len_attr =
12701 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12702 }
12703
12704 if (wakeup->packet_len &&
12705 nla_put_u32(msg, len_attr, wakeup->packet_len))
12706 goto free_msg;
12707
12708 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12709 wakeup->packet))
12710 goto free_msg;
12711 }
12712
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012713 if (wakeup->net_detect &&
12714 cfg80211_net_detect_results(msg, wakeup))
12715 goto free_msg;
12716
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012717 nla_nest_end(msg, reasons);
12718 }
12719
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012720 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012721
Johannes Berg68eb5502013-11-19 15:19:38 +010012722 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012723 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012724 return;
12725
12726 free_msg:
12727 nlmsg_free(msg);
12728}
12729EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12730#endif
12731
Jouni Malinen3475b092012-11-16 22:49:57 +020012732void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12733 enum nl80211_tdls_operation oper,
12734 u16 reason_code, gfp_t gfp)
12735{
12736 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012737 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012738 struct sk_buff *msg;
12739 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012740
12741 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12742 reason_code);
12743
12744 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12745 if (!msg)
12746 return;
12747
12748 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12749 if (!hdr) {
12750 nlmsg_free(msg);
12751 return;
12752 }
12753
12754 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12755 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12756 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12757 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12758 (reason_code > 0 &&
12759 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12760 goto nla_put_failure;
12761
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012762 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012763
Johannes Berg68eb5502013-11-19 15:19:38 +010012764 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012765 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012766 return;
12767
12768 nla_put_failure:
12769 genlmsg_cancel(msg, hdr);
12770 nlmsg_free(msg);
12771}
12772EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12773
Jouni Malinen026331c2010-02-15 12:53:10 +020012774static int nl80211_netlink_notify(struct notifier_block * nb,
12775 unsigned long state,
12776 void *_notify)
12777{
12778 struct netlink_notify *notify = _notify;
12779 struct cfg80211_registered_device *rdev;
12780 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012781 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012782
12783 if (state != NETLINK_URELEASE)
12784 return NOTIFY_DONE;
12785
12786 rcu_read_lock();
12787
Johannes Berg5e7602302011-11-04 11:18:17 +010012788 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012789 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012790 bool schedule_scan_stop = false;
12791 struct cfg80211_sched_scan_request *sched_scan_req =
12792 rcu_dereference(rdev->sched_scan_req);
12793
12794 if (sched_scan_req && notify->portid &&
12795 sched_scan_req->owner_nlportid == notify->portid)
12796 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010012797
12798 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012799 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012800
Johannes Berg78f22b62014-03-24 17:57:27 +010012801 if (wdev->owner_nlportid == notify->portid)
12802 schedule_destroy_work = true;
12803 }
12804
Ben Greear37c73b52012-10-26 14:49:25 -070012805 spin_lock_bh(&rdev->beacon_registrations_lock);
12806 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12807 list) {
12808 if (reg->nlportid == notify->portid) {
12809 list_del(&reg->list);
12810 kfree(reg);
12811 break;
12812 }
12813 }
12814 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012815
12816 if (schedule_destroy_work) {
12817 struct cfg80211_iface_destroy *destroy;
12818
12819 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12820 if (destroy) {
12821 destroy->nlportid = notify->portid;
12822 spin_lock(&rdev->destroy_list_lock);
12823 list_add(&destroy->list, &rdev->destroy_list);
12824 spin_unlock(&rdev->destroy_list_lock);
12825 schedule_work(&rdev->destroy_work);
12826 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012827 } else if (schedule_scan_stop) {
12828 sched_scan_req->owner_nlportid = 0;
12829
12830 if (rdev->ops->sched_scan_stop &&
12831 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
12832 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010012833 }
Johannes Berg5e7602302011-11-04 11:18:17 +010012834 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012835
12836 rcu_read_unlock();
12837
Ilan peer05050752015-03-04 00:32:06 -050012838 /*
12839 * It is possible that the user space process that is controlling the
12840 * indoor setting disappeared, so notify the regulatory core.
12841 */
12842 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012843 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012844}
12845
12846static struct notifier_block nl80211_netlink_notifier = {
12847 .notifier_call = nl80211_netlink_notify,
12848};
12849
Jouni Malinen355199e2013-02-27 17:14:27 +020012850void cfg80211_ft_event(struct net_device *netdev,
12851 struct cfg80211_ft_event_params *ft_event)
12852{
12853 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012854 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012855 struct sk_buff *msg;
12856 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012857
12858 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12859
12860 if (!ft_event->target_ap)
12861 return;
12862
12863 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12864 if (!msg)
12865 return;
12866
12867 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012868 if (!hdr)
12869 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012870
Johannes Bergae917c92013-10-25 11:05:22 +020012871 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12872 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12873 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12874 goto out;
12875
12876 if (ft_event->ies &&
12877 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12878 goto out;
12879 if (ft_event->ric_ies &&
12880 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12881 ft_event->ric_ies))
12882 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012883
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012884 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012885
Johannes Berg68eb5502013-11-19 15:19:38 +010012886 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012887 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012888 return;
12889 out:
12890 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012891}
12892EXPORT_SYMBOL(cfg80211_ft_event);
12893
Arend van Spriel5de17982013-04-18 15:49:00 +020012894void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12895{
12896 struct cfg80211_registered_device *rdev;
12897 struct sk_buff *msg;
12898 void *hdr;
12899 u32 nlportid;
12900
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012901 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012902 if (!rdev->crit_proto_nlportid)
12903 return;
12904
12905 nlportid = rdev->crit_proto_nlportid;
12906 rdev->crit_proto_nlportid = 0;
12907
12908 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12909 if (!msg)
12910 return;
12911
12912 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12913 if (!hdr)
12914 goto nla_put_failure;
12915
12916 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12917 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12918 goto nla_put_failure;
12919
12920 genlmsg_end(msg, hdr);
12921
12922 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12923 return;
12924
12925 nla_put_failure:
12926 if (hdr)
12927 genlmsg_cancel(msg, hdr);
12928 nlmsg_free(msg);
12929
12930}
12931EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12932
Johannes Berg348baf02014-01-24 14:06:29 +010012933void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12934{
12935 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012936 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012937 struct sk_buff *msg;
12938 void *hdr;
12939
12940 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12941 if (!msg)
12942 return;
12943
12944 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12945 if (!hdr)
12946 goto out;
12947
12948 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12949 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12950 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12951 goto out;
12952
12953 genlmsg_end(msg, hdr);
12954
12955 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12956 NL80211_MCGRP_MLME, GFP_KERNEL);
12957 return;
12958 out:
12959 nlmsg_free(msg);
12960}
12961
Johannes Berg55682962007-09-20 13:09:35 -040012962/* initialisation/exit functions */
12963
12964int nl80211_init(void)
12965{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012966 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012967
Johannes Berg2a94fe42013-11-19 15:19:39 +010012968 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12969 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012970 if (err)
12971 return err;
12972
Jouni Malinen026331c2010-02-15 12:53:10 +020012973 err = netlink_register_notifier(&nl80211_netlink_notifier);
12974 if (err)
12975 goto err_out;
12976
Johannes Berg55682962007-09-20 13:09:35 -040012977 return 0;
12978 err_out:
12979 genl_unregister_family(&nl80211_fam);
12980 return err;
12981}
12982
12983void nl80211_exit(void)
12984{
Jouni Malinen026331c2010-02-15 12:53:10 +020012985 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012986 genl_unregister_family(&nl80211_fam);
12987}