blob: 5d8748b4c8a2d20f76c38a8394888c7fe56924bf [file] [log] [blame]
Johannes Berg55682962007-09-20 13:09:35 -04001/*
2 * This is the new netlink-based wireless configuration interface.
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Berg2740f0c2014-09-03 15:24:58 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Johannes Berg55682962007-09-20 13:09:35 -04006 */
7
8#include <linux/if.h>
9#include <linux/module.h>
10#include <linux/err.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Johannes Berg55682962007-09-20 13:09:35 -040012#include <linux/list.h>
13#include <linux/if_ether.h>
14#include <linux/ieee80211.h>
15#include <linux/nl80211.h>
16#include <linux/rtnetlink.h>
17#include <linux/netlink.h>
Johannes Berg2a519312009-02-10 21:25:55 +010018#include <linux/etherdevice.h>
Johannes Berg463d0182009-07-14 00:33:35 +020019#include <net/net_namespace.h>
Johannes Berg55682962007-09-20 13:09:35 -040020#include <net/genetlink.h>
21#include <net/cfg80211.h>
Johannes Berg463d0182009-07-14 00:33:35 +020022#include <net/sock.h>
Johannes Berg2a0e0472013-01-23 22:57:40 +010023#include <net/inet_connection_sock.h>
Johannes Berg55682962007-09-20 13:09:35 -040024#include "core.h"
25#include "nl80211.h"
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070026#include "reg.h"
Hila Gonene35e4d22012-06-27 17:19:42 +030027#include "rdev-ops.h"
Johannes Berg55682962007-09-20 13:09:35 -040028
Jouni Malinen5fb628e2011-08-10 23:54:35 +030029static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
30 struct genl_info *info,
31 struct cfg80211_crypto_settings *settings,
32 int cipher_limit);
33
Johannes Bergf84f7712013-11-14 17:14:45 +010034static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020035 struct genl_info *info);
Johannes Bergf84f7712013-11-14 17:14:45 +010036static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020037 struct genl_info *info);
38
Johannes Berg55682962007-09-20 13:09:35 -040039/* the netlink family */
40static struct genl_family nl80211_fam = {
Marcel Holtmannfb4e1562013-04-28 16:22:06 -070041 .id = GENL_ID_GENERATE, /* don't bother with a hardcoded ID */
42 .name = NL80211_GENL_NAME, /* have users key off the name instead */
43 .hdrsize = 0, /* no private header */
44 .version = 1, /* no particular meaning now */
Johannes Berg55682962007-09-20 13:09:35 -040045 .maxattr = NL80211_ATTR_MAX,
Johannes Berg463d0182009-07-14 00:33:35 +020046 .netnsok = true,
Johannes Berg4c476992010-10-04 21:36:35 +020047 .pre_doit = nl80211_pre_doit,
48 .post_doit = nl80211_post_doit,
Johannes Berg55682962007-09-20 13:09:35 -040049};
50
Johannes Berg2a94fe42013-11-19 15:19:39 +010051/* multicast groups */
52enum nl80211_multicast_groups {
53 NL80211_MCGRP_CONFIG,
54 NL80211_MCGRP_SCAN,
55 NL80211_MCGRP_REGULATORY,
56 NL80211_MCGRP_MLME,
Johannes Berg567ffc32013-12-18 14:43:31 +010057 NL80211_MCGRP_VENDOR,
Johannes Berg2a94fe42013-11-19 15:19:39 +010058 NL80211_MCGRP_TESTMODE /* keep last - ifdef! */
59};
60
61static const struct genl_multicast_group nl80211_mcgrps[] = {
Johannes Berg71b836e2014-12-23 17:17:38 +010062 [NL80211_MCGRP_CONFIG] = { .name = NL80211_MULTICAST_GROUP_CONFIG },
63 [NL80211_MCGRP_SCAN] = { .name = NL80211_MULTICAST_GROUP_SCAN },
64 [NL80211_MCGRP_REGULATORY] = { .name = NL80211_MULTICAST_GROUP_REG },
65 [NL80211_MCGRP_MLME] = { .name = NL80211_MULTICAST_GROUP_MLME },
66 [NL80211_MCGRP_VENDOR] = { .name = NL80211_MULTICAST_GROUP_VENDOR },
Johannes Berg2a94fe42013-11-19 15:19:39 +010067#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg71b836e2014-12-23 17:17:38 +010068 [NL80211_MCGRP_TESTMODE] = { .name = NL80211_MULTICAST_GROUP_TESTMODE }
Johannes Berg2a94fe42013-11-19 15:19:39 +010069#endif
70};
71
Johannes Berg89a54e42012-06-15 14:33:17 +020072/* returns ERR_PTR values */
73static struct wireless_dev *
74__cfg80211_wdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berg55682962007-09-20 13:09:35 -040075{
Johannes Berg89a54e42012-06-15 14:33:17 +020076 struct cfg80211_registered_device *rdev;
77 struct wireless_dev *result = NULL;
78 bool have_ifidx = attrs[NL80211_ATTR_IFINDEX];
79 bool have_wdev_id = attrs[NL80211_ATTR_WDEV];
80 u64 wdev_id;
81 int wiphy_idx = -1;
82 int ifidx = -1;
Johannes Berg55682962007-09-20 13:09:35 -040083
Johannes Berg5fe231e2013-05-08 21:45:15 +020084 ASSERT_RTNL();
Johannes Berg55682962007-09-20 13:09:35 -040085
Johannes Berg89a54e42012-06-15 14:33:17 +020086 if (!have_ifidx && !have_wdev_id)
87 return ERR_PTR(-EINVAL);
Johannes Berg55682962007-09-20 13:09:35 -040088
Johannes Berg89a54e42012-06-15 14:33:17 +020089 if (have_ifidx)
90 ifidx = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
91 if (have_wdev_id) {
92 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
93 wiphy_idx = wdev_id >> 32;
Johannes Berg55682962007-09-20 13:09:35 -040094 }
95
Johannes Berg89a54e42012-06-15 14:33:17 +020096 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
97 struct wireless_dev *wdev;
98
99 if (wiphy_net(&rdev->wiphy) != netns)
100 continue;
101
102 if (have_wdev_id && rdev->wiphy_idx != wiphy_idx)
103 continue;
104
Johannes Berg89a54e42012-06-15 14:33:17 +0200105 list_for_each_entry(wdev, &rdev->wdev_list, list) {
106 if (have_ifidx && wdev->netdev &&
107 wdev->netdev->ifindex == ifidx) {
108 result = wdev;
109 break;
110 }
111 if (have_wdev_id && wdev->identifier == (u32)wdev_id) {
112 result = wdev;
113 break;
114 }
115 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200116
117 if (result)
118 break;
119 }
120
121 if (result)
122 return result;
123 return ERR_PTR(-ENODEV);
Johannes Berg55682962007-09-20 13:09:35 -0400124}
125
Johannes Berga9455402012-06-15 13:32:49 +0200126static struct cfg80211_registered_device *
Johannes Berg878d9ec2012-06-15 14:18:32 +0200127__cfg80211_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
Johannes Berga9455402012-06-15 13:32:49 +0200128{
Johannes Berg7fee4772012-06-15 14:09:58 +0200129 struct cfg80211_registered_device *rdev = NULL, *tmp;
130 struct net_device *netdev;
Johannes Berga9455402012-06-15 13:32:49 +0200131
Johannes Berg5fe231e2013-05-08 21:45:15 +0200132 ASSERT_RTNL();
Johannes Berga9455402012-06-15 13:32:49 +0200133
Johannes Berg878d9ec2012-06-15 14:18:32 +0200134 if (!attrs[NL80211_ATTR_WIPHY] &&
Johannes Berg89a54e42012-06-15 14:33:17 +0200135 !attrs[NL80211_ATTR_IFINDEX] &&
136 !attrs[NL80211_ATTR_WDEV])
Johannes Berg7fee4772012-06-15 14:09:58 +0200137 return ERR_PTR(-EINVAL);
138
Johannes Berg878d9ec2012-06-15 14:18:32 +0200139 if (attrs[NL80211_ATTR_WIPHY])
Johannes Berg7fee4772012-06-15 14:09:58 +0200140 rdev = cfg80211_rdev_by_wiphy_idx(
Johannes Berg878d9ec2012-06-15 14:18:32 +0200141 nla_get_u32(attrs[NL80211_ATTR_WIPHY]));
Johannes Berga9455402012-06-15 13:32:49 +0200142
Johannes Berg89a54e42012-06-15 14:33:17 +0200143 if (attrs[NL80211_ATTR_WDEV]) {
144 u64 wdev_id = nla_get_u64(attrs[NL80211_ATTR_WDEV]);
145 struct wireless_dev *wdev;
146 bool found = false;
147
148 tmp = cfg80211_rdev_by_wiphy_idx(wdev_id >> 32);
149 if (tmp) {
150 /* make sure wdev exists */
Johannes Berg89a54e42012-06-15 14:33:17 +0200151 list_for_each_entry(wdev, &tmp->wdev_list, list) {
152 if (wdev->identifier != (u32)wdev_id)
153 continue;
154 found = true;
155 break;
156 }
Johannes Berg89a54e42012-06-15 14:33:17 +0200157
158 if (!found)
159 tmp = NULL;
160
161 if (rdev && tmp != rdev)
162 return ERR_PTR(-EINVAL);
163 rdev = tmp;
164 }
165 }
166
Johannes Berg878d9ec2012-06-15 14:18:32 +0200167 if (attrs[NL80211_ATTR_IFINDEX]) {
168 int ifindex = nla_get_u32(attrs[NL80211_ATTR_IFINDEX]);
Ying Xue7f2b8562014-01-15 10:23:45 +0800169 netdev = __dev_get_by_index(netns, ifindex);
Johannes Berg7fee4772012-06-15 14:09:58 +0200170 if (netdev) {
171 if (netdev->ieee80211_ptr)
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800172 tmp = wiphy_to_rdev(
173 netdev->ieee80211_ptr->wiphy);
Johannes Berg7fee4772012-06-15 14:09:58 +0200174 else
175 tmp = NULL;
176
Johannes Berg7fee4772012-06-15 14:09:58 +0200177 /* not wireless device -- return error */
178 if (!tmp)
179 return ERR_PTR(-EINVAL);
180
181 /* mismatch -- return error */
182 if (rdev && tmp != rdev)
183 return ERR_PTR(-EINVAL);
184
185 rdev = tmp;
Johannes Berga9455402012-06-15 13:32:49 +0200186 }
Johannes Berga9455402012-06-15 13:32:49 +0200187 }
188
Johannes Berg4f7eff12012-06-15 14:14:22 +0200189 if (!rdev)
190 return ERR_PTR(-ENODEV);
Johannes Berga9455402012-06-15 13:32:49 +0200191
Johannes Berg4f7eff12012-06-15 14:14:22 +0200192 if (netns != wiphy_net(&rdev->wiphy))
193 return ERR_PTR(-ENODEV);
194
195 return rdev;
Johannes Berga9455402012-06-15 13:32:49 +0200196}
197
198/*
199 * This function returns a pointer to the driver
200 * that the genl_info item that is passed refers to.
Johannes Berga9455402012-06-15 13:32:49 +0200201 *
202 * The result of this can be a PTR_ERR and hence must
203 * be checked with IS_ERR() for errors.
204 */
205static struct cfg80211_registered_device *
Johannes Berg4f7eff12012-06-15 14:14:22 +0200206cfg80211_get_dev_from_info(struct net *netns, struct genl_info *info)
Johannes Berga9455402012-06-15 13:32:49 +0200207{
Johannes Berg5fe231e2013-05-08 21:45:15 +0200208 return __cfg80211_rdev_from_attrs(netns, info->attrs);
Johannes Berga9455402012-06-15 13:32:49 +0200209}
210
Johannes Berg55682962007-09-20 13:09:35 -0400211/* policy for the attributes */
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300212static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
Johannes Berg55682962007-09-20 13:09:35 -0400213 [NL80211_ATTR_WIPHY] = { .type = NLA_U32 },
214 [NL80211_ATTR_WIPHY_NAME] = { .type = NLA_NUL_STRING,
David S. Miller079e24e2009-05-26 21:15:00 -0700215 .len = 20-1 },
Jouni Malinen31888482008-10-30 16:59:24 +0200216 [NL80211_ATTR_WIPHY_TXQ_PARAMS] = { .type = NLA_NESTED },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100217
Jouni Malinen72bdcf32008-11-26 16:15:24 +0200218 [NL80211_ATTR_WIPHY_FREQ] = { .type = NLA_U32 },
Sujith094d05d2008-12-12 11:57:43 +0530219 [NL80211_ATTR_WIPHY_CHANNEL_TYPE] = { .type = NLA_U32 },
Johannes Berg3d9d1d62012-11-08 23:14:50 +0100220 [NL80211_ATTR_CHANNEL_WIDTH] = { .type = NLA_U32 },
221 [NL80211_ATTR_CENTER_FREQ1] = { .type = NLA_U32 },
222 [NL80211_ATTR_CENTER_FREQ2] = { .type = NLA_U32 },
223
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +0200224 [NL80211_ATTR_WIPHY_RETRY_SHORT] = { .type = NLA_U8 },
225 [NL80211_ATTR_WIPHY_RETRY_LONG] = { .type = NLA_U8 },
226 [NL80211_ATTR_WIPHY_FRAG_THRESHOLD] = { .type = NLA_U32 },
227 [NL80211_ATTR_WIPHY_RTS_THRESHOLD] = { .type = NLA_U32 },
Lukáš Turek81077e82009-12-21 22:50:47 +0100228 [NL80211_ATTR_WIPHY_COVERAGE_CLASS] = { .type = NLA_U8 },
Lorenzo Bianconi3057dbf2014-09-04 23:57:40 +0200229 [NL80211_ATTR_WIPHY_DYN_ACK] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400230
231 [NL80211_ATTR_IFTYPE] = { .type = NLA_U32 },
232 [NL80211_ATTR_IFINDEX] = { .type = NLA_U32 },
233 [NL80211_ATTR_IFNAME] = { .type = NLA_NUL_STRING, .len = IFNAMSIZ-1 },
Johannes Berg41ade002007-12-19 02:03:29 +0100234
Eliad Pellere007b852011-11-24 18:13:56 +0200235 [NL80211_ATTR_MAC] = { .len = ETH_ALEN },
236 [NL80211_ATTR_PREV_BSSID] = { .len = ETH_ALEN },
Johannes Berg41ade002007-12-19 02:03:29 +0100237
Johannes Bergb9454e82009-07-08 13:29:08 +0200238 [NL80211_ATTR_KEY] = { .type = NLA_NESTED, },
Johannes Berg41ade002007-12-19 02:03:29 +0100239 [NL80211_ATTR_KEY_DATA] = { .type = NLA_BINARY,
240 .len = WLAN_MAX_KEY_LEN },
241 [NL80211_ATTR_KEY_IDX] = { .type = NLA_U8 },
242 [NL80211_ATTR_KEY_CIPHER] = { .type = NLA_U32 },
243 [NL80211_ATTR_KEY_DEFAULT] = { .type = NLA_FLAG },
Jouni Malinen81962262011-11-02 23:36:31 +0200244 [NL80211_ATTR_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Berge31b8212010-10-05 19:39:30 +0200245 [NL80211_ATTR_KEY_TYPE] = { .type = NLA_U32 },
Johannes Berged1b6cc2007-12-19 02:03:32 +0100246
247 [NL80211_ATTR_BEACON_INTERVAL] = { .type = NLA_U32 },
248 [NL80211_ATTR_DTIM_PERIOD] = { .type = NLA_U32 },
249 [NL80211_ATTR_BEACON_HEAD] = { .type = NLA_BINARY,
250 .len = IEEE80211_MAX_DATA_LEN },
251 [NL80211_ATTR_BEACON_TAIL] = { .type = NLA_BINARY,
252 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg5727ef12007-12-19 02:03:34 +0100253 [NL80211_ATTR_STA_AID] = { .type = NLA_U16 },
254 [NL80211_ATTR_STA_FLAGS] = { .type = NLA_NESTED },
255 [NL80211_ATTR_STA_LISTEN_INTERVAL] = { .type = NLA_U16 },
256 [NL80211_ATTR_STA_SUPPORTED_RATES] = { .type = NLA_BINARY,
257 .len = NL80211_MAX_SUPP_RATES },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100258 [NL80211_ATTR_STA_PLINK_ACTION] = { .type = NLA_U8 },
Johannes Berg5727ef12007-12-19 02:03:34 +0100259 [NL80211_ATTR_STA_VLAN] = { .type = NLA_U32 },
Johannes Berg0a9542e2008-10-15 11:54:04 +0200260 [NL80211_ATTR_MNTR_FLAGS] = { /* NLA_NESTED can't be empty */ },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100261 [NL80211_ATTR_MESH_ID] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +0800262 .len = IEEE80211_MAX_MESH_ID_LEN },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100263 [NL80211_ATTR_MPATH_NEXT_HOP] = { .type = NLA_U32 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300264
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -0700265 [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 },
266 [NL80211_ATTR_REG_RULES] = { .type = NLA_NESTED },
267
Jouni Malinen9f1ba902008-08-07 20:07:01 +0300268 [NL80211_ATTR_BSS_CTS_PROT] = { .type = NLA_U8 },
269 [NL80211_ATTR_BSS_SHORT_PREAMBLE] = { .type = NLA_U8 },
270 [NL80211_ATTR_BSS_SHORT_SLOT_TIME] = { .type = NLA_U8 },
Jouni Malinen90c97a02008-10-30 16:59:22 +0200271 [NL80211_ATTR_BSS_BASIC_RATES] = { .type = NLA_BINARY,
272 .len = NL80211_MAX_SUPP_RATES },
Helmut Schaa50b12f52010-11-19 12:40:25 +0100273 [NL80211_ATTR_BSS_HT_OPMODE] = { .type = NLA_U16 },
Jouni Malinen36aedc92008-08-25 11:58:58 +0300274
Javier Cardona24bdd9f2010-12-16 17:37:48 -0800275 [NL80211_ATTR_MESH_CONFIG] = { .type = NLA_NESTED },
Javier Cardona15d5dda2011-04-07 15:08:28 -0700276 [NL80211_ATTR_SUPPORT_MESH_AUTH] = { .type = NLA_FLAG },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700277
Johannes Berg6c739412011-11-03 09:27:01 +0100278 [NL80211_ATTR_HT_CAPABILITY] = { .len = NL80211_HT_CAPABILITY_LEN },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +0200279
280 [NL80211_ATTR_MGMT_SUBTYPE] = { .type = NLA_U8 },
281 [NL80211_ATTR_IE] = { .type = NLA_BINARY,
282 .len = IEEE80211_MAX_DATA_LEN },
Johannes Berg2a519312009-02-10 21:25:55 +0100283 [NL80211_ATTR_SCAN_FREQUENCIES] = { .type = NLA_NESTED },
284 [NL80211_ATTR_SCAN_SSIDS] = { .type = NLA_NESTED },
Jouni Malinen636a5d32009-03-19 13:39:22 +0200285
286 [NL80211_ATTR_SSID] = { .type = NLA_BINARY,
287 .len = IEEE80211_MAX_SSID_LEN },
288 [NL80211_ATTR_AUTH_TYPE] = { .type = NLA_U32 },
289 [NL80211_ATTR_REASON_CODE] = { .type = NLA_U16 },
Johannes Berg04a773a2009-04-19 21:24:32 +0200290 [NL80211_ATTR_FREQ_FIXED] = { .type = NLA_FLAG },
Jouni Malinen1965c852009-04-22 21:38:25 +0300291 [NL80211_ATTR_TIMED_OUT] = { .type = NLA_FLAG },
Jouni Malinendc6382c2009-05-06 22:09:37 +0300292 [NL80211_ATTR_USE_MFP] = { .type = NLA_U32 },
Johannes Bergeccb8e82009-05-11 21:57:56 +0300293 [NL80211_ATTR_STA_FLAGS2] = {
294 .len = sizeof(struct nl80211_sta_flag_update),
295 },
Jouni Malinen3f77316c2009-05-11 21:57:57 +0300296 [NL80211_ATTR_CONTROL_PORT] = { .type = NLA_FLAG },
Johannes Bergc0692b82010-08-27 14:26:53 +0300297 [NL80211_ATTR_CONTROL_PORT_ETHERTYPE] = { .type = NLA_U16 },
298 [NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT] = { .type = NLA_FLAG },
Samuel Ortizb23aa672009-07-01 21:26:54 +0200299 [NL80211_ATTR_PRIVACY] = { .type = NLA_FLAG },
300 [NL80211_ATTR_CIPHER_SUITE_GROUP] = { .type = NLA_U32 },
301 [NL80211_ATTR_WPA_VERSIONS] = { .type = NLA_U32 },
Johannes Berg463d0182009-07-14 00:33:35 +0200302 [NL80211_ATTR_PID] = { .type = NLA_U32 },
Felix Fietkau8b787642009-11-10 18:53:10 +0100303 [NL80211_ATTR_4ADDR] = { .type = NLA_U8 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +0100304 [NL80211_ATTR_PMKID] = { .type = NLA_BINARY,
305 .len = WLAN_PMKID_LEN },
Jouni Malinen9588bbd2009-12-23 13:15:41 +0100306 [NL80211_ATTR_DURATION] = { .type = NLA_U32 },
307 [NL80211_ATTR_COOKIE] = { .type = NLA_U64 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +0200308 [NL80211_ATTR_TX_RATES] = { .type = NLA_NESTED },
Jouni Malinen026331c2010-02-15 12:53:10 +0200309 [NL80211_ATTR_FRAME] = { .type = NLA_BINARY,
310 .len = IEEE80211_MAX_DATA_LEN },
311 [NL80211_ATTR_FRAME_MATCH] = { .type = NLA_BINARY, },
Kalle Valoffb9eb32010-02-17 17:58:10 +0200312 [NL80211_ATTR_PS_STATE] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +0200313 [NL80211_ATTR_CQM] = { .type = NLA_NESTED, },
Jouni Malinend5cdfac2010-04-04 09:37:19 +0300314 [NL80211_ATTR_LOCAL_STATE_CHANGE] = { .type = NLA_FLAG },
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +0200315 [NL80211_ATTR_AP_ISOLATE] = { .type = NLA_U8 },
Juuso Oikarinen98d2ff82010-06-23 12:12:38 +0300316 [NL80211_ATTR_WIPHY_TX_POWER_SETTING] = { .type = NLA_U32 },
317 [NL80211_ATTR_WIPHY_TX_POWER_LEVEL] = { .type = NLA_U32 },
Johannes Berg2e161f72010-08-12 15:38:38 +0200318 [NL80211_ATTR_FRAME_TYPE] = { .type = NLA_U16 },
Bruno Randolfafe0cbf2010-11-10 12:50:50 +0900319 [NL80211_ATTR_WIPHY_ANTENNA_TX] = { .type = NLA_U32 },
320 [NL80211_ATTR_WIPHY_ANTENNA_RX] = { .type = NLA_U32 },
Felix Fietkau885a46d2010-11-11 15:07:22 +0100321 [NL80211_ATTR_MCAST_RATE] = { .type = NLA_U32 },
Johannes Bergf7ca38d2010-11-25 10:02:29 +0100322 [NL80211_ATTR_OFFCHANNEL_TX_OK] = { .type = NLA_FLAG },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100323 [NL80211_ATTR_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200324 [NL80211_ATTR_WOWLAN_TRIGGERS] = { .type = NLA_NESTED },
Javier Cardona9c3990a2011-05-03 16:57:11 -0700325 [NL80211_ATTR_STA_PLINK_STATE] = { .type = NLA_U8 },
Luciano Coelhobbe6ad62011-05-11 17:09:37 +0300326 [NL80211_ATTR_SCHED_SCAN_INTERVAL] = { .type = NLA_U32 },
Johannes Berge5497d72011-07-05 16:35:40 +0200327 [NL80211_ATTR_REKEY_DATA] = { .type = NLA_NESTED },
Johannes Berg34850ab2011-07-18 18:08:35 +0200328 [NL80211_ATTR_SCAN_SUPP_RATES] = { .type = NLA_NESTED },
Jouni Malinen32e9de82011-08-10 23:53:31 +0300329 [NL80211_ATTR_HIDDEN_SSID] = { .type = NLA_U32 },
Jouni Malinen9946ecf2011-08-10 23:55:56 +0300330 [NL80211_ATTR_IE_PROBE_RESP] = { .type = NLA_BINARY,
331 .len = IEEE80211_MAX_DATA_LEN },
332 [NL80211_ATTR_IE_ASSOC_RESP] = { .type = NLA_BINARY,
333 .len = IEEE80211_MAX_DATA_LEN },
Vivek Natarajanf4b34b52011-08-29 14:23:03 +0530334 [NL80211_ATTR_ROAM_SUPPORT] = { .type = NLA_FLAG },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300335 [NL80211_ATTR_SCHED_SCAN_MATCH] = { .type = NLA_NESTED },
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +0530336 [NL80211_ATTR_TX_NO_CCK_RATE] = { .type = NLA_FLAG },
Arik Nemtsov109086c2011-09-28 14:12:50 +0300337 [NL80211_ATTR_TDLS_ACTION] = { .type = NLA_U8 },
338 [NL80211_ATTR_TDLS_DIALOG_TOKEN] = { .type = NLA_U8 },
339 [NL80211_ATTR_TDLS_OPERATION] = { .type = NLA_U8 },
340 [NL80211_ATTR_TDLS_SUPPORT] = { .type = NLA_FLAG },
341 [NL80211_ATTR_TDLS_EXTERNAL_SETUP] = { .type = NLA_FLAG },
Arik Nemtsov31fa97c2014-06-11 17:18:21 +0300342 [NL80211_ATTR_TDLS_INITIATOR] = { .type = NLA_FLAG },
Johannes Berge247bd902011-11-04 11:18:21 +0100343 [NL80211_ATTR_DONT_WAIT_FOR_ACK] = { .type = NLA_FLAG },
Arik Nemtsov00f740e2011-11-10 11:28:56 +0200344 [NL80211_ATTR_PROBE_RESP] = { .type = NLA_BINARY,
345 .len = IEEE80211_MAX_DATA_LEN },
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -0700346 [NL80211_ATTR_DFS_REGION] = { .type = NLA_U8 },
Ben Greear7e7c8922011-11-18 11:31:59 -0800347 [NL80211_ATTR_DISABLE_HT] = { .type = NLA_FLAG },
348 [NL80211_ATTR_HT_CAPABILITY_MASK] = {
349 .len = NL80211_HT_CAPABILITY_LEN
350 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +0100351 [NL80211_ATTR_NOACK_MAP] = { .type = NLA_U16 },
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +0530352 [NL80211_ATTR_INACTIVITY_TIMEOUT] = { .type = NLA_U16 },
Bala Shanmugam4486ea92012-03-07 17:27:12 +0530353 [NL80211_ATTR_BG_SCAN_PERIOD] = { .type = NLA_U16 },
Johannes Berg89a54e42012-06-15 14:33:17 +0200354 [NL80211_ATTR_WDEV] = { .type = NLA_U64 },
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -0700355 [NL80211_ATTR_USER_REG_HINT_TYPE] = { .type = NLA_U32 },
Jouni Malinene39e5b52012-09-30 19:29:39 +0300356 [NL80211_ATTR_SAE_DATA] = { .type = NLA_BINARY, },
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +0000357 [NL80211_ATTR_VHT_CAPABILITY] = { .len = NL80211_VHT_CAPABILITY_LEN },
Sam Lefflered4737712012-10-11 21:03:31 -0700358 [NL80211_ATTR_SCAN_FLAGS] = { .type = NLA_U32 },
Johannes Berg53cabad2012-11-14 15:17:28 +0100359 [NL80211_ATTR_P2P_CTWINDOW] = { .type = NLA_U8 },
360 [NL80211_ATTR_P2P_OPPPS] = { .type = NLA_U8 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +0530361 [NL80211_ATTR_ACL_POLICY] = {. type = NLA_U32 },
362 [NL80211_ATTR_MAC_ADDRS] = { .type = NLA_NESTED },
Jouni Malinen9d62a982013-02-14 21:10:13 +0200363 [NL80211_ATTR_STA_CAPABILITY] = { .type = NLA_U16 },
364 [NL80211_ATTR_STA_EXT_CAPABILITY] = { .type = NLA_BINARY, },
Johannes Berg3713b4e2013-02-14 16:19:38 +0100365 [NL80211_ATTR_SPLIT_WIPHY_DUMP] = { .type = NLA_FLAG, },
Johannes Bergee2aca32013-02-21 17:36:01 +0100366 [NL80211_ATTR_DISABLE_VHT] = { .type = NLA_FLAG },
367 [NL80211_ATTR_VHT_CAPABILITY_MASK] = {
368 .len = NL80211_VHT_CAPABILITY_LEN,
369 },
Jouni Malinen355199e2013-02-27 17:14:27 +0200370 [NL80211_ATTR_MDID] = { .type = NLA_U16 },
371 [NL80211_ATTR_IE_RIC] = { .type = NLA_BINARY,
372 .len = IEEE80211_MAX_DATA_LEN },
Jouni Malinen5e4b6f52013-05-16 20:11:08 +0300373 [NL80211_ATTR_PEER_AID] = { .type = NLA_U16 },
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +0200374 [NL80211_ATTR_CH_SWITCH_COUNT] = { .type = NLA_U32 },
375 [NL80211_ATTR_CH_SWITCH_BLOCK_TX] = { .type = NLA_FLAG },
376 [NL80211_ATTR_CSA_IES] = { .type = NLA_NESTED },
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +0300377 [NL80211_ATTR_CSA_C_OFF_BEACON] = { .type = NLA_BINARY },
378 [NL80211_ATTR_CSA_C_OFF_PRESP] = { .type = NLA_BINARY },
Sunil Duttc01fc9a2013-10-09 20:45:21 +0530379 [NL80211_ATTR_STA_SUPPORTED_CHANNELS] = { .type = NLA_BINARY },
380 [NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES] = { .type = NLA_BINARY },
Simon Wunderlich5336fa82013-10-07 18:41:05 +0200381 [NL80211_ATTR_HANDLE_DFS] = { .type = NLA_FLAG },
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +0100382 [NL80211_ATTR_OPMODE_NOTIF] = { .type = NLA_U8 },
Johannes Bergad7e7182013-11-13 13:37:47 +0100383 [NL80211_ATTR_VENDOR_ID] = { .type = NLA_U32 },
384 [NL80211_ATTR_VENDOR_SUBCMD] = { .type = NLA_U32 },
385 [NL80211_ATTR_VENDOR_DATA] = { .type = NLA_BINARY },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -0800386 [NL80211_ATTR_QOS_MAP] = { .type = NLA_BINARY,
387 .len = IEEE80211_QOS_MAP_LEN_MAX },
Jouni Malinen1df4a512014-01-15 00:00:47 +0200388 [NL80211_ATTR_MAC_HINT] = { .len = ETH_ALEN },
389 [NL80211_ATTR_WIPHY_FREQ_HINT] = { .type = NLA_U32 },
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +0530390 [NL80211_ATTR_TDLS_PEER_CAPABILITY] = { .type = NLA_U32 },
Jukka Rissanen18e5ca62014-11-13 17:25:14 +0200391 [NL80211_ATTR_SOCKET_OWNER] = { .type = NLA_FLAG },
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +0300392 [NL80211_ATTR_CSA_C_OFFSETS_TX] = { .type = NLA_BINARY },
Assaf Kraussbab5ab72014-09-03 15:25:01 +0300393 [NL80211_ATTR_USE_RRM] = { .type = NLA_FLAG },
Johannes Berg960d01a2014-09-09 22:55:35 +0300394 [NL80211_ATTR_TSID] = { .type = NLA_U8 },
395 [NL80211_ATTR_USER_PRIO] = { .type = NLA_U8 },
396 [NL80211_ATTR_ADMITTED_TIME] = { .type = NLA_U16 },
Eliad Peller18998c32014-09-10 14:07:34 +0300397 [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
Johannes Bergad2b26a2014-06-12 21:39:05 +0200398 [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
Arik Nemtsov1bdd7162014-12-15 19:26:01 +0200399 [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
Vadim Kochan4b681c82015-01-12 16:34:05 +0200400 [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
Luciano Coelho9c748932015-01-16 16:04:09 +0200401 [NL80211_ATTR_SCHED_SCAN_DELAY] = { .type = NLA_U32 },
Ilan peer05050752015-03-04 00:32:06 -0500402 [NL80211_ATTR_REG_INDOOR] = { .type = NLA_FLAG },
Johannes Berg55682962007-09-20 13:09:35 -0400403};
404
Johannes Berge31b8212010-10-05 19:39:30 +0200405/* policy for the key attributes */
Alexey Dobriyanb54452b2010-02-18 08:14:31 +0000406static const struct nla_policy nl80211_key_policy[NL80211_KEY_MAX + 1] = {
Johannes Bergfffd0932009-07-08 14:22:54 +0200407 [NL80211_KEY_DATA] = { .type = NLA_BINARY, .len = WLAN_MAX_KEY_LEN },
Johannes Bergb9454e82009-07-08 13:29:08 +0200408 [NL80211_KEY_IDX] = { .type = NLA_U8 },
409 [NL80211_KEY_CIPHER] = { .type = NLA_U32 },
Jouni Malinen81962262011-11-02 23:36:31 +0200410 [NL80211_KEY_SEQ] = { .type = NLA_BINARY, .len = 16 },
Johannes Bergb9454e82009-07-08 13:29:08 +0200411 [NL80211_KEY_DEFAULT] = { .type = NLA_FLAG },
412 [NL80211_KEY_DEFAULT_MGMT] = { .type = NLA_FLAG },
Johannes Berge31b8212010-10-05 19:39:30 +0200413 [NL80211_KEY_TYPE] = { .type = NLA_U32 },
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100414 [NL80211_KEY_DEFAULT_TYPES] = { .type = NLA_NESTED },
415};
416
417/* policy for the key default flags */
418static const struct nla_policy
419nl80211_key_default_policy[NUM_NL80211_KEY_DEFAULT_TYPES] = {
420 [NL80211_KEY_DEFAULT_TYPE_UNICAST] = { .type = NLA_FLAG },
421 [NL80211_KEY_DEFAULT_TYPE_MULTICAST] = { .type = NLA_FLAG },
Johannes Bergb9454e82009-07-08 13:29:08 +0200422};
423
Johannes Bergff1b6e62011-05-04 15:37:28 +0200424/* policy for WoWLAN attributes */
425static const struct nla_policy
426nl80211_wowlan_policy[NUM_NL80211_WOWLAN_TRIG] = {
427 [NL80211_WOWLAN_TRIG_ANY] = { .type = NLA_FLAG },
428 [NL80211_WOWLAN_TRIG_DISCONNECT] = { .type = NLA_FLAG },
429 [NL80211_WOWLAN_TRIG_MAGIC_PKT] = { .type = NLA_FLAG },
430 [NL80211_WOWLAN_TRIG_PKT_PATTERN] = { .type = NLA_NESTED },
Johannes Berg77dbbb12011-07-13 10:48:55 +0200431 [NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE] = { .type = NLA_FLAG },
432 [NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST] = { .type = NLA_FLAG },
433 [NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE] = { .type = NLA_FLAG },
434 [NL80211_WOWLAN_TRIG_RFKILL_RELEASE] = { .type = NLA_FLAG },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100435 [NL80211_WOWLAN_TRIG_TCP_CONNECTION] = { .type = NLA_NESTED },
Luciano Coelho8cd4d452014-09-17 11:55:28 +0300436 [NL80211_WOWLAN_TRIG_NET_DETECT] = { .type = NLA_NESTED },
Johannes Berg2a0e0472013-01-23 22:57:40 +0100437};
438
439static const struct nla_policy
440nl80211_wowlan_tcp_policy[NUM_NL80211_WOWLAN_TCP] = {
441 [NL80211_WOWLAN_TCP_SRC_IPV4] = { .type = NLA_U32 },
442 [NL80211_WOWLAN_TCP_DST_IPV4] = { .type = NLA_U32 },
443 [NL80211_WOWLAN_TCP_DST_MAC] = { .len = ETH_ALEN },
444 [NL80211_WOWLAN_TCP_SRC_PORT] = { .type = NLA_U16 },
445 [NL80211_WOWLAN_TCP_DST_PORT] = { .type = NLA_U16 },
446 [NL80211_WOWLAN_TCP_DATA_PAYLOAD] = { .len = 1 },
447 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ] = {
448 .len = sizeof(struct nl80211_wowlan_tcp_data_seq)
449 },
450 [NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN] = {
451 .len = sizeof(struct nl80211_wowlan_tcp_data_token)
452 },
453 [NL80211_WOWLAN_TCP_DATA_INTERVAL] = { .type = NLA_U32 },
454 [NL80211_WOWLAN_TCP_WAKE_PAYLOAD] = { .len = 1 },
455 [NL80211_WOWLAN_TCP_WAKE_MASK] = { .len = 1 },
Johannes Bergff1b6e62011-05-04 15:37:28 +0200456};
457
Amitkumar Karwarbe29b992013-06-28 11:51:26 -0700458/* policy for coalesce rule attributes */
459static const struct nla_policy
460nl80211_coalesce_policy[NUM_NL80211_ATTR_COALESCE_RULE] = {
461 [NL80211_ATTR_COALESCE_RULE_DELAY] = { .type = NLA_U32 },
462 [NL80211_ATTR_COALESCE_RULE_CONDITION] = { .type = NLA_U32 },
463 [NL80211_ATTR_COALESCE_RULE_PKT_PATTERN] = { .type = NLA_NESTED },
464};
465
Johannes Berge5497d72011-07-05 16:35:40 +0200466/* policy for GTK rekey offload attributes */
467static const struct nla_policy
468nl80211_rekey_policy[NUM_NL80211_REKEY_DATA] = {
469 [NL80211_REKEY_DATA_KEK] = { .len = NL80211_KEK_LEN },
470 [NL80211_REKEY_DATA_KCK] = { .len = NL80211_KCK_LEN },
471 [NL80211_REKEY_DATA_REPLAY_CTR] = { .len = NL80211_REPLAY_CTR_LEN },
472};
473
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300474static const struct nla_policy
475nl80211_match_policy[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1] = {
Johannes Berg4a4ab0d2012-06-13 11:17:11 +0200476 [NL80211_SCHED_SCAN_MATCH_ATTR_SSID] = { .type = NLA_BINARY,
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300477 .len = IEEE80211_MAX_SSID_LEN },
Thomas Pedersen88e920b2012-06-21 11:09:54 -0700478 [NL80211_SCHED_SCAN_MATCH_ATTR_RSSI] = { .type = NLA_U32 },
Luciano Coelhoa1f1c212011-08-31 16:01:48 +0300479};
480
Johannes Berg97990a02013-04-19 01:02:55 +0200481static int nl80211_prepare_wdev_dump(struct sk_buff *skb,
482 struct netlink_callback *cb,
483 struct cfg80211_registered_device **rdev,
484 struct wireless_dev **wdev)
Holger Schuriga0438972009-11-11 11:30:02 +0100485{
Johannes Berg67748892010-10-04 21:14:06 +0200486 int err;
487
Johannes Berg67748892010-10-04 21:14:06 +0200488 rtnl_lock();
489
Johannes Berg97990a02013-04-19 01:02:55 +0200490 if (!cb->args[0]) {
491 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
492 nl80211_fam.attrbuf, nl80211_fam.maxattr,
493 nl80211_policy);
494 if (err)
495 goto out_unlock;
496
497 *wdev = __cfg80211_wdev_from_attrs(sock_net(skb->sk),
498 nl80211_fam.attrbuf);
499 if (IS_ERR(*wdev)) {
500 err = PTR_ERR(*wdev);
501 goto out_unlock;
502 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800503 *rdev = wiphy_to_rdev((*wdev)->wiphy);
Johannes Bergc319d502013-07-30 22:34:28 +0200504 /* 0 is the first index - add 1 to parse only once */
505 cb->args[0] = (*rdev)->wiphy_idx + 1;
Johannes Berg97990a02013-04-19 01:02:55 +0200506 cb->args[1] = (*wdev)->identifier;
507 } else {
Johannes Bergc319d502013-07-30 22:34:28 +0200508 /* subtract the 1 again here */
509 struct wiphy *wiphy = wiphy_idx_to_wiphy(cb->args[0] - 1);
Johannes Berg97990a02013-04-19 01:02:55 +0200510 struct wireless_dev *tmp;
511
512 if (!wiphy) {
513 err = -ENODEV;
514 goto out_unlock;
515 }
Zhao, Gangf26cbf42014-04-21 12:53:03 +0800516 *rdev = wiphy_to_rdev(wiphy);
Johannes Berg97990a02013-04-19 01:02:55 +0200517 *wdev = NULL;
518
Johannes Berg97990a02013-04-19 01:02:55 +0200519 list_for_each_entry(tmp, &(*rdev)->wdev_list, list) {
520 if (tmp->identifier == cb->args[1]) {
521 *wdev = tmp;
522 break;
523 }
524 }
Johannes Berg97990a02013-04-19 01:02:55 +0200525
526 if (!*wdev) {
527 err = -ENODEV;
528 goto out_unlock;
529 }
Johannes Berg67748892010-10-04 21:14:06 +0200530 }
531
Johannes Berg67748892010-10-04 21:14:06 +0200532 return 0;
Johannes Berg97990a02013-04-19 01:02:55 +0200533 out_unlock:
Johannes Berg67748892010-10-04 21:14:06 +0200534 rtnl_unlock();
535 return err;
536}
537
Johannes Berg97990a02013-04-19 01:02:55 +0200538static void nl80211_finish_wdev_dump(struct cfg80211_registered_device *rdev)
Johannes Berg67748892010-10-04 21:14:06 +0200539{
Johannes Berg67748892010-10-04 21:14:06 +0200540 rtnl_unlock();
541}
542
Johannes Bergf4a11bb2009-03-27 12:40:28 +0100543/* IE validation */
544static bool is_valid_ie_attr(const struct nlattr *attr)
545{
546 const u8 *pos;
547 int len;
548
549 if (!attr)
550 return true;
551
552 pos = nla_data(attr);
553 len = nla_len(attr);
554
555 while (len) {
556 u8 elemlen;
557
558 if (len < 2)
559 return false;
560 len -= 2;
561
562 elemlen = pos[1];
563 if (elemlen > len)
564 return false;
565
566 len -= elemlen;
567 pos += 2 + elemlen;
568 }
569
570 return true;
571}
572
Johannes Berg55682962007-09-20 13:09:35 -0400573/* message building helper */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000574static inline void *nl80211hdr_put(struct sk_buff *skb, u32 portid, u32 seq,
Johannes Berg55682962007-09-20 13:09:35 -0400575 int flags, u8 cmd)
576{
577 /* since there is no private header just add the generic one */
Eric W. Biederman15e47302012-09-07 20:12:54 +0000578 return genlmsg_put(skb, portid, seq, &nl80211_fam, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -0400579}
580
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400581static int nl80211_msg_put_channel(struct sk_buff *msg,
Johannes Bergcdc89b92013-02-18 23:54:36 +0100582 struct ieee80211_channel *chan,
583 bool large)
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400584{
Rostislav Lisovyea077c12014-04-15 14:37:55 +0200585 /* Some channels must be completely excluded from the
586 * list to protect old user-space tools from breaking
587 */
588 if (!large && chan->flags &
589 (IEEE80211_CHAN_NO_10MHZ | IEEE80211_CHAN_NO_20MHZ))
590 return 0;
591
David S. Miller9360ffd2012-03-29 04:41:26 -0400592 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_FREQ,
593 chan->center_freq))
594 goto nla_put_failure;
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400595
David S. Miller9360ffd2012-03-29 04:41:26 -0400596 if ((chan->flags & IEEE80211_CHAN_DISABLED) &&
597 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_DISABLED))
598 goto nla_put_failure;
Luis R. Rodriguez8fe02e12013-10-21 19:22:25 +0200599 if (chan->flags & IEEE80211_CHAN_NO_IR) {
600 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_IR))
601 goto nla_put_failure;
602 if (nla_put_flag(msg, __NL80211_FREQUENCY_ATTR_NO_IBSS))
603 goto nla_put_failure;
604 }
Johannes Bergcdc89b92013-02-18 23:54:36 +0100605 if (chan->flags & IEEE80211_CHAN_RADAR) {
606 if (nla_put_flag(msg, NL80211_FREQUENCY_ATTR_RADAR))
607 goto nla_put_failure;
608 if (large) {
609 u32 time;
610
611 time = elapsed_jiffies_msecs(chan->dfs_state_entered);
612
613 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_STATE,
614 chan->dfs_state))
615 goto nla_put_failure;
616 if (nla_put_u32(msg, NL80211_FREQUENCY_ATTR_DFS_TIME,
617 time))
618 goto nla_put_failure;
Janusz Dziedzic089027e2014-02-21 19:46:12 +0100619 if (nla_put_u32(msg,
620 NL80211_FREQUENCY_ATTR_DFS_CAC_TIME,
621 chan->dfs_cac_ms))
622 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +0100623 }
624 }
Luis R. Rodriguez5dab3b82009-04-02 14:08:08 -0400625
Johannes Bergfe1abaf2013-02-27 15:39:45 +0100626 if (large) {
627 if ((chan->flags & IEEE80211_CHAN_NO_HT40MINUS) &&
628 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_MINUS))
629 goto nla_put_failure;
630 if ((chan->flags & IEEE80211_CHAN_NO_HT40PLUS) &&
631 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_HT40_PLUS))
632 goto nla_put_failure;
633 if ((chan->flags & IEEE80211_CHAN_NO_80MHZ) &&
634 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_80MHZ))
635 goto nla_put_failure;
636 if ((chan->flags & IEEE80211_CHAN_NO_160MHZ) &&
637 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_NO_160MHZ))
638 goto nla_put_failure;
David Spinadel570dbde2014-02-23 09:12:59 +0200639 if ((chan->flags & IEEE80211_CHAN_INDOOR_ONLY) &&
640 nla_put_flag(msg, NL80211_FREQUENCY_ATTR_INDOOR_ONLY))
641 goto nla_put_failure;
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;
Michal Kazior9189ee32015-08-03 10:55:24 +02002324 return result;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002325 }
2326 }
Ying Xue7f2b8562014-01-15 10:23:45 +08002327 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002328}
2329
Johannes Berg71bbc992012-06-15 15:30:18 +02002330static inline u64 wdev_id(struct wireless_dev *wdev)
2331{
2332 return (u64)wdev->identifier |
Zhao, Gangf26cbf42014-04-21 12:53:03 +08002333 ((u64)wiphy_to_rdev(wdev->wiphy)->wiphy_idx << 32);
Johannes Berg71bbc992012-06-15 15:30:18 +02002334}
Johannes Berg55682962007-09-20 13:09:35 -04002335
Johannes Berg683b6d32012-11-08 21:25:48 +01002336static int nl80211_send_chandef(struct sk_buff *msg,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01002337 const struct cfg80211_chan_def *chandef)
Johannes Berg683b6d32012-11-08 21:25:48 +01002338{
Johannes Berg601555c2014-11-27 17:26:56 +01002339 if (WARN_ON(!cfg80211_chandef_valid(chandef)))
2340 return -EINVAL;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002341
Johannes Berg683b6d32012-11-08 21:25:48 +01002342 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
2343 chandef->chan->center_freq))
2344 return -ENOBUFS;
Johannes Berg3d9d1d62012-11-08 23:14:50 +01002345 switch (chandef->width) {
2346 case NL80211_CHAN_WIDTH_20_NOHT:
2347 case NL80211_CHAN_WIDTH_20:
2348 case NL80211_CHAN_WIDTH_40:
2349 if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
2350 cfg80211_get_chandef_type(chandef)))
2351 return -ENOBUFS;
2352 break;
2353 default:
2354 break;
2355 }
2356 if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, chandef->width))
2357 return -ENOBUFS;
2358 if (nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, chandef->center_freq1))
2359 return -ENOBUFS;
2360 if (chandef->center_freq2 &&
2361 nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, chandef->center_freq2))
Johannes Berg683b6d32012-11-08 21:25:48 +01002362 return -ENOBUFS;
2363 return 0;
2364}
2365
Eric W. Biederman15e47302012-09-07 20:12:54 +00002366static int nl80211_send_iface(struct sk_buff *msg, u32 portid, u32 seq, int flags,
Johannes Bergd7264052009-04-19 16:23:20 +02002367 struct cfg80211_registered_device *rdev,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002368 struct wireless_dev *wdev, bool removal)
Johannes Berg55682962007-09-20 13:09:35 -04002369{
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002370 struct net_device *dev = wdev->netdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002371 u8 cmd = NL80211_CMD_NEW_INTERFACE;
Johannes Berg55682962007-09-20 13:09:35 -04002372 void *hdr;
2373
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002374 if (removal)
2375 cmd = NL80211_CMD_DEL_INTERFACE;
2376
2377 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg55682962007-09-20 13:09:35 -04002378 if (!hdr)
2379 return -1;
2380
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002381 if (dev &&
2382 (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002383 nla_put_string(msg, NL80211_ATTR_IFNAME, dev->name)))
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002384 goto nla_put_failure;
2385
2386 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
2387 nla_put_u32(msg, NL80211_ATTR_IFTYPE, wdev->iftype) ||
Johannes Berg71bbc992012-06-15 15:30:18 +02002388 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
Johannes Berg98104fde2012-06-16 00:19:54 +02002389 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, wdev_address(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04002390 nla_put_u32(msg, NL80211_ATTR_GENERATION,
2391 rdev->devlist_generation ^
2392 (cfg80211_rdev_list_generation << 2)))
2393 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02002394
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002395 if (rdev->ops->get_channel) {
Johannes Berg683b6d32012-11-08 21:25:48 +01002396 int ret;
2397 struct cfg80211_chan_def chandef;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02002398
Johannes Berg683b6d32012-11-08 21:25:48 +01002399 ret = rdev_get_channel(rdev, wdev, &chandef);
2400 if (ret == 0) {
2401 if (nl80211_send_chandef(msg, &chandef))
2402 goto nla_put_failure;
2403 }
Pontus Fuchsd91df0e2012-04-03 16:39:58 +02002404 }
2405
Antonio Quartullib84e7a02012-11-07 12:52:20 +01002406 if (wdev->ssid_len) {
2407 if (nla_put(msg, NL80211_ATTR_SSID, wdev->ssid_len, wdev->ssid))
2408 goto nla_put_failure;
2409 }
2410
Johannes Berg053c0952015-01-16 22:09:00 +01002411 genlmsg_end(msg, hdr);
2412 return 0;
Johannes Berg55682962007-09-20 13:09:35 -04002413
2414 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07002415 genlmsg_cancel(msg, hdr);
2416 return -EMSGSIZE;
Johannes Berg55682962007-09-20 13:09:35 -04002417}
2418
2419static int nl80211_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
2420{
2421 int wp_idx = 0;
2422 int if_idx = 0;
2423 int wp_start = cb->args[0];
2424 int if_start = cb->args[1];
Johannes Bergf5ea9122009-08-07 16:17:38 +02002425 struct cfg80211_registered_device *rdev;
Johannes Berg55682962007-09-20 13:09:35 -04002426 struct wireless_dev *wdev;
2427
Johannes Berg5fe231e2013-05-08 21:45:15 +02002428 rtnl_lock();
Johannes Bergf5ea9122009-08-07 16:17:38 +02002429 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
2430 if (!net_eq(wiphy_net(&rdev->wiphy), sock_net(skb->sk)))
Johannes Berg463d0182009-07-14 00:33:35 +02002431 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002432 if (wp_idx < wp_start) {
2433 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002434 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002435 }
Johannes Berg55682962007-09-20 13:09:35 -04002436 if_idx = 0;
2437
Johannes Berg89a54e42012-06-15 14:33:17 +02002438 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002439 if (if_idx < if_start) {
2440 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002441 continue;
Johannes Bergbba95fe2008-07-29 13:22:51 +02002442 }
Eric W. Biederman15e47302012-09-07 20:12:54 +00002443 if (nl80211_send_iface(skb, NETLINK_CB(cb->skb).portid,
Johannes Berg55682962007-09-20 13:09:35 -04002444 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002445 rdev, wdev, false) < 0) {
Johannes Bergbba95fe2008-07-29 13:22:51 +02002446 goto out;
2447 }
2448 if_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002449 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002450
2451 wp_idx++;
Johannes Berg55682962007-09-20 13:09:35 -04002452 }
Johannes Bergbba95fe2008-07-29 13:22:51 +02002453 out:
Johannes Berg5fe231e2013-05-08 21:45:15 +02002454 rtnl_unlock();
Johannes Berg55682962007-09-20 13:09:35 -04002455
2456 cb->args[0] = wp_idx;
2457 cb->args[1] = if_idx;
2458
2459 return skb->len;
2460}
2461
2462static int nl80211_get_interface(struct sk_buff *skb, struct genl_info *info)
2463{
2464 struct sk_buff *msg;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08002465 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg72fb2ab2012-06-15 17:52:47 +02002466 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg55682962007-09-20 13:09:35 -04002467
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002468 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -04002469 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02002470 return -ENOMEM;
Johannes Berg55682962007-09-20 13:09:35 -04002471
Eric W. Biederman15e47302012-09-07 20:12:54 +00002472 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002473 rdev, wdev, false) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02002474 nlmsg_free(msg);
2475 return -ENOBUFS;
2476 }
Johannes Berg55682962007-09-20 13:09:35 -04002477
Johannes Berg134e6372009-07-10 09:51:34 +00002478 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002479}
2480
Michael Wu66f7ac52008-01-31 19:48:22 +01002481static const struct nla_policy mntr_flags_policy[NL80211_MNTR_FLAG_MAX + 1] = {
2482 [NL80211_MNTR_FLAG_FCSFAIL] = { .type = NLA_FLAG },
2483 [NL80211_MNTR_FLAG_PLCPFAIL] = { .type = NLA_FLAG },
2484 [NL80211_MNTR_FLAG_CONTROL] = { .type = NLA_FLAG },
2485 [NL80211_MNTR_FLAG_OTHER_BSS] = { .type = NLA_FLAG },
2486 [NL80211_MNTR_FLAG_COOK_FRAMES] = { .type = NLA_FLAG },
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002487 [NL80211_MNTR_FLAG_ACTIVE] = { .type = NLA_FLAG },
Michael Wu66f7ac52008-01-31 19:48:22 +01002488};
2489
2490static int parse_monitor_flags(struct nlattr *nla, u32 *mntrflags)
2491{
2492 struct nlattr *flags[NL80211_MNTR_FLAG_MAX + 1];
2493 int flag;
2494
2495 *mntrflags = 0;
2496
2497 if (!nla)
2498 return -EINVAL;
2499
2500 if (nla_parse_nested(flags, NL80211_MNTR_FLAG_MAX,
2501 nla, mntr_flags_policy))
2502 return -EINVAL;
2503
2504 for (flag = 1; flag <= NL80211_MNTR_FLAG_MAX; flag++)
2505 if (flags[flag])
2506 *mntrflags |= (1<<flag);
2507
2508 return 0;
2509}
2510
Johannes Berg9bc383d2009-11-19 11:55:19 +01002511static int nl80211_valid_4addr(struct cfg80211_registered_device *rdev,
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002512 struct net_device *netdev, u8 use_4addr,
2513 enum nl80211_iftype iftype)
Johannes Berg9bc383d2009-11-19 11:55:19 +01002514{
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002515 if (!use_4addr) {
Jiri Pirkof350a0a82010-06-15 06:50:45 +00002516 if (netdev && (netdev->priv_flags & IFF_BRIDGE_PORT))
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002517 return -EBUSY;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002518 return 0;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002519 }
Johannes Berg9bc383d2009-11-19 11:55:19 +01002520
2521 switch (iftype) {
2522 case NL80211_IFTYPE_AP_VLAN:
2523 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_AP)
2524 return 0;
2525 break;
2526 case NL80211_IFTYPE_STATION:
2527 if (rdev->wiphy.flags & WIPHY_FLAG_4ADDR_STATION)
2528 return 0;
2529 break;
2530 default:
2531 break;
2532 }
2533
2534 return -EOPNOTSUPP;
2535}
2536
Johannes Berg55682962007-09-20 13:09:35 -04002537static int nl80211_set_interface(struct sk_buff *skb, struct genl_info *info)
2538{
Johannes Berg4c476992010-10-04 21:36:35 +02002539 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002540 struct vif_params params;
Johannes Berge36d56b2009-06-09 21:04:43 +02002541 int err;
Johannes Berg04a773a2009-04-19 21:24:32 +02002542 enum nl80211_iftype otype, ntype;
Johannes Berg4c476992010-10-04 21:36:35 +02002543 struct net_device *dev = info->user_ptr[1];
Johannes Berg92ffe052008-09-16 20:39:36 +02002544 u32 _flags, *flags = NULL;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002545 bool change = false;
Johannes Berg55682962007-09-20 13:09:35 -04002546
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002547 memset(&params, 0, sizeof(params));
2548
Johannes Berg04a773a2009-04-19 21:24:32 +02002549 otype = ntype = dev->ieee80211_ptr->iftype;
Johannes Berg55682962007-09-20 13:09:35 -04002550
Johannes Berg723b0382008-09-16 20:22:09 +02002551 if (info->attrs[NL80211_ATTR_IFTYPE]) {
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002552 ntype = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
Johannes Berg04a773a2009-04-19 21:24:32 +02002553 if (otype != ntype)
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002554 change = true;
Johannes Berg4c476992010-10-04 21:36:35 +02002555 if (ntype > NL80211_IFTYPE_MAX)
2556 return -EINVAL;
Johannes Berg723b0382008-09-16 20:22:09 +02002557 }
2558
Johannes Berg92ffe052008-09-16 20:39:36 +02002559 if (info->attrs[NL80211_ATTR_MESH_ID]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01002560 struct wireless_dev *wdev = dev->ieee80211_ptr;
2561
Johannes Berg4c476992010-10-04 21:36:35 +02002562 if (ntype != NL80211_IFTYPE_MESH_POINT)
2563 return -EINVAL;
Johannes Berg29cbe682010-12-03 09:20:44 +01002564 if (netif_running(dev))
2565 return -EBUSY;
2566
2567 wdev_lock(wdev);
2568 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2569 IEEE80211_MAX_MESH_ID_LEN);
2570 wdev->mesh_id_up_len =
2571 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2572 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2573 wdev->mesh_id_up_len);
2574 wdev_unlock(wdev);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002575 }
2576
Felix Fietkau8b787642009-11-10 18:53:10 +01002577 if (info->attrs[NL80211_ATTR_4ADDR]) {
2578 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
2579 change = true;
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002580 err = nl80211_valid_4addr(rdev, dev, params.use_4addr, ntype);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002581 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002582 return err;
Felix Fietkau8b787642009-11-10 18:53:10 +01002583 } else {
2584 params.use_4addr = -1;
2585 }
2586
Johannes Berg92ffe052008-09-16 20:39:36 +02002587 if (info->attrs[NL80211_ATTR_MNTR_FLAGS]) {
Johannes Berg4c476992010-10-04 21:36:35 +02002588 if (ntype != NL80211_IFTYPE_MONITOR)
2589 return -EINVAL;
Johannes Berg92ffe052008-09-16 20:39:36 +02002590 err = parse_monitor_flags(info->attrs[NL80211_ATTR_MNTR_FLAGS],
2591 &_flags);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002592 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002593 return err;
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002594
2595 flags = &_flags;
2596 change = true;
Johannes Berg92ffe052008-09-16 20:39:36 +02002597 }
Johannes Berg3b858752009-03-12 09:55:09 +01002598
Luciano Coelho18003292013-08-29 13:26:57 +03002599 if (flags && (*flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002600 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2601 return -EOPNOTSUPP;
2602
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002603 if (change)
Johannes Berg3d54d252009-08-21 14:51:05 +02002604 err = cfg80211_change_iface(rdev, dev, ntype, flags, &params);
Johannes Bergac7f9cf2009-03-21 17:07:59 +01002605 else
2606 err = 0;
Johannes Berg60719ff2008-09-16 14:55:09 +02002607
Johannes Berg9bc383d2009-11-19 11:55:19 +01002608 if (!err && params.use_4addr != -1)
2609 dev->ieee80211_ptr->use_4addr = params.use_4addr;
2610
Johannes Berg55682962007-09-20 13:09:35 -04002611 return err;
2612}
2613
2614static int nl80211_new_interface(struct sk_buff *skb, struct genl_info *info)
2615{
Johannes Berg4c476992010-10-04 21:36:35 +02002616 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002617 struct vif_params params;
Johannes Berg84efbb82012-06-16 00:00:26 +02002618 struct wireless_dev *wdev;
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002619 struct sk_buff *msg, *event;
Johannes Berg55682962007-09-20 13:09:35 -04002620 int err;
2621 enum nl80211_iftype type = NL80211_IFTYPE_UNSPECIFIED;
Michael Wu66f7ac52008-01-31 19:48:22 +01002622 u32 flags;
Johannes Berg55682962007-09-20 13:09:35 -04002623
Johannes Berg78f22b62014-03-24 17:57:27 +01002624 /* to avoid failing a new interface creation due to pending removal */
2625 cfg80211_destroy_ifaces(rdev);
2626
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002627 memset(&params, 0, sizeof(params));
2628
Johannes Berg55682962007-09-20 13:09:35 -04002629 if (!info->attrs[NL80211_ATTR_IFNAME])
2630 return -EINVAL;
2631
2632 if (info->attrs[NL80211_ATTR_IFTYPE]) {
2633 type = nla_get_u32(info->attrs[NL80211_ATTR_IFTYPE]);
2634 if (type > NL80211_IFTYPE_MAX)
2635 return -EINVAL;
2636 }
2637
Johannes Berg79c97e92009-07-07 03:56:12 +02002638 if (!rdev->ops->add_virtual_intf ||
Johannes Berg4c476992010-10-04 21:36:35 +02002639 !(rdev->wiphy.interface_modes & (1 << type)))
2640 return -EOPNOTSUPP;
Johannes Berg55682962007-09-20 13:09:35 -04002641
Ben Greeare8f479b2014-10-22 12:23:05 -07002642 if ((type == NL80211_IFTYPE_P2P_DEVICE ||
2643 rdev->wiphy.features & NL80211_FEATURE_MAC_ON_CREATE) &&
2644 info->attrs[NL80211_ATTR_MAC]) {
Arend van Spriel1c18f142013-01-08 10:17:27 +01002645 nla_memcpy(params.macaddr, info->attrs[NL80211_ATTR_MAC],
2646 ETH_ALEN);
2647 if (!is_valid_ether_addr(params.macaddr))
2648 return -EADDRNOTAVAIL;
2649 }
2650
Johannes Berg9bc383d2009-11-19 11:55:19 +01002651 if (info->attrs[NL80211_ATTR_4ADDR]) {
Felix Fietkau8b787642009-11-10 18:53:10 +01002652 params.use_4addr = !!nla_get_u8(info->attrs[NL80211_ATTR_4ADDR]);
Johannes Bergad4bb6f2009-11-19 00:56:30 +01002653 err = nl80211_valid_4addr(rdev, NULL, params.use_4addr, type);
Johannes Berg9bc383d2009-11-19 11:55:19 +01002654 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02002655 return err;
Johannes Berg9bc383d2009-11-19 11:55:19 +01002656 }
Felix Fietkau8b787642009-11-10 18:53:10 +01002657
Michael Wu66f7ac52008-01-31 19:48:22 +01002658 err = parse_monitor_flags(type == NL80211_IFTYPE_MONITOR ?
2659 info->attrs[NL80211_ATTR_MNTR_FLAGS] : NULL,
2660 &flags);
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002661
Luciano Coelho18003292013-08-29 13:26:57 +03002662 if (!err && (flags & MONITOR_FLAG_ACTIVE) &&
Felix Fietkaue057d3c2013-05-28 13:01:52 +02002663 !(rdev->wiphy.features & NL80211_FEATURE_ACTIVE_MONITOR))
2664 return -EOPNOTSUPP;
2665
Johannes Berga18c7192015-02-24 10:56:42 +01002666 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2667 if (!msg)
2668 return -ENOMEM;
2669
Hila Gonene35e4d22012-06-27 17:19:42 +03002670 wdev = rdev_add_virtual_intf(rdev,
2671 nla_data(info->attrs[NL80211_ATTR_IFNAME]),
Tom Gundersen6bab2e192015-03-18 11:13:39 +01002672 NET_NAME_USER, type, err ? NULL : &flags,
2673 &params);
Rafał Miłeckid687cbb2014-11-14 18:43:28 +01002674 if (WARN_ON(!wdev)) {
2675 nlmsg_free(msg);
2676 return -EPROTO;
2677 } else if (IS_ERR(wdev)) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002678 nlmsg_free(msg);
Johannes Berg84efbb82012-06-16 00:00:26 +02002679 return PTR_ERR(wdev);
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002680 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01002681
Jukka Rissanen18e5ca62014-11-13 17:25:14 +02002682 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
Johannes Berg78f22b62014-03-24 17:57:27 +01002683 wdev->owner_nlportid = info->snd_portid;
2684
Johannes Berg98104fde2012-06-16 00:19:54 +02002685 switch (type) {
2686 case NL80211_IFTYPE_MESH_POINT:
2687 if (!info->attrs[NL80211_ATTR_MESH_ID])
2688 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002689 wdev_lock(wdev);
2690 BUILD_BUG_ON(IEEE80211_MAX_SSID_LEN !=
2691 IEEE80211_MAX_MESH_ID_LEN);
2692 wdev->mesh_id_up_len =
2693 nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
2694 memcpy(wdev->ssid, nla_data(info->attrs[NL80211_ATTR_MESH_ID]),
2695 wdev->mesh_id_up_len);
2696 wdev_unlock(wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02002697 break;
2698 case NL80211_IFTYPE_P2P_DEVICE:
2699 /*
2700 * P2P Device doesn't have a netdev, so doesn't go
2701 * through the netdev notifier and must be added here
2702 */
2703 mutex_init(&wdev->mtx);
2704 INIT_LIST_HEAD(&wdev->event_list);
2705 spin_lock_init(&wdev->event_lock);
2706 INIT_LIST_HEAD(&wdev->mgmt_registrations);
2707 spin_lock_init(&wdev->mgmt_registrations_lock);
2708
Johannes Berg98104fde2012-06-16 00:19:54 +02002709 wdev->identifier = ++rdev->wdev_id;
2710 list_add_rcu(&wdev->list, &rdev->wdev_list);
2711 rdev->devlist_generation++;
Johannes Berg98104fde2012-06-16 00:19:54 +02002712 break;
2713 default:
2714 break;
Johannes Berg29cbe682010-12-03 09:20:44 +01002715 }
2716
Eric W. Biederman15e47302012-09-07 20:12:54 +00002717 if (nl80211_send_iface(msg, info->snd_portid, info->snd_seq, 0,
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002718 rdev, wdev, false) < 0) {
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002719 nlmsg_free(msg);
2720 return -ENOBUFS;
2721 }
2722
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002723 event = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2724 if (event) {
2725 if (nl80211_send_iface(event, 0, 0, 0,
2726 rdev, wdev, false) < 0) {
2727 nlmsg_free(event);
2728 goto out;
2729 }
2730
2731 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2732 event, 0, NL80211_MCGRP_CONFIG,
2733 GFP_KERNEL);
2734 }
2735
2736out:
Johannes Berg1c90f9d2012-06-16 00:05:37 +02002737 return genlmsg_reply(msg, info);
Johannes Berg55682962007-09-20 13:09:35 -04002738}
2739
2740static int nl80211_del_interface(struct sk_buff *skb, struct genl_info *info)
2741{
Johannes Berg4c476992010-10-04 21:36:35 +02002742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg84efbb82012-06-16 00:00:26 +02002743 struct wireless_dev *wdev = info->user_ptr[1];
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002744 struct sk_buff *msg;
2745 int status;
Johannes Berg55682962007-09-20 13:09:35 -04002746
Johannes Berg4c476992010-10-04 21:36:35 +02002747 if (!rdev->ops->del_virtual_intf)
2748 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01002749
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002750 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
2751 if (msg && nl80211_send_iface(msg, 0, 0, 0, rdev, wdev, true) < 0) {
2752 nlmsg_free(msg);
2753 msg = NULL;
2754 }
2755
Johannes Berg84efbb82012-06-16 00:00:26 +02002756 /*
2757 * If we remove a wireless device without a netdev then clear
2758 * user_ptr[1] so that nl80211_post_doit won't dereference it
2759 * to check if it needs to do dev_put(). Otherwise it crashes
2760 * since the wdev has been freed, unlike with a netdev where
2761 * we need the dev_put() for the netdev to really be freed.
2762 */
2763 if (!wdev->netdev)
2764 info->user_ptr[1] = NULL;
2765
Tomasz Bursztyka8f894be2014-11-12 16:26:45 +02002766 status = rdev_del_virtual_intf(rdev, wdev);
2767 if (status >= 0 && msg)
2768 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy),
2769 msg, 0, NL80211_MCGRP_CONFIG,
2770 GFP_KERNEL);
2771 else
2772 nlmsg_free(msg);
2773
2774 return status;
Johannes Berg55682962007-09-20 13:09:35 -04002775}
2776
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002777static int nl80211_set_noack_map(struct sk_buff *skb, struct genl_info *info)
2778{
2779 struct cfg80211_registered_device *rdev = info->user_ptr[0];
2780 struct net_device *dev = info->user_ptr[1];
2781 u16 noack_map;
2782
2783 if (!info->attrs[NL80211_ATTR_NOACK_MAP])
2784 return -EINVAL;
2785
2786 if (!rdev->ops->set_noack_map)
2787 return -EOPNOTSUPP;
2788
2789 noack_map = nla_get_u16(info->attrs[NL80211_ATTR_NOACK_MAP]);
2790
Hila Gonene35e4d22012-06-27 17:19:42 +03002791 return rdev_set_noack_map(rdev, dev, noack_map);
Simon Wunderlich1d9d9212011-11-18 14:20:43 +01002792}
2793
Johannes Berg41ade002007-12-19 02:03:29 +01002794struct get_key_cookie {
2795 struct sk_buff *msg;
2796 int error;
Johannes Bergb9454e82009-07-08 13:29:08 +02002797 int idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002798};
2799
2800static void get_key_callback(void *c, struct key_params *params)
2801{
Johannes Bergb9454e82009-07-08 13:29:08 +02002802 struct nlattr *key;
Johannes Berg41ade002007-12-19 02:03:29 +01002803 struct get_key_cookie *cookie = c;
2804
David S. Miller9360ffd2012-03-29 04:41:26 -04002805 if ((params->key &&
2806 nla_put(cookie->msg, NL80211_ATTR_KEY_DATA,
2807 params->key_len, params->key)) ||
2808 (params->seq &&
2809 nla_put(cookie->msg, NL80211_ATTR_KEY_SEQ,
2810 params->seq_len, params->seq)) ||
2811 (params->cipher &&
2812 nla_put_u32(cookie->msg, NL80211_ATTR_KEY_CIPHER,
2813 params->cipher)))
2814 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002815
Johannes Bergb9454e82009-07-08 13:29:08 +02002816 key = nla_nest_start(cookie->msg, NL80211_ATTR_KEY);
2817 if (!key)
2818 goto nla_put_failure;
2819
David S. Miller9360ffd2012-03-29 04:41:26 -04002820 if ((params->key &&
2821 nla_put(cookie->msg, NL80211_KEY_DATA,
2822 params->key_len, params->key)) ||
2823 (params->seq &&
2824 nla_put(cookie->msg, NL80211_KEY_SEQ,
2825 params->seq_len, params->seq)) ||
2826 (params->cipher &&
2827 nla_put_u32(cookie->msg, NL80211_KEY_CIPHER,
2828 params->cipher)))
2829 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002830
David S. Miller9360ffd2012-03-29 04:41:26 -04002831 if (nla_put_u8(cookie->msg, NL80211_ATTR_KEY_IDX, cookie->idx))
2832 goto nla_put_failure;
Johannes Bergb9454e82009-07-08 13:29:08 +02002833
2834 nla_nest_end(cookie->msg, key);
2835
Johannes Berg41ade002007-12-19 02:03:29 +01002836 return;
2837 nla_put_failure:
2838 cookie->error = 1;
2839}
2840
2841static int nl80211_get_key(struct sk_buff *skb, struct genl_info *info)
2842{
Johannes Berg4c476992010-10-04 21:36:35 +02002843 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01002844 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002845 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002846 u8 key_idx = 0;
Johannes Berge31b8212010-10-05 19:39:30 +02002847 const u8 *mac_addr = NULL;
2848 bool pairwise;
Johannes Berg41ade002007-12-19 02:03:29 +01002849 struct get_key_cookie cookie = {
2850 .error = 0,
2851 };
2852 void *hdr;
2853 struct sk_buff *msg;
2854
2855 if (info->attrs[NL80211_ATTR_KEY_IDX])
2856 key_idx = nla_get_u8(info->attrs[NL80211_ATTR_KEY_IDX]);
2857
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002858 if (key_idx > 5)
Johannes Berg41ade002007-12-19 02:03:29 +01002859 return -EINVAL;
2860
2861 if (info->attrs[NL80211_ATTR_MAC])
2862 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
2863
Johannes Berge31b8212010-10-05 19:39:30 +02002864 pairwise = !!mac_addr;
2865 if (info->attrs[NL80211_ATTR_KEY_TYPE]) {
2866 u32 kt = nla_get_u32(info->attrs[NL80211_ATTR_KEY_TYPE]);
2867 if (kt >= NUM_NL80211_KEYTYPES)
2868 return -EINVAL;
2869 if (kt != NL80211_KEYTYPE_GROUP &&
2870 kt != NL80211_KEYTYPE_PAIRWISE)
2871 return -EINVAL;
2872 pairwise = kt == NL80211_KEYTYPE_PAIRWISE;
2873 }
2874
Johannes Berg4c476992010-10-04 21:36:35 +02002875 if (!rdev->ops->get_key)
2876 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01002877
Johannes Berg0fa7b392015-01-23 11:10:12 +01002878 if (!pairwise && mac_addr && !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
2879 return -ENOENT;
2880
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07002881 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02002882 if (!msg)
2883 return -ENOMEM;
Johannes Berg41ade002007-12-19 02:03:29 +01002884
Eric W. Biederman15e47302012-09-07 20:12:54 +00002885 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg41ade002007-12-19 02:03:29 +01002886 NL80211_CMD_NEW_KEY);
Dan Carpentercb35fba2013-08-14 14:50:01 +03002887 if (!hdr)
Johannes Berg9fe271a2013-10-25 11:15:12 +02002888 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002889
2890 cookie.msg = msg;
Johannes Bergb9454e82009-07-08 13:29:08 +02002891 cookie.idx = key_idx;
Johannes Berg41ade002007-12-19 02:03:29 +01002892
David S. Miller9360ffd2012-03-29 04:41:26 -04002893 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
2894 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
2895 goto nla_put_failure;
2896 if (mac_addr &&
2897 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr))
2898 goto nla_put_failure;
Johannes Berg41ade002007-12-19 02:03:29 +01002899
Hila Gonene35e4d22012-06-27 17:19:42 +03002900 err = rdev_get_key(rdev, dev, key_idx, pairwise, mac_addr, &cookie,
2901 get_key_callback);
Johannes Berg41ade002007-12-19 02:03:29 +01002902
2903 if (err)
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002904 goto free_msg;
Johannes Berg41ade002007-12-19 02:03:29 +01002905
2906 if (cookie.error)
2907 goto nla_put_failure;
2908
2909 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02002910 return genlmsg_reply(msg, info);
Johannes Berg41ade002007-12-19 02:03:29 +01002911
2912 nla_put_failure:
2913 err = -ENOBUFS;
Niko Jokinen6c95e2a2009-07-15 11:00:53 +03002914 free_msg:
Johannes Berg41ade002007-12-19 02:03:29 +01002915 nlmsg_free(msg);
Johannes Berg41ade002007-12-19 02:03:29 +01002916 return err;
2917}
2918
2919static int nl80211_set_key(struct sk_buff *skb, struct genl_info *info)
2920{
Johannes Berg4c476992010-10-04 21:36:35 +02002921 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergb9454e82009-07-08 13:29:08 +02002922 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01002923 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002924 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01002925
Johannes Bergb9454e82009-07-08 13:29:08 +02002926 err = nl80211_parse_key(info, &key);
2927 if (err)
2928 return err;
2929
2930 if (key.idx < 0)
Johannes Berg41ade002007-12-19 02:03:29 +01002931 return -EINVAL;
2932
Johannes Bergb9454e82009-07-08 13:29:08 +02002933 /* only support setting default key */
2934 if (!key.def && !key.defmgmt)
Johannes Berg41ade002007-12-19 02:03:29 +01002935 return -EINVAL;
2936
Johannes Bergfffd0932009-07-08 14:22:54 +02002937 wdev_lock(dev->ieee80211_ptr);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002938
2939 if (key.def) {
2940 if (!rdev->ops->set_default_key) {
2941 err = -EOPNOTSUPP;
2942 goto out;
2943 }
2944
2945 err = nl80211_key_allowed(dev->ieee80211_ptr);
2946 if (err)
2947 goto out;
2948
Hila Gonene35e4d22012-06-27 17:19:42 +03002949 err = rdev_set_default_key(rdev, dev, key.idx,
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002950 key.def_uni, key.def_multi);
2951
2952 if (err)
2953 goto out;
Johannes Bergfffd0932009-07-08 14:22:54 +02002954
Johannes Berg3d23e342009-09-29 23:27:28 +02002955#ifdef CONFIG_CFG80211_WEXT
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002956 dev->ieee80211_ptr->wext.default_key = key.idx;
Johannes Berg08645122009-05-11 13:54:58 +02002957#endif
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002958 } else {
2959 if (key.def_uni || !key.def_multi) {
2960 err = -EINVAL;
2961 goto out;
2962 }
2963
2964 if (!rdev->ops->set_default_mgmt_key) {
2965 err = -EOPNOTSUPP;
2966 goto out;
2967 }
2968
2969 err = nl80211_key_allowed(dev->ieee80211_ptr);
2970 if (err)
2971 goto out;
2972
Hila Gonene35e4d22012-06-27 17:19:42 +03002973 err = rdev_set_default_mgmt_key(rdev, dev, key.idx);
Johannes Bergdbd2fd62010-12-09 19:58:59 +01002974 if (err)
2975 goto out;
2976
2977#ifdef CONFIG_CFG80211_WEXT
2978 dev->ieee80211_ptr->wext.default_mgmt_key = key.idx;
2979#endif
2980 }
2981
2982 out:
Johannes Bergfffd0932009-07-08 14:22:54 +02002983 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01002984
Johannes Berg41ade002007-12-19 02:03:29 +01002985 return err;
2986}
2987
2988static int nl80211_new_key(struct sk_buff *skb, struct genl_info *info)
2989{
Johannes Berg4c476992010-10-04 21:36:35 +02002990 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfffd0932009-07-08 14:22:54 +02002991 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02002992 struct net_device *dev = info->user_ptr[1];
Johannes Bergb9454e82009-07-08 13:29:08 +02002993 struct key_parse key;
Johannes Berge31b8212010-10-05 19:39:30 +02002994 const u8 *mac_addr = NULL;
Johannes Berg41ade002007-12-19 02:03:29 +01002995
Johannes Bergb9454e82009-07-08 13:29:08 +02002996 err = nl80211_parse_key(info, &key);
2997 if (err)
2998 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01002999
Johannes Bergb9454e82009-07-08 13:29:08 +02003000 if (!key.p.key)
Johannes Berg41ade002007-12-19 02:03:29 +01003001 return -EINVAL;
3002
Johannes Berg41ade002007-12-19 02:03:29 +01003003 if (info->attrs[NL80211_ATTR_MAC])
3004 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3005
Johannes Berge31b8212010-10-05 19:39:30 +02003006 if (key.type == -1) {
3007 if (mac_addr)
3008 key.type = NL80211_KEYTYPE_PAIRWISE;
3009 else
3010 key.type = NL80211_KEYTYPE_GROUP;
3011 }
3012
3013 /* for now */
3014 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3015 key.type != NL80211_KEYTYPE_GROUP)
3016 return -EINVAL;
3017
Johannes Berg4c476992010-10-04 21:36:35 +02003018 if (!rdev->ops->add_key)
3019 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01003020
Johannes Berge31b8212010-10-05 19:39:30 +02003021 if (cfg80211_validate_key_settings(rdev, &key.p, key.idx,
3022 key.type == NL80211_KEYTYPE_PAIRWISE,
3023 mac_addr))
Johannes Berg4c476992010-10-04 21:36:35 +02003024 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02003025
3026 wdev_lock(dev->ieee80211_ptr);
3027 err = nl80211_key_allowed(dev->ieee80211_ptr);
3028 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003029 err = rdev_add_key(rdev, dev, key.idx,
3030 key.type == NL80211_KEYTYPE_PAIRWISE,
3031 mac_addr, &key.p);
Johannes Bergfffd0932009-07-08 14:22:54 +02003032 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg41ade002007-12-19 02:03:29 +01003033
Johannes Berg41ade002007-12-19 02:03:29 +01003034 return err;
3035}
3036
3037static int nl80211_del_key(struct sk_buff *skb, struct genl_info *info)
3038{
Johannes Berg4c476992010-10-04 21:36:35 +02003039 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg41ade002007-12-19 02:03:29 +01003040 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02003041 struct net_device *dev = info->user_ptr[1];
Johannes Berg41ade002007-12-19 02:03:29 +01003042 u8 *mac_addr = NULL;
Johannes Bergb9454e82009-07-08 13:29:08 +02003043 struct key_parse key;
Johannes Berg41ade002007-12-19 02:03:29 +01003044
Johannes Bergb9454e82009-07-08 13:29:08 +02003045 err = nl80211_parse_key(info, &key);
3046 if (err)
3047 return err;
Johannes Berg41ade002007-12-19 02:03:29 +01003048
3049 if (info->attrs[NL80211_ATTR_MAC])
3050 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3051
Johannes Berge31b8212010-10-05 19:39:30 +02003052 if (key.type == -1) {
3053 if (mac_addr)
3054 key.type = NL80211_KEYTYPE_PAIRWISE;
3055 else
3056 key.type = NL80211_KEYTYPE_GROUP;
3057 }
3058
3059 /* for now */
3060 if (key.type != NL80211_KEYTYPE_PAIRWISE &&
3061 key.type != NL80211_KEYTYPE_GROUP)
3062 return -EINVAL;
3063
Johannes Berg4c476992010-10-04 21:36:35 +02003064 if (!rdev->ops->del_key)
3065 return -EOPNOTSUPP;
Johannes Berg41ade002007-12-19 02:03:29 +01003066
Johannes Bergfffd0932009-07-08 14:22:54 +02003067 wdev_lock(dev->ieee80211_ptr);
3068 err = nl80211_key_allowed(dev->ieee80211_ptr);
Johannes Berge31b8212010-10-05 19:39:30 +02003069
Johannes Berg0fa7b392015-01-23 11:10:12 +01003070 if (key.type == NL80211_KEYTYPE_GROUP && mac_addr &&
Johannes Berge31b8212010-10-05 19:39:30 +02003071 !(rdev->wiphy.flags & WIPHY_FLAG_IBSS_RSN))
3072 err = -ENOENT;
3073
Johannes Bergfffd0932009-07-08 14:22:54 +02003074 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03003075 err = rdev_del_key(rdev, dev, key.idx,
3076 key.type == NL80211_KEYTYPE_PAIRWISE,
3077 mac_addr);
Johannes Berg41ade002007-12-19 02:03:29 +01003078
Johannes Berg3d23e342009-09-29 23:27:28 +02003079#ifdef CONFIG_CFG80211_WEXT
Johannes Berg08645122009-05-11 13:54:58 +02003080 if (!err) {
Johannes Bergb9454e82009-07-08 13:29:08 +02003081 if (key.idx == dev->ieee80211_ptr->wext.default_key)
Johannes Berg08645122009-05-11 13:54:58 +02003082 dev->ieee80211_ptr->wext.default_key = -1;
Johannes Bergb9454e82009-07-08 13:29:08 +02003083 else if (key.idx == dev->ieee80211_ptr->wext.default_mgmt_key)
Johannes Berg08645122009-05-11 13:54:58 +02003084 dev->ieee80211_ptr->wext.default_mgmt_key = -1;
3085 }
3086#endif
Johannes Bergfffd0932009-07-08 14:22:54 +02003087 wdev_unlock(dev->ieee80211_ptr);
Johannes Berg08645122009-05-11 13:54:58 +02003088
Johannes Berg41ade002007-12-19 02:03:29 +01003089 return err;
3090}
3091
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303092/* This function returns an error or the number of nested attributes */
3093static int validate_acl_mac_addrs(struct nlattr *nl_attr)
3094{
3095 struct nlattr *attr;
3096 int n_entries = 0, tmp;
3097
3098 nla_for_each_nested(attr, nl_attr, tmp) {
3099 if (nla_len(attr) != ETH_ALEN)
3100 return -EINVAL;
3101
3102 n_entries++;
3103 }
3104
3105 return n_entries;
3106}
3107
3108/*
3109 * This function parses ACL information and allocates memory for ACL data.
3110 * On successful return, the calling function is responsible to free the
3111 * ACL buffer returned by this function.
3112 */
3113static struct cfg80211_acl_data *parse_acl_data(struct wiphy *wiphy,
3114 struct genl_info *info)
3115{
3116 enum nl80211_acl_policy acl_policy;
3117 struct nlattr *attr;
3118 struct cfg80211_acl_data *acl;
3119 int i = 0, n_entries, tmp;
3120
3121 if (!wiphy->max_acl_mac_addrs)
3122 return ERR_PTR(-EOPNOTSUPP);
3123
3124 if (!info->attrs[NL80211_ATTR_ACL_POLICY])
3125 return ERR_PTR(-EINVAL);
3126
3127 acl_policy = nla_get_u32(info->attrs[NL80211_ATTR_ACL_POLICY]);
3128 if (acl_policy != NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED &&
3129 acl_policy != NL80211_ACL_POLICY_DENY_UNLESS_LISTED)
3130 return ERR_PTR(-EINVAL);
3131
3132 if (!info->attrs[NL80211_ATTR_MAC_ADDRS])
3133 return ERR_PTR(-EINVAL);
3134
3135 n_entries = validate_acl_mac_addrs(info->attrs[NL80211_ATTR_MAC_ADDRS]);
3136 if (n_entries < 0)
3137 return ERR_PTR(n_entries);
3138
3139 if (n_entries > wiphy->max_acl_mac_addrs)
3140 return ERR_PTR(-ENOTSUPP);
3141
3142 acl = kzalloc(sizeof(*acl) + (sizeof(struct mac_address) * n_entries),
3143 GFP_KERNEL);
3144 if (!acl)
3145 return ERR_PTR(-ENOMEM);
3146
3147 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_MAC_ADDRS], tmp) {
3148 memcpy(acl->mac_addrs[i].addr, nla_data(attr), ETH_ALEN);
3149 i++;
3150 }
3151
3152 acl->n_acl_entries = n_entries;
3153 acl->acl_policy = acl_policy;
3154
3155 return acl;
3156}
3157
3158static int nl80211_set_mac_acl(struct sk_buff *skb, struct genl_info *info)
3159{
3160 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3161 struct net_device *dev = info->user_ptr[1];
3162 struct cfg80211_acl_data *acl;
3163 int err;
3164
3165 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3166 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3167 return -EOPNOTSUPP;
3168
3169 if (!dev->ieee80211_ptr->beacon_interval)
3170 return -EINVAL;
3171
3172 acl = parse_acl_data(&rdev->wiphy, info);
3173 if (IS_ERR(acl))
3174 return PTR_ERR(acl);
3175
3176 err = rdev_set_mac_acl(rdev, dev, acl);
3177
3178 kfree(acl);
3179
3180 return err;
3181}
3182
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003183static int nl80211_parse_beacon(struct nlattr *attrs[],
Johannes Berg88600202012-02-13 15:17:18 +01003184 struct cfg80211_beacon_data *bcn)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003185{
Johannes Berg88600202012-02-13 15:17:18 +01003186 bool haveinfo = false;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003187
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003188 if (!is_valid_ie_attr(attrs[NL80211_ATTR_BEACON_TAIL]) ||
3189 !is_valid_ie_attr(attrs[NL80211_ATTR_IE]) ||
3190 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_PROBE_RESP]) ||
3191 !is_valid_ie_attr(attrs[NL80211_ATTR_IE_ASSOC_RESP]))
Johannes Bergf4a11bb2009-03-27 12:40:28 +01003192 return -EINVAL;
3193
Johannes Berg88600202012-02-13 15:17:18 +01003194 memset(bcn, 0, sizeof(*bcn));
Johannes Berged1b6cc2007-12-19 02:03:32 +01003195
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003196 if (attrs[NL80211_ATTR_BEACON_HEAD]) {
3197 bcn->head = nla_data(attrs[NL80211_ATTR_BEACON_HEAD]);
3198 bcn->head_len = nla_len(attrs[NL80211_ATTR_BEACON_HEAD]);
Johannes Berg88600202012-02-13 15:17:18 +01003199 if (!bcn->head_len)
3200 return -EINVAL;
3201 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003202 }
3203
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003204 if (attrs[NL80211_ATTR_BEACON_TAIL]) {
3205 bcn->tail = nla_data(attrs[NL80211_ATTR_BEACON_TAIL]);
3206 bcn->tail_len = nla_len(attrs[NL80211_ATTR_BEACON_TAIL]);
Johannes Berg88600202012-02-13 15:17:18 +01003207 haveinfo = true;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003208 }
3209
Johannes Berg4c476992010-10-04 21:36:35 +02003210 if (!haveinfo)
3211 return -EINVAL;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003212
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003213 if (attrs[NL80211_ATTR_IE]) {
3214 bcn->beacon_ies = nla_data(attrs[NL80211_ATTR_IE]);
3215 bcn->beacon_ies_len = nla_len(attrs[NL80211_ATTR_IE]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003216 }
3217
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003218 if (attrs[NL80211_ATTR_IE_PROBE_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003219 bcn->proberesp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003220 nla_data(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003221 bcn->proberesp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003222 nla_len(attrs[NL80211_ATTR_IE_PROBE_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003223 }
3224
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003225 if (attrs[NL80211_ATTR_IE_ASSOC_RESP]) {
Johannes Berg88600202012-02-13 15:17:18 +01003226 bcn->assocresp_ies =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003227 nla_data(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Johannes Berg88600202012-02-13 15:17:18 +01003228 bcn->assocresp_ies_len =
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003229 nla_len(attrs[NL80211_ATTR_IE_ASSOC_RESP]);
Jouni Malinen9946ecf2011-08-10 23:55:56 +03003230 }
3231
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003232 if (attrs[NL80211_ATTR_PROBE_RESP]) {
3233 bcn->probe_resp = nla_data(attrs[NL80211_ATTR_PROBE_RESP]);
3234 bcn->probe_resp_len = nla_len(attrs[NL80211_ATTR_PROBE_RESP]);
Arik Nemtsov00f740e2011-11-10 11:28:56 +02003235 }
3236
Johannes Berg88600202012-02-13 15:17:18 +01003237 return 0;
3238}
3239
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003240static bool nl80211_get_ap_channel(struct cfg80211_registered_device *rdev,
3241 struct cfg80211_ap_settings *params)
3242{
3243 struct wireless_dev *wdev;
3244 bool ret = false;
3245
Johannes Berg89a54e42012-06-15 14:33:17 +02003246 list_for_each_entry(wdev, &rdev->wdev_list, list) {
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003247 if (wdev->iftype != NL80211_IFTYPE_AP &&
3248 wdev->iftype != NL80211_IFTYPE_P2P_GO)
3249 continue;
3250
Johannes Berg683b6d32012-11-08 21:25:48 +01003251 if (!wdev->preset_chandef.chan)
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003252 continue;
3253
Johannes Berg683b6d32012-11-08 21:25:48 +01003254 params->chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003255 ret = true;
3256 break;
3257 }
3258
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003259 return ret;
3260}
3261
Jouni Malinene39e5b52012-09-30 19:29:39 +03003262static bool nl80211_valid_auth_type(struct cfg80211_registered_device *rdev,
3263 enum nl80211_auth_type auth_type,
3264 enum nl80211_commands cmd)
3265{
3266 if (auth_type > NL80211_AUTHTYPE_MAX)
3267 return false;
3268
3269 switch (cmd) {
3270 case NL80211_CMD_AUTHENTICATE:
3271 if (!(rdev->wiphy.features & NL80211_FEATURE_SAE) &&
3272 auth_type == NL80211_AUTHTYPE_SAE)
3273 return false;
3274 return true;
3275 case NL80211_CMD_CONNECT:
3276 case NL80211_CMD_START_AP:
3277 /* SAE not supported yet */
3278 if (auth_type == NL80211_AUTHTYPE_SAE)
3279 return false;
3280 return true;
3281 default:
3282 return false;
3283 }
3284}
3285
Johannes Berg88600202012-02-13 15:17:18 +01003286static int nl80211_start_ap(struct sk_buff *skb, struct genl_info *info)
3287{
3288 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3289 struct net_device *dev = info->user_ptr[1];
3290 struct wireless_dev *wdev = dev->ieee80211_ptr;
3291 struct cfg80211_ap_settings params;
3292 int err;
3293
3294 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3295 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3296 return -EOPNOTSUPP;
3297
3298 if (!rdev->ops->start_ap)
3299 return -EOPNOTSUPP;
3300
3301 if (wdev->beacon_interval)
3302 return -EALREADY;
3303
3304 memset(&params, 0, sizeof(params));
3305
3306 /* these are required for START_AP */
3307 if (!info->attrs[NL80211_ATTR_BEACON_INTERVAL] ||
3308 !info->attrs[NL80211_ATTR_DTIM_PERIOD] ||
3309 !info->attrs[NL80211_ATTR_BEACON_HEAD])
3310 return -EINVAL;
3311
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003312 err = nl80211_parse_beacon(info->attrs, &params.beacon);
Johannes Berg88600202012-02-13 15:17:18 +01003313 if (err)
3314 return err;
3315
3316 params.beacon_interval =
3317 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
3318 params.dtim_period =
3319 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
3320
3321 err = cfg80211_validate_beacon_int(rdev, params.beacon_interval);
3322 if (err)
3323 return err;
3324
3325 /*
3326 * In theory, some of these attributes should be required here
3327 * but since they were not used when the command was originally
3328 * added, keep them optional for old user space programs to let
3329 * them continue to work with drivers that do not need the
3330 * additional information -- drivers must check!
3331 */
3332 if (info->attrs[NL80211_ATTR_SSID]) {
3333 params.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
3334 params.ssid_len =
3335 nla_len(info->attrs[NL80211_ATTR_SSID]);
3336 if (params.ssid_len == 0 ||
3337 params.ssid_len > IEEE80211_MAX_SSID_LEN)
3338 return -EINVAL;
3339 }
3340
3341 if (info->attrs[NL80211_ATTR_HIDDEN_SSID]) {
3342 params.hidden_ssid = nla_get_u32(
3343 info->attrs[NL80211_ATTR_HIDDEN_SSID]);
3344 if (params.hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE &&
3345 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_LEN &&
3346 params.hidden_ssid != NL80211_HIDDEN_SSID_ZERO_CONTENTS)
3347 return -EINVAL;
3348 }
3349
3350 params.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
3351
3352 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
3353 params.auth_type = nla_get_u32(
3354 info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03003355 if (!nl80211_valid_auth_type(rdev, params.auth_type,
3356 NL80211_CMD_START_AP))
Johannes Berg88600202012-02-13 15:17:18 +01003357 return -EINVAL;
3358 } else
3359 params.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
3360
3361 err = nl80211_crypto_settings(rdev, info, &params.crypto,
3362 NL80211_MAX_NR_CIPHER_SUITES);
3363 if (err)
3364 return err;
3365
Vasanthakumar Thiagarajan1b658f12012-03-02 15:50:02 +05303366 if (info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]) {
3367 if (!(rdev->wiphy.features & NL80211_FEATURE_INACTIVITY_TIMER))
3368 return -EOPNOTSUPP;
3369 params.inactivity_timeout = nla_get_u16(
3370 info->attrs[NL80211_ATTR_INACTIVITY_TIMEOUT]);
3371 }
3372
Johannes Berg53cabad2012-11-14 15:17:28 +01003373 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
3374 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3375 return -EINVAL;
3376 params.p2p_ctwindow =
3377 nla_get_u8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
3378 if (params.p2p_ctwindow > 127)
3379 return -EINVAL;
3380 if (params.p2p_ctwindow != 0 &&
3381 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
3382 return -EINVAL;
3383 }
3384
3385 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
3386 u8 tmp;
3387
3388 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3389 return -EINVAL;
3390 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
3391 if (tmp > 1)
3392 return -EINVAL;
3393 params.p2p_opp_ps = tmp;
3394 if (params.p2p_opp_ps != 0 &&
3395 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
3396 return -EINVAL;
3397 }
3398
Johannes Bergaa430da2012-05-16 23:50:18 +02003399 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003400 err = nl80211_parse_chandef(rdev, info, &params.chandef);
3401 if (err)
3402 return err;
3403 } else if (wdev->preset_chandef.chan) {
3404 params.chandef = wdev->preset_chandef;
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003405 } else if (!nl80211_get_ap_channel(rdev, &params))
Johannes Bergaa430da2012-05-16 23:50:18 +02003406 return -EINVAL;
3407
Arik Nemtsov923b3522015-07-08 15:41:44 +03003408 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
3409 wdev->iftype))
Johannes Bergaa430da2012-05-16 23:50:18 +02003410 return -EINVAL;
3411
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303412 if (info->attrs[NL80211_ATTR_ACL_POLICY]) {
3413 params.acl = parse_acl_data(&rdev->wiphy, info);
3414 if (IS_ERR(params.acl))
3415 return PTR_ERR(params.acl);
3416 }
3417
Eliad Peller18998c32014-09-10 14:07:34 +03003418 if (info->attrs[NL80211_ATTR_SMPS_MODE]) {
3419 params.smps_mode =
3420 nla_get_u8(info->attrs[NL80211_ATTR_SMPS_MODE]);
3421 switch (params.smps_mode) {
3422 case NL80211_SMPS_OFF:
3423 break;
3424 case NL80211_SMPS_STATIC:
3425 if (!(rdev->wiphy.features &
3426 NL80211_FEATURE_STATIC_SMPS))
3427 return -EINVAL;
3428 break;
3429 case NL80211_SMPS_DYNAMIC:
3430 if (!(rdev->wiphy.features &
3431 NL80211_FEATURE_DYNAMIC_SMPS))
3432 return -EINVAL;
3433 break;
3434 default:
3435 return -EINVAL;
3436 }
3437 } else {
3438 params.smps_mode = NL80211_SMPS_OFF;
3439 }
3440
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003441 wdev_lock(wdev);
Hila Gonene35e4d22012-06-27 17:19:42 +03003442 err = rdev_start_ap(rdev, dev, &params);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003443 if (!err) {
Johannes Berg683b6d32012-11-08 21:25:48 +01003444 wdev->preset_chandef = params.chandef;
Johannes Berg88600202012-02-13 15:17:18 +01003445 wdev->beacon_interval = params.beacon_interval;
Michal Kazior9e0e2962014-01-29 14:22:27 +01003446 wdev->chandef = params.chandef;
Antonio Quartulli06e191e2012-11-07 12:52:19 +01003447 wdev->ssid_len = params.ssid_len;
3448 memcpy(wdev->ssid, params.ssid, wdev->ssid_len);
Felix Fietkau46c1dd02012-06-19 02:50:57 +02003449 }
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003450 wdev_unlock(wdev);
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +05303451
3452 kfree(params.acl);
3453
Johannes Berg56d18932011-05-09 18:41:15 +02003454 return err;
Johannes Berged1b6cc2007-12-19 02:03:32 +01003455}
3456
Johannes Berg88600202012-02-13 15:17:18 +01003457static int nl80211_set_beacon(struct sk_buff *skb, struct genl_info *info)
3458{
3459 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3460 struct net_device *dev = info->user_ptr[1];
3461 struct wireless_dev *wdev = dev->ieee80211_ptr;
3462 struct cfg80211_beacon_data params;
3463 int err;
3464
3465 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
3466 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
3467 return -EOPNOTSUPP;
3468
3469 if (!rdev->ops->change_beacon)
3470 return -EOPNOTSUPP;
3471
3472 if (!wdev->beacon_interval)
3473 return -EINVAL;
3474
Simon Wunderlicha1193be2013-06-14 14:15:19 +02003475 err = nl80211_parse_beacon(info->attrs, &params);
Johannes Berg88600202012-02-13 15:17:18 +01003476 if (err)
3477 return err;
3478
Simon Wunderlichc56589e2013-11-21 18:19:49 +01003479 wdev_lock(wdev);
3480 err = rdev_change_beacon(rdev, dev, &params);
3481 wdev_unlock(wdev);
3482
3483 return err;
Johannes Berg88600202012-02-13 15:17:18 +01003484}
3485
3486static int nl80211_stop_ap(struct sk_buff *skb, struct genl_info *info)
Johannes Berged1b6cc2007-12-19 02:03:32 +01003487{
Johannes Berg4c476992010-10-04 21:36:35 +02003488 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3489 struct net_device *dev = info->user_ptr[1];
Johannes Berged1b6cc2007-12-19 02:03:32 +01003490
Ilan Peer7c8d5e02014-02-25 15:33:38 +02003491 return cfg80211_stop_ap(rdev, dev, false);
Johannes Berged1b6cc2007-12-19 02:03:32 +01003492}
3493
Johannes Berg5727ef12007-12-19 02:03:34 +01003494static const struct nla_policy sta_flags_policy[NL80211_STA_FLAG_MAX + 1] = {
3495 [NL80211_STA_FLAG_AUTHORIZED] = { .type = NLA_FLAG },
3496 [NL80211_STA_FLAG_SHORT_PREAMBLE] = { .type = NLA_FLAG },
3497 [NL80211_STA_FLAG_WME] = { .type = NLA_FLAG },
Jouni Malinen0e467242009-05-11 21:57:55 +03003498 [NL80211_STA_FLAG_MFP] = { .type = NLA_FLAG },
Javier Cardonab39c48f2011-04-07 15:08:30 -07003499 [NL80211_STA_FLAG_AUTHENTICATED] = { .type = NLA_FLAG },
Johannes Bergd83023d2011-12-14 09:29:15 +01003500 [NL80211_STA_FLAG_TDLS_PEER] = { .type = NLA_FLAG },
Johannes Berg5727ef12007-12-19 02:03:34 +01003501};
3502
Johannes Bergeccb8e82009-05-11 21:57:56 +03003503static int parse_station_flags(struct genl_info *info,
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003504 enum nl80211_iftype iftype,
Johannes Bergeccb8e82009-05-11 21:57:56 +03003505 struct station_parameters *params)
Johannes Berg5727ef12007-12-19 02:03:34 +01003506{
3507 struct nlattr *flags[NL80211_STA_FLAG_MAX + 1];
Johannes Bergeccb8e82009-05-11 21:57:56 +03003508 struct nlattr *nla;
Johannes Berg5727ef12007-12-19 02:03:34 +01003509 int flag;
3510
Johannes Bergeccb8e82009-05-11 21:57:56 +03003511 /*
3512 * Try parsing the new attribute first so userspace
3513 * can specify both for older kernels.
3514 */
3515 nla = info->attrs[NL80211_ATTR_STA_FLAGS2];
3516 if (nla) {
3517 struct nl80211_sta_flag_update *sta_flags;
Johannes Berg5727ef12007-12-19 02:03:34 +01003518
Johannes Bergeccb8e82009-05-11 21:57:56 +03003519 sta_flags = nla_data(nla);
3520 params->sta_flags_mask = sta_flags->mask;
3521 params->sta_flags_set = sta_flags->set;
Johannes Berg77ee7c82013-02-15 00:48:33 +01003522 params->sta_flags_set &= params->sta_flags_mask;
Johannes Bergeccb8e82009-05-11 21:57:56 +03003523 if ((params->sta_flags_mask |
3524 params->sta_flags_set) & BIT(__NL80211_STA_FLAG_INVALID))
3525 return -EINVAL;
3526 return 0;
3527 }
3528
3529 /* if present, parse the old attribute */
3530
3531 nla = info->attrs[NL80211_ATTR_STA_FLAGS];
Johannes Berg5727ef12007-12-19 02:03:34 +01003532 if (!nla)
3533 return 0;
3534
3535 if (nla_parse_nested(flags, NL80211_STA_FLAG_MAX,
3536 nla, sta_flags_policy))
3537 return -EINVAL;
3538
Johannes Bergbdd3ae32012-01-02 13:30:03 +01003539 /*
3540 * Only allow certain flags for interface types so that
3541 * other attributes are silently ignored. Remember that
3542 * this is backward compatibility code with old userspace
3543 * and shouldn't be hit in other cases anyway.
3544 */
3545 switch (iftype) {
3546 case NL80211_IFTYPE_AP:
3547 case NL80211_IFTYPE_AP_VLAN:
3548 case NL80211_IFTYPE_P2P_GO:
3549 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3550 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
3551 BIT(NL80211_STA_FLAG_WME) |
3552 BIT(NL80211_STA_FLAG_MFP);
3553 break;
3554 case NL80211_IFTYPE_P2P_CLIENT:
3555 case NL80211_IFTYPE_STATION:
3556 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
3557 BIT(NL80211_STA_FLAG_TDLS_PEER);
3558 break;
3559 case NL80211_IFTYPE_MESH_POINT:
3560 params->sta_flags_mask = BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3561 BIT(NL80211_STA_FLAG_MFP) |
3562 BIT(NL80211_STA_FLAG_AUTHORIZED);
3563 default:
3564 return -EINVAL;
3565 }
Johannes Berg5727ef12007-12-19 02:03:34 +01003566
Johannes Berg3383b5a2012-05-10 20:14:43 +02003567 for (flag = 1; flag <= NL80211_STA_FLAG_MAX; flag++) {
3568 if (flags[flag]) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03003569 params->sta_flags_set |= (1<<flag);
Johannes Berg5727ef12007-12-19 02:03:34 +01003570
Johannes Berg3383b5a2012-05-10 20:14:43 +02003571 /* no longer support new API additions in old API */
3572 if (flag > NL80211_STA_FLAG_MAX_OLD_API)
3573 return -EINVAL;
3574 }
3575 }
3576
Johannes Berg5727ef12007-12-19 02:03:34 +01003577 return 0;
3578}
3579
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003580static bool nl80211_put_sta_rate(struct sk_buff *msg, struct rate_info *info,
3581 int attr)
3582{
3583 struct nlattr *rate;
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003584 u32 bitrate;
3585 u16 bitrate_compat;
Johannes Bergb51f3be2015-01-15 16:14:02 +01003586 enum nl80211_attrs rate_flg;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003587
3588 rate = nla_nest_start(msg, attr);
3589 if (!rate)
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003590 return false;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003591
3592 /* cfg80211_calculate_bitrate will return 0 for mcs >= 32 */
3593 bitrate = cfg80211_calculate_bitrate(info);
Vladimir Kondratiev8eb41c82012-07-05 14:25:49 +03003594 /* report 16-bit bitrate only if we can */
3595 bitrate_compat = bitrate < (1UL << 16) ? bitrate : 0;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003596 if (bitrate > 0 &&
3597 nla_put_u32(msg, NL80211_RATE_INFO_BITRATE32, bitrate))
3598 return false;
3599 if (bitrate_compat > 0 &&
3600 nla_put_u16(msg, NL80211_RATE_INFO_BITRATE, bitrate_compat))
3601 return false;
3602
Johannes Bergb51f3be2015-01-15 16:14:02 +01003603 switch (info->bw) {
3604 case RATE_INFO_BW_5:
3605 rate_flg = NL80211_RATE_INFO_5_MHZ_WIDTH;
3606 break;
3607 case RATE_INFO_BW_10:
3608 rate_flg = NL80211_RATE_INFO_10_MHZ_WIDTH;
3609 break;
3610 default:
3611 WARN_ON(1);
3612 /* fall through */
3613 case RATE_INFO_BW_20:
3614 rate_flg = 0;
3615 break;
3616 case RATE_INFO_BW_40:
3617 rate_flg = NL80211_RATE_INFO_40_MHZ_WIDTH;
3618 break;
3619 case RATE_INFO_BW_80:
3620 rate_flg = NL80211_RATE_INFO_80_MHZ_WIDTH;
3621 break;
3622 case RATE_INFO_BW_160:
3623 rate_flg = NL80211_RATE_INFO_160_MHZ_WIDTH;
3624 break;
3625 }
3626
3627 if (rate_flg && nla_put_flag(msg, rate_flg))
3628 return false;
3629
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003630 if (info->flags & RATE_INFO_FLAGS_MCS) {
3631 if (nla_put_u8(msg, NL80211_RATE_INFO_MCS, info->mcs))
3632 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003633 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3634 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3635 return false;
3636 } else if (info->flags & RATE_INFO_FLAGS_VHT_MCS) {
3637 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_MCS, info->mcs))
3638 return false;
3639 if (nla_put_u8(msg, NL80211_RATE_INFO_VHT_NSS, info->nss))
3640 return false;
Johannes Bergdb9c64c2012-11-09 14:56:41 +01003641 if (info->flags & RATE_INFO_FLAGS_SHORT_GI &&
3642 nla_put_flag(msg, NL80211_RATE_INFO_SHORT_GI))
3643 return false;
3644 }
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003645
3646 nla_nest_end(msg, rate);
3647 return true;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003648}
3649
Felix Fietkau119363c2013-04-22 16:29:30 +02003650static bool nl80211_put_signal(struct sk_buff *msg, u8 mask, s8 *signal,
3651 int id)
3652{
3653 void *attr;
3654 int i = 0;
3655
3656 if (!mask)
3657 return true;
3658
3659 attr = nla_nest_start(msg, id);
3660 if (!attr)
3661 return false;
3662
3663 for (i = 0; i < IEEE80211_MAX_CHAINS; i++) {
3664 if (!(mask & BIT(i)))
3665 continue;
3666
3667 if (nla_put_u8(msg, i, signal[i]))
3668 return false;
3669 }
3670
3671 nla_nest_end(msg, attr);
3672
3673 return true;
3674}
3675
Johannes Bergcf5ead82014-11-14 17:14:00 +01003676static int nl80211_send_station(struct sk_buff *msg, u32 cmd, u32 portid,
3677 u32 seq, int flags,
John W. Linville66266b32012-03-15 13:25:41 -04003678 struct cfg80211_registered_device *rdev,
3679 struct net_device *dev,
Johannes Berg98b62182009-12-23 13:15:44 +01003680 const u8 *mac_addr, struct station_info *sinfo)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003681{
3682 void *hdr;
Paul Stewartf4263c92011-03-31 09:25:41 -07003683 struct nlattr *sinfoattr, *bss_param;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003684
Johannes Bergcf5ead82014-11-14 17:14:00 +01003685 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003686 if (!hdr)
3687 return -1;
3688
David S. Miller9360ffd2012-03-29 04:41:26 -04003689 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
3690 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
3691 nla_put_u32(msg, NL80211_ATTR_GENERATION, sinfo->generation))
3692 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02003693
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003694 sinfoattr = nla_nest_start(msg, NL80211_ATTR_STA_INFO);
3695 if (!sinfoattr)
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003696 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003697
3698#define PUT_SINFO(attr, memb, type) do { \
3699 if (sinfo->filled & BIT(NL80211_STA_INFO_ ## attr) && \
3700 nla_put_ ## type(msg, NL80211_STA_INFO_ ## attr, \
3701 sinfo->memb)) \
3702 goto nla_put_failure; \
3703 } while (0)
3704
3705 PUT_SINFO(CONNECTED_TIME, connected_time, u32);
3706 PUT_SINFO(INACTIVE_TIME, inactive_time, u32);
3707
3708 if (sinfo->filled & (BIT(NL80211_STA_INFO_RX_BYTES) |
3709 BIT(NL80211_STA_INFO_RX_BYTES64)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003710 nla_put_u32(msg, NL80211_STA_INFO_RX_BYTES,
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003711 (u32)sinfo->rx_bytes))
3712 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003713
3714 if (sinfo->filled & (BIT(NL80211_STA_INFO_TX_BYTES) |
3715 BIT(NL80211_STA_INFO_TX_BYTES64)) &&
Vladimir Kondratiev42745e02013-02-04 13:53:11 +02003716 nla_put_u32(msg, NL80211_STA_INFO_TX_BYTES,
3717 (u32)sinfo->tx_bytes))
3718 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003719
3720 PUT_SINFO(RX_BYTES64, rx_bytes, u64);
3721 PUT_SINFO(TX_BYTES64, tx_bytes, u64);
3722 PUT_SINFO(LLID, llid, u16);
3723 PUT_SINFO(PLID, plid, u16);
3724 PUT_SINFO(PLINK_STATE, plink_state, u8);
3725
John W. Linville66266b32012-03-15 13:25:41 -04003726 switch (rdev->wiphy.signal_type) {
3727 case CFG80211_SIGNAL_TYPE_MBM:
Johannes Berg319090b2014-11-17 14:08:11 +01003728 PUT_SINFO(SIGNAL, signal, u8);
3729 PUT_SINFO(SIGNAL_AVG, signal_avg, u8);
John W. Linville66266b32012-03-15 13:25:41 -04003730 break;
3731 default:
3732 break;
3733 }
Johannes Berg319090b2014-11-17 14:08:11 +01003734 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003735 if (!nl80211_put_signal(msg, sinfo->chains,
3736 sinfo->chain_signal,
3737 NL80211_STA_INFO_CHAIN_SIGNAL))
3738 goto nla_put_failure;
3739 }
Johannes Berg319090b2014-11-17 14:08:11 +01003740 if (sinfo->filled & BIT(NL80211_STA_INFO_CHAIN_SIGNAL_AVG)) {
Felix Fietkau119363c2013-04-22 16:29:30 +02003741 if (!nl80211_put_signal(msg, sinfo->chains,
3742 sinfo->chain_signal_avg,
3743 NL80211_STA_INFO_CHAIN_SIGNAL_AVG))
3744 goto nla_put_failure;
3745 }
Johannes Berg319090b2014-11-17 14:08:11 +01003746 if (sinfo->filled & BIT(NL80211_STA_INFO_TX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003747 if (!nl80211_put_sta_rate(msg, &sinfo->txrate,
3748 NL80211_STA_INFO_TX_BITRATE))
Henning Rogge420e7fa2008-12-11 22:04:19 +01003749 goto nla_put_failure;
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003750 }
Johannes Berg319090b2014-11-17 14:08:11 +01003751 if (sinfo->filled & BIT(NL80211_STA_INFO_RX_BITRATE)) {
Felix Fietkauc8dcfd82011-02-27 22:08:00 +01003752 if (!nl80211_put_sta_rate(msg, &sinfo->rxrate,
3753 NL80211_STA_INFO_RX_BITRATE))
3754 goto nla_put_failure;
Henning Rogge420e7fa2008-12-11 22:04:19 +01003755 }
Johannes Berg319090b2014-11-17 14:08:11 +01003756
3757 PUT_SINFO(RX_PACKETS, rx_packets, u32);
3758 PUT_SINFO(TX_PACKETS, tx_packets, u32);
3759 PUT_SINFO(TX_RETRIES, tx_retries, u32);
3760 PUT_SINFO(TX_FAILED, tx_failed, u32);
3761 PUT_SINFO(EXPECTED_THROUGHPUT, expected_throughput, u32);
3762 PUT_SINFO(BEACON_LOSS, beacon_loss_count, u32);
3763 PUT_SINFO(LOCAL_PM, local_pm, u32);
3764 PUT_SINFO(PEER_PM, peer_pm, u32);
3765 PUT_SINFO(NONPEER_PM, nonpeer_pm, u32);
3766
3767 if (sinfo->filled & BIT(NL80211_STA_INFO_BSS_PARAM)) {
Paul Stewartf4263c92011-03-31 09:25:41 -07003768 bss_param = nla_nest_start(msg, NL80211_STA_INFO_BSS_PARAM);
3769 if (!bss_param)
3770 goto nla_put_failure;
3771
David S. Miller9360ffd2012-03-29 04:41:26 -04003772 if (((sinfo->bss_param.flags & BSS_PARAM_FLAGS_CTS_PROT) &&
3773 nla_put_flag(msg, NL80211_STA_BSS_PARAM_CTS_PROT)) ||
3774 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_PREAMBLE) &&
3775 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_PREAMBLE)) ||
3776 ((sinfo->bss_param.flags & BSS_PARAM_FLAGS_SHORT_SLOT_TIME) &&
3777 nla_put_flag(msg, NL80211_STA_BSS_PARAM_SHORT_SLOT_TIME)) ||
3778 nla_put_u8(msg, NL80211_STA_BSS_PARAM_DTIM_PERIOD,
3779 sinfo->bss_param.dtim_period) ||
3780 nla_put_u16(msg, NL80211_STA_BSS_PARAM_BEACON_INTERVAL,
3781 sinfo->bss_param.beacon_interval))
3782 goto nla_put_failure;
Paul Stewartf4263c92011-03-31 09:25:41 -07003783
3784 nla_nest_end(msg, bss_param);
3785 }
Johannes Berg319090b2014-11-17 14:08:11 +01003786 if ((sinfo->filled & BIT(NL80211_STA_INFO_STA_FLAGS)) &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003787 nla_put(msg, NL80211_STA_INFO_STA_FLAGS,
3788 sizeof(struct nl80211_sta_flag_update),
3789 &sinfo->sta_flags))
3790 goto nla_put_failure;
Johannes Berg319090b2014-11-17 14:08:11 +01003791
3792 PUT_SINFO(T_OFFSET, t_offset, u64);
3793 PUT_SINFO(RX_DROP_MISC, rx_dropped_misc, u64);
Johannes Berga76b1942014-11-17 14:12:22 +01003794 PUT_SINFO(BEACON_RX, rx_beacon, u64);
3795 PUT_SINFO(BEACON_SIGNAL_AVG, rx_beacon_signal_avg, u8);
Johannes Berg319090b2014-11-17 14:08:11 +01003796
3797#undef PUT_SINFO
Johannes Berg6de39802014-12-19 12:34:00 +01003798
3799 if (sinfo->filled & BIT(NL80211_STA_INFO_TID_STATS)) {
3800 struct nlattr *tidsattr;
3801 int tid;
3802
3803 tidsattr = nla_nest_start(msg, NL80211_STA_INFO_TID_STATS);
3804 if (!tidsattr)
3805 goto nla_put_failure;
3806
3807 for (tid = 0; tid < IEEE80211_NUM_TIDS + 1; tid++) {
3808 struct cfg80211_tid_stats *tidstats;
3809 struct nlattr *tidattr;
3810
3811 tidstats = &sinfo->pertid[tid];
3812
3813 if (!tidstats->filled)
3814 continue;
3815
3816 tidattr = nla_nest_start(msg, tid + 1);
3817 if (!tidattr)
3818 goto nla_put_failure;
3819
3820#define PUT_TIDVAL(attr, memb, type) do { \
3821 if (tidstats->filled & BIT(NL80211_TID_STATS_ ## attr) && \
3822 nla_put_ ## type(msg, NL80211_TID_STATS_ ## attr, \
3823 tidstats->memb)) \
3824 goto nla_put_failure; \
3825 } while (0)
3826
3827 PUT_TIDVAL(RX_MSDU, rx_msdu, u64);
3828 PUT_TIDVAL(TX_MSDU, tx_msdu, u64);
3829 PUT_TIDVAL(TX_MSDU_RETRIES, tx_msdu_retries, u64);
3830 PUT_TIDVAL(TX_MSDU_FAILED, tx_msdu_failed, u64);
3831
3832#undef PUT_TIDVAL
3833 nla_nest_end(msg, tidattr);
3834 }
3835
3836 nla_nest_end(msg, tidsattr);
3837 }
3838
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003839 nla_nest_end(msg, sinfoattr);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003840
Johannes Berg319090b2014-11-17 14:08:11 +01003841 if (sinfo->assoc_req_ies_len &&
David S. Miller9360ffd2012-03-29 04:41:26 -04003842 nla_put(msg, NL80211_ATTR_IE, sinfo->assoc_req_ies_len,
3843 sinfo->assoc_req_ies))
3844 goto nla_put_failure;
Jouni Malinen50d3dfb2011-08-08 12:11:52 +03003845
Johannes Berg053c0952015-01-16 22:09:00 +01003846 genlmsg_end(msg, hdr);
3847 return 0;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003848
3849 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07003850 genlmsg_cancel(msg, hdr);
3851 return -EMSGSIZE;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003852}
3853
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003854static int nl80211_dump_station(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003855 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003856{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003857 struct station_info sinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003858 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02003859 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003860 u8 mac_addr[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02003861 int sta_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003862 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003863
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003864 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02003865 if (err)
3866 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003867
Johannes Berg97990a02013-04-19 01:02:55 +02003868 if (!wdev->netdev) {
3869 err = -EINVAL;
3870 goto out_err;
3871 }
3872
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003873 if (!rdev->ops->dump_station) {
Jouni Malineneec60b02009-03-20 21:21:19 +02003874 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003875 goto out_err;
3876 }
3877
Johannes Bergbba95fe2008-07-29 13:22:51 +02003878 while (1) {
Jouni Malinenf612ced2011-08-11 11:46:22 +03003879 memset(&sinfo, 0, sizeof(sinfo));
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003880 err = rdev_dump_station(rdev, wdev->netdev, sta_idx,
Hila Gonene35e4d22012-06-27 17:19:42 +03003881 mac_addr, &sinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003882 if (err == -ENOENT)
3883 break;
3884 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01003885 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003886
Johannes Bergcf5ead82014-11-14 17:14:00 +01003887 if (nl80211_send_station(skb, NL80211_CMD_NEW_STATION,
Eric W. Biederman15e47302012-09-07 20:12:54 +00003888 NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003889 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003890 rdev, wdev->netdev, mac_addr,
Johannes Bergbba95fe2008-07-29 13:22:51 +02003891 &sinfo) < 0)
3892 goto out;
3893
3894 sta_idx++;
3895 }
3896
3897
3898 out:
Johannes Berg97990a02013-04-19 01:02:55 +02003899 cb->args[2] = sta_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003900 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02003901 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08003902 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02003903
3904 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003905}
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003906
Johannes Berg5727ef12007-12-19 02:03:34 +01003907static int nl80211_get_station(struct sk_buff *skb, struct genl_info *info)
3908{
Johannes Berg4c476992010-10-04 21:36:35 +02003909 struct cfg80211_registered_device *rdev = info->user_ptr[0];
3910 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003911 struct station_info sinfo;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003912 struct sk_buff *msg;
3913 u8 *mac_addr = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02003914 int err;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003915
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003916 memset(&sinfo, 0, sizeof(sinfo));
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003917
3918 if (!info->attrs[NL80211_ATTR_MAC])
3919 return -EINVAL;
3920
3921 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
3922
Johannes Berg4c476992010-10-04 21:36:35 +02003923 if (!rdev->ops->get_station)
3924 return -EOPNOTSUPP;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003925
Hila Gonene35e4d22012-06-27 17:19:42 +03003926 err = rdev_get_station(rdev, dev, mac_addr, &sinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003927 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02003928 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01003929
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07003930 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003931 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02003932 return -ENOMEM;
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003933
Johannes Bergcf5ead82014-11-14 17:14:00 +01003934 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION,
3935 info->snd_portid, info->snd_seq, 0,
John W. Linville66266b32012-03-15 13:25:41 -04003936 rdev, dev, mac_addr, &sinfo) < 0) {
Johannes Berg4c476992010-10-04 21:36:35 +02003937 nlmsg_free(msg);
3938 return -ENOBUFS;
3939 }
Johannes Bergfd5b74d2007-12-19 02:03:36 +01003940
Johannes Berg4c476992010-10-04 21:36:35 +02003941 return genlmsg_reply(msg, info);
Johannes Berg5727ef12007-12-19 02:03:34 +01003942}
3943
Johannes Berg77ee7c82013-02-15 00:48:33 +01003944int cfg80211_check_station_change(struct wiphy *wiphy,
3945 struct station_parameters *params,
3946 enum cfg80211_station_type statype)
3947{
3948 if (params->listen_interval != -1)
3949 return -EINVAL;
Arik Nemtsovc72e1142014-07-17 17:14:29 +03003950 if (params->aid &&
3951 !(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
Johannes Berg77ee7c82013-02-15 00:48:33 +01003952 return -EINVAL;
3953
3954 /* When you run into this, adjust the code below for the new flag */
3955 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
3956
3957 switch (statype) {
Thomas Pederseneef941e2013-03-04 13:06:11 -08003958 case CFG80211_STA_MESH_PEER_KERNEL:
3959 case CFG80211_STA_MESH_PEER_USER:
Johannes Berg77ee7c82013-02-15 00:48:33 +01003960 /*
3961 * No ignoring the TDLS flag here -- the userspace mesh
3962 * code doesn't have the bug of including TDLS in the
3963 * mask everywhere.
3964 */
3965 if (params->sta_flags_mask &
3966 ~(BIT(NL80211_STA_FLAG_AUTHENTICATED) |
3967 BIT(NL80211_STA_FLAG_MFP) |
3968 BIT(NL80211_STA_FLAG_AUTHORIZED)))
3969 return -EINVAL;
3970 break;
3971 case CFG80211_STA_TDLS_PEER_SETUP:
3972 case CFG80211_STA_TDLS_PEER_ACTIVE:
3973 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
3974 return -EINVAL;
3975 /* ignore since it can't change */
3976 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3977 break;
3978 default:
3979 /* disallow mesh-specific things */
3980 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION)
3981 return -EINVAL;
3982 if (params->local_pm)
3983 return -EINVAL;
3984 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
3985 return -EINVAL;
3986 }
3987
3988 if (statype != CFG80211_STA_TDLS_PEER_SETUP &&
3989 statype != CFG80211_STA_TDLS_PEER_ACTIVE) {
3990 /* TDLS can't be set, ... */
3991 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))
3992 return -EINVAL;
3993 /*
3994 * ... but don't bother the driver with it. This works around
3995 * a hostapd/wpa_supplicant issue -- it always includes the
3996 * TLDS_PEER flag in the mask even for AP mode.
3997 */
3998 params->sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
3999 }
4000
4001 if (statype != CFG80211_STA_TDLS_PEER_SETUP) {
4002 /* reject other things that can't change */
4003 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD)
4004 return -EINVAL;
4005 if (params->sta_modify_mask & STATION_PARAM_APPLY_CAPABILITY)
4006 return -EINVAL;
4007 if (params->supported_rates)
4008 return -EINVAL;
4009 if (params->ext_capab || params->ht_capa || params->vht_capa)
4010 return -EINVAL;
4011 }
4012
4013 if (statype != CFG80211_STA_AP_CLIENT) {
4014 if (params->vlan)
4015 return -EINVAL;
4016 }
4017
4018 switch (statype) {
4019 case CFG80211_STA_AP_MLME_CLIENT:
4020 /* Use this only for authorizing/unauthorizing a station */
4021 if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
4022 return -EOPNOTSUPP;
4023 break;
4024 case CFG80211_STA_AP_CLIENT:
4025 /* accept only the listed bits */
4026 if (params->sta_flags_mask &
4027 ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4028 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4029 BIT(NL80211_STA_FLAG_ASSOCIATED) |
4030 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
4031 BIT(NL80211_STA_FLAG_WME) |
4032 BIT(NL80211_STA_FLAG_MFP)))
4033 return -EINVAL;
4034
4035 /* but authenticated/associated only if driver handles it */
4036 if (!(wiphy->features & NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4037 params->sta_flags_mask &
4038 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4039 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4040 return -EINVAL;
4041 break;
4042 case CFG80211_STA_IBSS:
4043 case CFG80211_STA_AP_STA:
4044 /* reject any changes other than AUTHORIZED */
4045 if (params->sta_flags_mask & ~BIT(NL80211_STA_FLAG_AUTHORIZED))
4046 return -EINVAL;
4047 break;
4048 case CFG80211_STA_TDLS_PEER_SETUP:
4049 /* reject any changes other than AUTHORIZED or WME */
4050 if (params->sta_flags_mask & ~(BIT(NL80211_STA_FLAG_AUTHORIZED) |
4051 BIT(NL80211_STA_FLAG_WME)))
4052 return -EINVAL;
4053 /* force (at least) rates when authorizing */
4054 if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED) &&
4055 !params->supported_rates)
4056 return -EINVAL;
4057 break;
4058 case CFG80211_STA_TDLS_PEER_ACTIVE:
4059 /* reject any changes */
4060 return -EINVAL;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004061 case CFG80211_STA_MESH_PEER_KERNEL:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004062 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE)
4063 return -EINVAL;
4064 break;
Thomas Pederseneef941e2013-03-04 13:06:11 -08004065 case CFG80211_STA_MESH_PEER_USER:
Chun-Yeow Yeoh42925042015-04-18 01:30:02 +08004066 if (params->plink_action != NL80211_PLINK_ACTION_NO_ACTION &&
4067 params->plink_action != NL80211_PLINK_ACTION_BLOCK)
Johannes Berg77ee7c82013-02-15 00:48:33 +01004068 return -EINVAL;
4069 break;
4070 }
4071
4072 return 0;
4073}
4074EXPORT_SYMBOL(cfg80211_check_station_change);
4075
Johannes Berg5727ef12007-12-19 02:03:34 +01004076/*
Felix Fietkauc258d2d2009-11-11 17:23:31 +01004077 * Get vlan interface making sure it is running and on the right wiphy.
Johannes Berg5727ef12007-12-19 02:03:34 +01004078 */
Johannes Berg80b99892011-11-18 16:23:01 +01004079static struct net_device *get_vlan(struct genl_info *info,
4080 struct cfg80211_registered_device *rdev)
Johannes Berg5727ef12007-12-19 02:03:34 +01004081{
Johannes Berg463d0182009-07-14 00:33:35 +02004082 struct nlattr *vlanattr = info->attrs[NL80211_ATTR_STA_VLAN];
Johannes Berg80b99892011-11-18 16:23:01 +01004083 struct net_device *v;
4084 int ret;
Johannes Berg5727ef12007-12-19 02:03:34 +01004085
Johannes Berg80b99892011-11-18 16:23:01 +01004086 if (!vlanattr)
4087 return NULL;
4088
4089 v = dev_get_by_index(genl_info_net(info), nla_get_u32(vlanattr));
4090 if (!v)
4091 return ERR_PTR(-ENODEV);
4092
4093 if (!v->ieee80211_ptr || v->ieee80211_ptr->wiphy != &rdev->wiphy) {
4094 ret = -EINVAL;
4095 goto error;
Johannes Berg5727ef12007-12-19 02:03:34 +01004096 }
Johannes Berg80b99892011-11-18 16:23:01 +01004097
Johannes Berg77ee7c82013-02-15 00:48:33 +01004098 if (v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
4099 v->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
4100 v->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO) {
4101 ret = -EINVAL;
4102 goto error;
4103 }
4104
Johannes Berg80b99892011-11-18 16:23:01 +01004105 if (!netif_running(v)) {
4106 ret = -ENETDOWN;
4107 goto error;
4108 }
4109
4110 return v;
4111 error:
4112 dev_put(v);
4113 return ERR_PTR(ret);
Johannes Berg5727ef12007-12-19 02:03:34 +01004114}
4115
Johannes Berg94e860f2014-01-20 23:58:15 +01004116static const struct nla_policy
4117nl80211_sta_wme_policy[NL80211_STA_WME_MAX + 1] = {
Jouni Malinendf881292013-02-14 21:10:54 +02004118 [NL80211_STA_WME_UAPSD_QUEUES] = { .type = NLA_U8 },
4119 [NL80211_STA_WME_MAX_SP] = { .type = NLA_U8 },
4120};
4121
Johannes Bergff276692013-02-15 00:09:01 +01004122static int nl80211_parse_sta_wme(struct genl_info *info,
4123 struct station_parameters *params)
Jouni Malinendf881292013-02-14 21:10:54 +02004124{
Jouni Malinendf881292013-02-14 21:10:54 +02004125 struct nlattr *tb[NL80211_STA_WME_MAX + 1];
4126 struct nlattr *nla;
4127 int err;
4128
Jouni Malinendf881292013-02-14 21:10:54 +02004129 /* parse WME attributes if present */
4130 if (!info->attrs[NL80211_ATTR_STA_WME])
4131 return 0;
4132
4133 nla = info->attrs[NL80211_ATTR_STA_WME];
4134 err = nla_parse_nested(tb, NL80211_STA_WME_MAX, nla,
4135 nl80211_sta_wme_policy);
4136 if (err)
4137 return err;
4138
4139 if (tb[NL80211_STA_WME_UAPSD_QUEUES])
4140 params->uapsd_queues = nla_get_u8(
4141 tb[NL80211_STA_WME_UAPSD_QUEUES]);
4142 if (params->uapsd_queues & ~IEEE80211_WMM_IE_STA_QOSINFO_AC_MASK)
4143 return -EINVAL;
4144
4145 if (tb[NL80211_STA_WME_MAX_SP])
4146 params->max_sp = nla_get_u8(tb[NL80211_STA_WME_MAX_SP]);
4147
4148 if (params->max_sp & ~IEEE80211_WMM_IE_STA_QOSINFO_SP_MASK)
4149 return -EINVAL;
4150
4151 params->sta_modify_mask |= STATION_PARAM_APPLY_UAPSD;
4152
4153 return 0;
4154}
4155
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304156static int nl80211_parse_sta_channel_info(struct genl_info *info,
4157 struct station_parameters *params)
4158{
4159 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]) {
4160 params->supported_channels =
4161 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4162 params->supported_channels_len =
4163 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_CHANNELS]);
4164 /*
4165 * Need to include at least one (first channel, number of
4166 * channels) tuple for each subband, and must have proper
4167 * tuples for the rest of the data as well.
4168 */
4169 if (params->supported_channels_len < 2)
4170 return -EINVAL;
4171 if (params->supported_channels_len % 2)
4172 return -EINVAL;
4173 }
4174
4175 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]) {
4176 params->supported_oper_classes =
4177 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4178 params->supported_oper_classes_len =
4179 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES]);
4180 /*
4181 * The value of the Length field of the Supported Operating
4182 * Classes element is between 2 and 253.
4183 */
4184 if (params->supported_oper_classes_len < 2 ||
4185 params->supported_oper_classes_len > 253)
4186 return -EINVAL;
4187 }
4188 return 0;
4189}
4190
Johannes Bergff276692013-02-15 00:09:01 +01004191static int nl80211_set_station_tdls(struct genl_info *info,
4192 struct station_parameters *params)
4193{
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304194 int err;
Johannes Bergff276692013-02-15 00:09:01 +01004195 /* Dummy STA entry gets updated once the peer capabilities are known */
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004196 if (info->attrs[NL80211_ATTR_PEER_AID])
4197 params->aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Johannes Bergff276692013-02-15 00:09:01 +01004198 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4199 params->ht_capa =
4200 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
4201 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4202 params->vht_capa =
4203 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4204
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304205 err = nl80211_parse_sta_channel_info(info, params);
4206 if (err)
4207 return err;
4208
Johannes Bergff276692013-02-15 00:09:01 +01004209 return nl80211_parse_sta_wme(info, params);
4210}
4211
Johannes Berg5727ef12007-12-19 02:03:34 +01004212static int nl80211_set_station(struct sk_buff *skb, struct genl_info *info)
4213{
Johannes Berg4c476992010-10-04 21:36:35 +02004214 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02004215 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004216 struct station_parameters params;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004217 u8 *mac_addr;
4218 int err;
Johannes Berg5727ef12007-12-19 02:03:34 +01004219
4220 memset(&params, 0, sizeof(params));
4221
4222 params.listen_interval = -1;
4223
Johannes Berg77ee7c82013-02-15 00:48:33 +01004224 if (!rdev->ops->change_station)
4225 return -EOPNOTSUPP;
4226
Johannes Berg5727ef12007-12-19 02:03:34 +01004227 if (info->attrs[NL80211_ATTR_STA_AID])
4228 return -EINVAL;
4229
4230 if (!info->attrs[NL80211_ATTR_MAC])
4231 return -EINVAL;
4232
4233 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4234
4235 if (info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]) {
4236 params.supported_rates =
4237 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4238 params.supported_rates_len =
4239 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4240 }
4241
Jouni Malinen9d62a982013-02-14 21:10:13 +02004242 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4243 params.capability =
4244 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4245 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4246 }
4247
4248 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4249 params.ext_capab =
4250 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4251 params.ext_capab_len =
4252 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4253 }
4254
Jouni Malinendf881292013-02-14 21:10:54 +02004255 if (info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
Johannes Bergba23d202012-12-27 17:32:09 +01004256 return -EINVAL;
Jouni Malinen36aedc92008-08-25 11:58:58 +03004257
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004258 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004259 return -EINVAL;
4260
Johannes Bergf8bacc22013-02-14 23:27:01 +01004261 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004262 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004263 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4264 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4265 return -EINVAL;
4266 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004267
Johannes Bergf8bacc22013-02-14 23:27:01 +01004268 if (info->attrs[NL80211_ATTR_STA_PLINK_STATE]) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07004269 params.plink_state =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004270 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_STATE]);
4271 if (params.plink_state >= NUM_NL80211_PLINK_STATES)
4272 return -EINVAL;
4273 params.sta_modify_mask |= STATION_PARAM_APPLY_PLINK_STATE;
4274 }
Javier Cardona9c3990a2011-05-03 16:57:11 -07004275
Marco Porsch3b1c5a52013-01-07 16:04:52 +01004276 if (info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]) {
4277 enum nl80211_mesh_power_mode pm = nla_get_u32(
4278 info->attrs[NL80211_ATTR_LOCAL_MESH_POWER_MODE]);
4279
4280 if (pm <= NL80211_MESH_POWER_UNKNOWN ||
4281 pm > NL80211_MESH_POWER_MAX)
4282 return -EINVAL;
4283
4284 params.local_pm = pm;
4285 }
4286
Johannes Berg77ee7c82013-02-15 00:48:33 +01004287 /* Include parameters for TDLS peer (will check later) */
4288 err = nl80211_set_station_tdls(info, &params);
4289 if (err)
4290 return err;
4291
4292 params.vlan = get_vlan(info, rdev);
4293 if (IS_ERR(params.vlan))
4294 return PTR_ERR(params.vlan);
4295
Johannes Berga97f4422009-06-18 17:23:43 +02004296 switch (dev->ieee80211_ptr->iftype) {
4297 case NL80211_IFTYPE_AP:
4298 case NL80211_IFTYPE_AP_VLAN:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004299 case NL80211_IFTYPE_P2P_GO:
Johannes Berg074ac8d2010-09-16 14:58:22 +02004300 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berga97f4422009-06-18 17:23:43 +02004301 case NL80211_IFTYPE_STATION:
Antonio Quartulli267335d2012-01-31 20:25:47 +01004302 case NL80211_IFTYPE_ADHOC:
Johannes Berga97f4422009-06-18 17:23:43 +02004303 case NL80211_IFTYPE_MESH_POINT:
Johannes Berga97f4422009-06-18 17:23:43 +02004304 break;
4305 default:
Johannes Berg77ee7c82013-02-15 00:48:33 +01004306 err = -EOPNOTSUPP;
4307 goto out_put_vlan;
Johannes Berg034d6552009-05-27 10:35:29 +02004308 }
4309
Johannes Berg77ee7c82013-02-15 00:48:33 +01004310 /* driver will call cfg80211_check_station_change() */
Hila Gonene35e4d22012-06-27 17:19:42 +03004311 err = rdev_change_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004312
Johannes Berg77ee7c82013-02-15 00:48:33 +01004313 out_put_vlan:
Johannes Berg5727ef12007-12-19 02:03:34 +01004314 if (params.vlan)
4315 dev_put(params.vlan);
Johannes Berg3b858752009-03-12 09:55:09 +01004316
Johannes Berg5727ef12007-12-19 02:03:34 +01004317 return err;
4318}
4319
4320static int nl80211_new_station(struct sk_buff *skb, struct genl_info *info)
4321{
Johannes Berg4c476992010-10-04 21:36:35 +02004322 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg5727ef12007-12-19 02:03:34 +01004323 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004324 struct net_device *dev = info->user_ptr[1];
Johannes Berg5727ef12007-12-19 02:03:34 +01004325 struct station_parameters params;
4326 u8 *mac_addr = NULL;
4327
4328 memset(&params, 0, sizeof(params));
4329
Johannes Berg984c3112013-02-14 23:43:25 +01004330 if (!rdev->ops->add_station)
4331 return -EOPNOTSUPP;
4332
Johannes Berg5727ef12007-12-19 02:03:34 +01004333 if (!info->attrs[NL80211_ATTR_MAC])
4334 return -EINVAL;
4335
Johannes Berg5727ef12007-12-19 02:03:34 +01004336 if (!info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL])
4337 return -EINVAL;
4338
4339 if (!info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES])
4340 return -EINVAL;
4341
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004342 if (!info->attrs[NL80211_ATTR_STA_AID] &&
4343 !info->attrs[NL80211_ATTR_PEER_AID])
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004344 return -EINVAL;
4345
Johannes Berg5727ef12007-12-19 02:03:34 +01004346 mac_addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
4347 params.supported_rates =
4348 nla_data(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4349 params.supported_rates_len =
4350 nla_len(info->attrs[NL80211_ATTR_STA_SUPPORTED_RATES]);
4351 params.listen_interval =
4352 nla_get_u16(info->attrs[NL80211_ATTR_STA_LISTEN_INTERVAL]);
Johannes Berg51b50fb2009-05-24 16:42:30 +02004353
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004354 if (info->attrs[NL80211_ATTR_PEER_AID])
Jouni Malinen5e4b6f52013-05-16 20:11:08 +03004355 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_PEER_AID]);
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004356 else
4357 params.aid = nla_get_u16(info->attrs[NL80211_ATTR_STA_AID]);
Thadeu Lima de Souza Cascardo0e956c12010-02-12 12:34:50 -02004358 if (!params.aid || params.aid > IEEE80211_MAX_AID)
4359 return -EINVAL;
Johannes Berg51b50fb2009-05-24 16:42:30 +02004360
Jouni Malinen9d62a982013-02-14 21:10:13 +02004361 if (info->attrs[NL80211_ATTR_STA_CAPABILITY]) {
4362 params.capability =
4363 nla_get_u16(info->attrs[NL80211_ATTR_STA_CAPABILITY]);
4364 params.sta_modify_mask |= STATION_PARAM_APPLY_CAPABILITY;
4365 }
4366
4367 if (info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]) {
4368 params.ext_capab =
4369 nla_data(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4370 params.ext_capab_len =
4371 nla_len(info->attrs[NL80211_ATTR_STA_EXT_CAPABILITY]);
4372 }
4373
Jouni Malinen36aedc92008-08-25 11:58:58 +03004374 if (info->attrs[NL80211_ATTR_HT_CAPABILITY])
4375 params.ht_capa =
4376 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004377
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00004378 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY])
4379 params.vht_capa =
4380 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]);
4381
Marek Kwaczynski60f4a7b2013-12-03 10:04:59 +01004382 if (info->attrs[NL80211_ATTR_OPMODE_NOTIF]) {
4383 params.opmode_notif_used = true;
4384 params.opmode_notif =
4385 nla_get_u8(info->attrs[NL80211_ATTR_OPMODE_NOTIF]);
4386 }
4387
Johannes Bergf8bacc22013-02-14 23:27:01 +01004388 if (info->attrs[NL80211_ATTR_STA_PLINK_ACTION]) {
Javier Cardona96b78df2011-04-07 15:08:33 -07004389 params.plink_action =
Johannes Bergf8bacc22013-02-14 23:27:01 +01004390 nla_get_u8(info->attrs[NL80211_ATTR_STA_PLINK_ACTION]);
4391 if (params.plink_action >= NUM_NL80211_PLINK_ACTIONS)
4392 return -EINVAL;
4393 }
Javier Cardona96b78df2011-04-07 15:08:33 -07004394
Sunil Duttc01fc9a2013-10-09 20:45:21 +05304395 err = nl80211_parse_sta_channel_info(info, &params);
4396 if (err)
4397 return err;
4398
Johannes Bergff276692013-02-15 00:09:01 +01004399 err = nl80211_parse_sta_wme(info, &params);
4400 if (err)
4401 return err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004402
Johannes Bergbdd3ae32012-01-02 13:30:03 +01004403 if (parse_station_flags(info, dev->ieee80211_ptr->iftype, &params))
Johannes Berg5727ef12007-12-19 02:03:34 +01004404 return -EINVAL;
4405
Johannes Berg496fcc22015-03-12 08:53:27 +02004406 /* HT/VHT requires QoS, but if we don't have that just ignore HT/VHT
4407 * as userspace might just pass through the capabilities from the IEs
4408 * directly, rather than enforcing this restriction and returning an
4409 * error in this case.
4410 */
4411 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME))) {
4412 params.ht_capa = NULL;
4413 params.vht_capa = NULL;
4414 }
4415
Johannes Berg77ee7c82013-02-15 00:48:33 +01004416 /* When you run into this, adjust the code below for the new flag */
4417 BUILD_BUG_ON(NL80211_STA_FLAG_MAX != 7);
4418
Johannes Bergbdd90d52011-12-14 12:20:27 +01004419 switch (dev->ieee80211_ptr->iftype) {
4420 case NL80211_IFTYPE_AP:
4421 case NL80211_IFTYPE_AP_VLAN:
4422 case NL80211_IFTYPE_P2P_GO:
Johannes Berg984c3112013-02-14 23:43:25 +01004423 /* ignore WME attributes if iface/sta is not capable */
4424 if (!(rdev->wiphy.flags & WIPHY_FLAG_AP_UAPSD) ||
4425 !(params.sta_flags_set & BIT(NL80211_STA_FLAG_WME)))
4426 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004427
Johannes Bergbdd90d52011-12-14 12:20:27 +01004428 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004429 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4430 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004431 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004432 /* but don't bother the driver with it */
4433 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_TDLS_PEER);
Eliad Pellerc75786c2011-08-23 14:37:46 +03004434
Johannes Bergd582cff2012-10-26 17:53:44 +02004435 /* allow authenticated/associated only if driver handles it */
4436 if (!(rdev->wiphy.features &
4437 NL80211_FEATURE_FULL_AP_CLIENT_STATE) &&
4438 params.sta_flags_mask &
4439 (BIT(NL80211_STA_FLAG_AUTHENTICATED) |
4440 BIT(NL80211_STA_FLAG_ASSOCIATED)))
4441 return -EINVAL;
4442
Johannes Bergbdd90d52011-12-14 12:20:27 +01004443 /* must be last in here for error handling */
4444 params.vlan = get_vlan(info, rdev);
4445 if (IS_ERR(params.vlan))
4446 return PTR_ERR(params.vlan);
4447 break;
4448 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg984c3112013-02-14 23:43:25 +01004449 /* ignore uAPSD data */
4450 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4451
Johannes Bergd582cff2012-10-26 17:53:44 +02004452 /* associated is disallowed */
4453 if (params.sta_flags_mask & BIT(NL80211_STA_FLAG_ASSOCIATED))
4454 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004455 /* TDLS peers cannot be added */
Jouni Malinen3d124ea2013-05-27 18:24:02 +03004456 if ((params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) ||
4457 info->attrs[NL80211_ATTR_PEER_AID])
Johannes Berg4319e192011-09-07 11:50:48 +02004458 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004459 break;
4460 case NL80211_IFTYPE_STATION:
Johannes Berg93d08f02013-03-04 09:29:46 +01004461 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg984c3112013-02-14 23:43:25 +01004462 /* ignore uAPSD data */
4463 params.sta_modify_mask &= ~STATION_PARAM_APPLY_UAPSD;
4464
Johannes Berg77ee7c82013-02-15 00:48:33 +01004465 /* these are disallowed */
4466 if (params.sta_flags_mask &
4467 (BIT(NL80211_STA_FLAG_ASSOCIATED) |
4468 BIT(NL80211_STA_FLAG_AUTHENTICATED)))
Johannes Bergd582cff2012-10-26 17:53:44 +02004469 return -EINVAL;
Johannes Bergbdd90d52011-12-14 12:20:27 +01004470 /* Only TDLS peers can be added */
4471 if (!(params.sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)))
4472 return -EINVAL;
4473 /* Can only add if TDLS ... */
4474 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS))
4475 return -EOPNOTSUPP;
4476 /* ... with external setup is supported */
4477 if (!(rdev->wiphy.flags & WIPHY_FLAG_TDLS_EXTERNAL_SETUP))
4478 return -EOPNOTSUPP;
Johannes Berg77ee7c82013-02-15 00:48:33 +01004479 /*
4480 * Older wpa_supplicant versions always mark the TDLS peer
4481 * as authorized, but it shouldn't yet be.
4482 */
4483 params.sta_flags_mask &= ~BIT(NL80211_STA_FLAG_AUTHORIZED);
Johannes Bergbdd90d52011-12-14 12:20:27 +01004484 break;
4485 default:
4486 return -EOPNOTSUPP;
Eliad Pellerc75786c2011-08-23 14:37:46 +03004487 }
4488
Johannes Bergbdd90d52011-12-14 12:20:27 +01004489 /* be aware of params.vlan when changing code here */
Johannes Berg5727ef12007-12-19 02:03:34 +01004490
Hila Gonene35e4d22012-06-27 17:19:42 +03004491 err = rdev_add_station(rdev, dev, mac_addr, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004492
Johannes Berg5727ef12007-12-19 02:03:34 +01004493 if (params.vlan)
4494 dev_put(params.vlan);
Johannes Berg5727ef12007-12-19 02:03:34 +01004495 return err;
4496}
4497
4498static int nl80211_del_station(struct sk_buff *skb, struct genl_info *info)
4499{
Johannes Berg4c476992010-10-04 21:36:35 +02004500 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4501 struct net_device *dev = info->user_ptr[1];
Jouni Malinen89c771e2014-10-10 20:52:40 +03004502 struct station_del_parameters params;
4503
4504 memset(&params, 0, sizeof(params));
Johannes Berg5727ef12007-12-19 02:03:34 +01004505
4506 if (info->attrs[NL80211_ATTR_MAC])
Jouni Malinen89c771e2014-10-10 20:52:40 +03004507 params.mac = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg5727ef12007-12-19 02:03:34 +01004508
Johannes Berge80cf852009-05-11 14:43:13 +02004509 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Marco Porschd5d9de02010-03-30 10:00:16 +02004510 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP_VLAN &&
Johannes Berg074ac8d2010-09-16 14:58:22 +02004511 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
Johannes Berg4c476992010-10-04 21:36:35 +02004512 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4513 return -EINVAL;
Johannes Berge80cf852009-05-11 14:43:13 +02004514
Johannes Berg4c476992010-10-04 21:36:35 +02004515 if (!rdev->ops->del_station)
4516 return -EOPNOTSUPP;
Johannes Berg5727ef12007-12-19 02:03:34 +01004517
Jouni Malinen98856862014-10-20 13:20:45 +03004518 if (info->attrs[NL80211_ATTR_MGMT_SUBTYPE]) {
4519 params.subtype =
4520 nla_get_u8(info->attrs[NL80211_ATTR_MGMT_SUBTYPE]);
4521 if (params.subtype != IEEE80211_STYPE_DISASSOC >> 4 &&
4522 params.subtype != IEEE80211_STYPE_DEAUTH >> 4)
4523 return -EINVAL;
4524 } else {
4525 /* Default to Deauthentication frame */
4526 params.subtype = IEEE80211_STYPE_DEAUTH >> 4;
4527 }
4528
4529 if (info->attrs[NL80211_ATTR_REASON_CODE]) {
4530 params.reason_code =
4531 nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
4532 if (params.reason_code == 0)
4533 return -EINVAL; /* 0 is reserved */
4534 } else {
4535 /* Default to reason code 2 */
4536 params.reason_code = WLAN_REASON_PREV_AUTH_NOT_VALID;
4537 }
4538
Jouni Malinen89c771e2014-10-10 20:52:40 +03004539 return rdev_del_station(rdev, dev, &params);
Johannes Berg5727ef12007-12-19 02:03:34 +01004540}
4541
Eric W. Biederman15e47302012-09-07 20:12:54 +00004542static int nl80211_send_mpath(struct sk_buff *msg, u32 portid, u32 seq,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004543 int flags, struct net_device *dev,
4544 u8 *dst, u8 *next_hop,
4545 struct mpath_info *pinfo)
4546{
4547 void *hdr;
4548 struct nlattr *pinfoattr;
4549
Henning Rogge1ef4c852014-11-04 16:14:58 +01004550 hdr = nl80211hdr_put(msg, portid, seq, flags, NL80211_CMD_NEW_MPATH);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004551 if (!hdr)
4552 return -1;
4553
David S. Miller9360ffd2012-03-29 04:41:26 -04004554 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
4555 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
4556 nla_put(msg, NL80211_ATTR_MPATH_NEXT_HOP, ETH_ALEN, next_hop) ||
4557 nla_put_u32(msg, NL80211_ATTR_GENERATION, pinfo->generation))
4558 goto nla_put_failure;
Johannes Bergf5ea9122009-08-07 16:17:38 +02004559
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004560 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MPATH_INFO);
4561 if (!pinfoattr)
4562 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04004563 if ((pinfo->filled & MPATH_INFO_FRAME_QLEN) &&
4564 nla_put_u32(msg, NL80211_MPATH_INFO_FRAME_QLEN,
4565 pinfo->frame_qlen))
4566 goto nla_put_failure;
4567 if (((pinfo->filled & MPATH_INFO_SN) &&
4568 nla_put_u32(msg, NL80211_MPATH_INFO_SN, pinfo->sn)) ||
4569 ((pinfo->filled & MPATH_INFO_METRIC) &&
4570 nla_put_u32(msg, NL80211_MPATH_INFO_METRIC,
4571 pinfo->metric)) ||
4572 ((pinfo->filled & MPATH_INFO_EXPTIME) &&
4573 nla_put_u32(msg, NL80211_MPATH_INFO_EXPTIME,
4574 pinfo->exptime)) ||
4575 ((pinfo->filled & MPATH_INFO_FLAGS) &&
4576 nla_put_u8(msg, NL80211_MPATH_INFO_FLAGS,
4577 pinfo->flags)) ||
4578 ((pinfo->filled & MPATH_INFO_DISCOVERY_TIMEOUT) &&
4579 nla_put_u32(msg, NL80211_MPATH_INFO_DISCOVERY_TIMEOUT,
4580 pinfo->discovery_timeout)) ||
4581 ((pinfo->filled & MPATH_INFO_DISCOVERY_RETRIES) &&
4582 nla_put_u8(msg, NL80211_MPATH_INFO_DISCOVERY_RETRIES,
4583 pinfo->discovery_retries)))
4584 goto nla_put_failure;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004585
4586 nla_nest_end(msg, pinfoattr);
4587
Johannes Berg053c0952015-01-16 22:09:00 +01004588 genlmsg_end(msg, hdr);
4589 return 0;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004590
4591 nla_put_failure:
Thomas Grafbc3ed282008-06-03 16:36:54 -07004592 genlmsg_cancel(msg, hdr);
4593 return -EMSGSIZE;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004594}
4595
4596static int nl80211_dump_mpath(struct sk_buff *skb,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004597 struct netlink_callback *cb)
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004598{
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004599 struct mpath_info pinfo;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004600 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02004601 struct wireless_dev *wdev;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004602 u8 dst[ETH_ALEN];
4603 u8 next_hop[ETH_ALEN];
Johannes Berg97990a02013-04-19 01:02:55 +02004604 int path_idx = cb->args[2];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004605 int err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004606
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004607 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02004608 if (err)
4609 return err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004610
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004611 if (!rdev->ops->dump_mpath) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004612 err = -EOPNOTSUPP;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004613 goto out_err;
4614 }
4615
Johannes Berg97990a02013-04-19 01:02:55 +02004616 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
Jouni Malineneec60b02009-03-20 21:21:19 +02004617 err = -EOPNOTSUPP;
Roel Kluin0448b5f2009-08-22 21:15:49 +02004618 goto out_err;
Jouni Malineneec60b02009-03-20 21:21:19 +02004619 }
4620
Johannes Bergbba95fe2008-07-29 13:22:51 +02004621 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004622 err = rdev_dump_mpath(rdev, wdev->netdev, path_idx, dst,
Johannes Berg97990a02013-04-19 01:02:55 +02004623 next_hop, &pinfo);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004624 if (err == -ENOENT)
4625 break;
4626 if (err)
Johannes Berg3b858752009-03-12 09:55:09 +01004627 goto out_err;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004628
Eric W. Biederman15e47302012-09-07 20:12:54 +00004629 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004630 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg97990a02013-04-19 01:02:55 +02004631 wdev->netdev, dst, next_hop,
Johannes Bergbba95fe2008-07-29 13:22:51 +02004632 &pinfo) < 0)
4633 goto out;
4634
4635 path_idx++;
4636 }
4637
4638
4639 out:
Johannes Berg97990a02013-04-19 01:02:55 +02004640 cb->args[2] = path_idx;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004641 err = skb->len;
Johannes Bergbba95fe2008-07-29 13:22:51 +02004642 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08004643 nl80211_finish_wdev_dump(rdev);
Johannes Bergbba95fe2008-07-29 13:22:51 +02004644 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004645}
4646
4647static int nl80211_get_mpath(struct sk_buff *skb, struct genl_info *info)
4648{
Johannes Berg4c476992010-10-04 21:36:35 +02004649 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004650 int err;
Johannes Berg4c476992010-10-04 21:36:35 +02004651 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004652 struct mpath_info pinfo;
4653 struct sk_buff *msg;
4654 u8 *dst = NULL;
4655 u8 next_hop[ETH_ALEN];
4656
4657 memset(&pinfo, 0, sizeof(pinfo));
4658
4659 if (!info->attrs[NL80211_ATTR_MAC])
4660 return -EINVAL;
4661
4662 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4663
Johannes Berg4c476992010-10-04 21:36:35 +02004664 if (!rdev->ops->get_mpath)
4665 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004666
Johannes Berg4c476992010-10-04 21:36:35 +02004667 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4668 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004669
Hila Gonene35e4d22012-06-27 17:19:42 +03004670 err = rdev_get_mpath(rdev, dev, dst, next_hop, &pinfo);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004671 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02004672 return err;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004673
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07004674 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004675 if (!msg)
Johannes Berg4c476992010-10-04 21:36:35 +02004676 return -ENOMEM;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004677
Eric W. Biederman15e47302012-09-07 20:12:54 +00004678 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg4c476992010-10-04 21:36:35 +02004679 dev, dst, next_hop, &pinfo) < 0) {
4680 nlmsg_free(msg);
4681 return -ENOBUFS;
4682 }
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004683
Johannes Berg4c476992010-10-04 21:36:35 +02004684 return genlmsg_reply(msg, info);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004685}
4686
4687static int nl80211_set_mpath(struct sk_buff *skb, struct genl_info *info)
4688{
Johannes Berg4c476992010-10-04 21:36:35 +02004689 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4690 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004691 u8 *dst = NULL;
4692 u8 *next_hop = NULL;
4693
4694 if (!info->attrs[NL80211_ATTR_MAC])
4695 return -EINVAL;
4696
4697 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4698 return -EINVAL;
4699
4700 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4701 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4702
Johannes Berg4c476992010-10-04 21:36:35 +02004703 if (!rdev->ops->change_mpath)
4704 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004705
Johannes Berg4c476992010-10-04 21:36:35 +02004706 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4707 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004708
Hila Gonene35e4d22012-06-27 17:19:42 +03004709 return rdev_change_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004710}
Johannes Berg4c476992010-10-04 21:36:35 +02004711
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004712static int nl80211_new_mpath(struct sk_buff *skb, struct genl_info *info)
4713{
Johannes Berg4c476992010-10-04 21:36:35 +02004714 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4715 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004716 u8 *dst = NULL;
4717 u8 *next_hop = NULL;
4718
4719 if (!info->attrs[NL80211_ATTR_MAC])
4720 return -EINVAL;
4721
4722 if (!info->attrs[NL80211_ATTR_MPATH_NEXT_HOP])
4723 return -EINVAL;
4724
4725 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4726 next_hop = nla_data(info->attrs[NL80211_ATTR_MPATH_NEXT_HOP]);
4727
Johannes Berg4c476992010-10-04 21:36:35 +02004728 if (!rdev->ops->add_mpath)
4729 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004730
Johannes Berg4c476992010-10-04 21:36:35 +02004731 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4732 return -EOPNOTSUPP;
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004733
Hila Gonene35e4d22012-06-27 17:19:42 +03004734 return rdev_add_mpath(rdev, dev, dst, next_hop);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004735}
4736
4737static int nl80211_del_mpath(struct sk_buff *skb, struct genl_info *info)
4738{
Johannes Berg4c476992010-10-04 21:36:35 +02004739 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4740 struct net_device *dev = info->user_ptr[1];
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004741 u8 *dst = NULL;
4742
4743 if (info->attrs[NL80211_ATTR_MAC])
4744 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4745
Johannes Berg4c476992010-10-04 21:36:35 +02004746 if (!rdev->ops->del_mpath)
4747 return -EOPNOTSUPP;
Johannes Berg3b858752009-03-12 09:55:09 +01004748
Hila Gonene35e4d22012-06-27 17:19:42 +03004749 return rdev_del_mpath(rdev, dev, dst);
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +01004750}
4751
Henning Rogge66be7d22014-09-12 08:58:49 +02004752static int nl80211_get_mpp(struct sk_buff *skb, struct genl_info *info)
4753{
4754 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4755 int err;
4756 struct net_device *dev = info->user_ptr[1];
4757 struct mpath_info pinfo;
4758 struct sk_buff *msg;
4759 u8 *dst = NULL;
4760 u8 mpp[ETH_ALEN];
4761
4762 memset(&pinfo, 0, sizeof(pinfo));
4763
4764 if (!info->attrs[NL80211_ATTR_MAC])
4765 return -EINVAL;
4766
4767 dst = nla_data(info->attrs[NL80211_ATTR_MAC]);
4768
4769 if (!rdev->ops->get_mpp)
4770 return -EOPNOTSUPP;
4771
4772 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT)
4773 return -EOPNOTSUPP;
4774
4775 err = rdev_get_mpp(rdev, dev, dst, mpp, &pinfo);
4776 if (err)
4777 return err;
4778
4779 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
4780 if (!msg)
4781 return -ENOMEM;
4782
4783 if (nl80211_send_mpath(msg, info->snd_portid, info->snd_seq, 0,
4784 dev, dst, mpp, &pinfo) < 0) {
4785 nlmsg_free(msg);
4786 return -ENOBUFS;
4787 }
4788
4789 return genlmsg_reply(msg, info);
4790}
4791
4792static int nl80211_dump_mpp(struct sk_buff *skb,
4793 struct netlink_callback *cb)
4794{
4795 struct mpath_info pinfo;
4796 struct cfg80211_registered_device *rdev;
4797 struct wireless_dev *wdev;
4798 u8 dst[ETH_ALEN];
4799 u8 mpp[ETH_ALEN];
4800 int path_idx = cb->args[2];
4801 int err;
4802
4803 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
4804 if (err)
4805 return err;
4806
4807 if (!rdev->ops->dump_mpp) {
4808 err = -EOPNOTSUPP;
4809 goto out_err;
4810 }
4811
4812 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT) {
4813 err = -EOPNOTSUPP;
4814 goto out_err;
4815 }
4816
4817 while (1) {
4818 err = rdev_dump_mpp(rdev, wdev->netdev, path_idx, dst,
4819 mpp, &pinfo);
4820 if (err == -ENOENT)
4821 break;
4822 if (err)
4823 goto out_err;
4824
4825 if (nl80211_send_mpath(skb, NETLINK_CB(cb->skb).portid,
4826 cb->nlh->nlmsg_seq, NLM_F_MULTI,
4827 wdev->netdev, dst, mpp,
4828 &pinfo) < 0)
4829 goto out;
4830
4831 path_idx++;
4832 }
4833
4834 out:
4835 cb->args[2] = path_idx;
4836 err = skb->len;
4837 out_err:
4838 nl80211_finish_wdev_dump(rdev);
4839 return err;
4840}
4841
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004842static int nl80211_set_bss(struct sk_buff *skb, struct genl_info *info)
4843{
Johannes Berg4c476992010-10-04 21:36:35 +02004844 struct cfg80211_registered_device *rdev = info->user_ptr[0];
4845 struct net_device *dev = info->user_ptr[1];
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004846 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004847 struct bss_parameters params;
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004848 int err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004849
4850 memset(&params, 0, sizeof(params));
4851 /* default to not changing parameters */
4852 params.use_cts_prot = -1;
4853 params.use_short_preamble = -1;
4854 params.use_short_slot_time = -1;
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004855 params.ap_isolate = -1;
Helmut Schaa50b12f52010-11-19 12:40:25 +01004856 params.ht_opmode = -1;
Johannes Berg53cabad2012-11-14 15:17:28 +01004857 params.p2p_ctwindow = -1;
4858 params.p2p_opp_ps = -1;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004859
4860 if (info->attrs[NL80211_ATTR_BSS_CTS_PROT])
4861 params.use_cts_prot =
4862 nla_get_u8(info->attrs[NL80211_ATTR_BSS_CTS_PROT]);
4863 if (info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE])
4864 params.use_short_preamble =
4865 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_PREAMBLE]);
4866 if (info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME])
4867 params.use_short_slot_time =
4868 nla_get_u8(info->attrs[NL80211_ATTR_BSS_SHORT_SLOT_TIME]);
Jouni Malinen90c97a02008-10-30 16:59:22 +02004869 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
4870 params.basic_rates =
4871 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4872 params.basic_rates_len =
4873 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
4874 }
Felix Fietkaufd8aaaf2010-04-27 01:23:35 +02004875 if (info->attrs[NL80211_ATTR_AP_ISOLATE])
4876 params.ap_isolate = !!nla_get_u8(info->attrs[NL80211_ATTR_AP_ISOLATE]);
Helmut Schaa50b12f52010-11-19 12:40:25 +01004877 if (info->attrs[NL80211_ATTR_BSS_HT_OPMODE])
4878 params.ht_opmode =
4879 nla_get_u16(info->attrs[NL80211_ATTR_BSS_HT_OPMODE]);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004880
Johannes Berg53cabad2012-11-14 15:17:28 +01004881 if (info->attrs[NL80211_ATTR_P2P_CTWINDOW]) {
4882 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4883 return -EINVAL;
4884 params.p2p_ctwindow =
4885 nla_get_s8(info->attrs[NL80211_ATTR_P2P_CTWINDOW]);
4886 if (params.p2p_ctwindow < 0)
4887 return -EINVAL;
4888 if (params.p2p_ctwindow != 0 &&
4889 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_CTWIN))
4890 return -EINVAL;
4891 }
4892
4893 if (info->attrs[NL80211_ATTR_P2P_OPPPS]) {
4894 u8 tmp;
4895
4896 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4897 return -EINVAL;
4898 tmp = nla_get_u8(info->attrs[NL80211_ATTR_P2P_OPPPS]);
4899 if (tmp > 1)
4900 return -EINVAL;
4901 params.p2p_opp_ps = tmp;
4902 if (params.p2p_opp_ps &&
4903 !(rdev->wiphy.features & NL80211_FEATURE_P2P_GO_OPPPS))
4904 return -EINVAL;
4905 }
4906
Johannes Berg4c476992010-10-04 21:36:35 +02004907 if (!rdev->ops->change_bss)
4908 return -EOPNOTSUPP;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004909
Johannes Berg074ac8d2010-09-16 14:58:22 +02004910 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_AP &&
Johannes Berg4c476992010-10-04 21:36:35 +02004911 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_GO)
4912 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02004913
Simon Wunderlichc56589e2013-11-21 18:19:49 +01004914 wdev_lock(wdev);
4915 err = rdev_change_bss(rdev, dev, &params);
4916 wdev_unlock(wdev);
4917
4918 return err;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004919}
4920
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00004921static const struct nla_policy reg_rule_policy[NL80211_REG_RULE_ATTR_MAX + 1] = {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004922 [NL80211_ATTR_REG_RULE_FLAGS] = { .type = NLA_U32 },
4923 [NL80211_ATTR_FREQ_RANGE_START] = { .type = NLA_U32 },
4924 [NL80211_ATTR_FREQ_RANGE_END] = { .type = NLA_U32 },
4925 [NL80211_ATTR_FREQ_RANGE_MAX_BW] = { .type = NLA_U32 },
4926 [NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN] = { .type = NLA_U32 },
4927 [NL80211_ATTR_POWER_RULE_MAX_EIRP] = { .type = NLA_U32 },
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004928 [NL80211_ATTR_DFS_CAC_TIME] = { .type = NLA_U32 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004929};
4930
4931static int parse_reg_rule(struct nlattr *tb[],
4932 struct ieee80211_reg_rule *reg_rule)
4933{
4934 struct ieee80211_freq_range *freq_range = &reg_rule->freq_range;
4935 struct ieee80211_power_rule *power_rule = &reg_rule->power_rule;
4936
4937 if (!tb[NL80211_ATTR_REG_RULE_FLAGS])
4938 return -EINVAL;
4939 if (!tb[NL80211_ATTR_FREQ_RANGE_START])
4940 return -EINVAL;
4941 if (!tb[NL80211_ATTR_FREQ_RANGE_END])
4942 return -EINVAL;
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004943 if (!tb[NL80211_ATTR_FREQ_RANGE_MAX_BW])
4944 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004945 if (!tb[NL80211_ATTR_POWER_RULE_MAX_EIRP])
4946 return -EINVAL;
4947
4948 reg_rule->flags = nla_get_u32(tb[NL80211_ATTR_REG_RULE_FLAGS]);
4949
4950 freq_range->start_freq_khz =
4951 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_START]);
4952 freq_range->end_freq_khz =
4953 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_END]);
Janusz Dziedzicb0dfd2e2014-02-20 13:52:16 +01004954 freq_range->max_bandwidth_khz =
4955 nla_get_u32(tb[NL80211_ATTR_FREQ_RANGE_MAX_BW]);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004956
4957 power_rule->max_eirp =
4958 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_EIRP]);
4959
4960 if (tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN])
4961 power_rule->max_antenna_gain =
4962 nla_get_u32(tb[NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN]);
4963
Janusz Dziedzic089027e2014-02-21 19:46:12 +01004964 if (tb[NL80211_ATTR_DFS_CAC_TIME])
4965 reg_rule->dfs_cac_ms =
4966 nla_get_u32(tb[NL80211_ATTR_DFS_CAC_TIME]);
4967
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004968 return 0;
4969}
4970
4971static int nl80211_req_set_reg(struct sk_buff *skb, struct genl_info *info)
4972{
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004973 char *data = NULL;
Ilan peer05050752015-03-04 00:32:06 -05004974 bool is_indoor;
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004975 enum nl80211_user_reg_hint_type user_reg_hint_type;
Ilan peer05050752015-03-04 00:32:06 -05004976 u32 owner_nlportid;
4977
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07004978
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004979 /*
4980 * You should only get this when cfg80211 hasn't yet initialized
4981 * completely when built-in to the kernel right between the time
4982 * window between nl80211_init() and regulatory_init(), if that is
4983 * even possible.
4984 */
Johannes Berg458f4f92012-12-06 15:47:38 +01004985 if (unlikely(!rcu_access_pointer(cfg80211_regdomain)))
Luis R. Rodriguezfe33eb32009-02-21 00:04:30 -05004986 return -EINPROGRESS;
Luis R. Rodriguez80778f12009-02-21 00:04:22 -05004987
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07004988 if (info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE])
4989 user_reg_hint_type =
4990 nla_get_u32(info->attrs[NL80211_ATTR_USER_REG_HINT_TYPE]);
4991 else
4992 user_reg_hint_type = NL80211_USER_REG_HINT_USER;
4993
4994 switch (user_reg_hint_type) {
4995 case NL80211_USER_REG_HINT_USER:
4996 case NL80211_USER_REG_HINT_CELL_BASE:
Ilan Peer52616f22014-02-25 16:26:00 +02004997 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
4998 return -EINVAL;
4999
5000 data = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5001 return regulatory_hint_user(data, user_reg_hint_type);
5002 case NL80211_USER_REG_HINT_INDOOR:
Ilan peer05050752015-03-04 00:32:06 -05005003 if (info->attrs[NL80211_ATTR_SOCKET_OWNER]) {
5004 owner_nlportid = info->snd_portid;
5005 is_indoor = !!info->attrs[NL80211_ATTR_REG_INDOOR];
5006 } else {
5007 owner_nlportid = 0;
5008 is_indoor = true;
5009 }
5010
5011 return regulatory_hint_indoor(is_indoor, owner_nlportid);
Luis R. Rodriguez57b5ce02012-07-12 11:49:18 -07005012 default:
5013 return -EINVAL;
5014 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005015}
5016
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005017static int nl80211_get_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005018 struct genl_info *info)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005019{
Johannes Berg4c476992010-10-04 21:36:35 +02005020 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02005021 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005022 struct wireless_dev *wdev = dev->ieee80211_ptr;
5023 struct mesh_config cur_params;
5024 int err = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005025 void *hdr;
5026 struct nlattr *pinfoattr;
5027 struct sk_buff *msg;
5028
Johannes Berg29cbe682010-12-03 09:20:44 +01005029 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5030 return -EOPNOTSUPP;
5031
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005032 if (!rdev->ops->get_mesh_config)
Johannes Berg4c476992010-10-04 21:36:35 +02005033 return -EOPNOTSUPP;
Jouni Malinenf3f92582009-03-20 17:57:36 +02005034
Johannes Berg29cbe682010-12-03 09:20:44 +01005035 wdev_lock(wdev);
5036 /* If not connected, get default parameters */
5037 if (!wdev->mesh_id_len)
5038 memcpy(&cur_params, &default_mesh_config, sizeof(cur_params));
5039 else
Hila Gonene35e4d22012-06-27 17:19:42 +03005040 err = rdev_get_mesh_config(rdev, dev, &cur_params);
Johannes Berg29cbe682010-12-03 09:20:44 +01005041 wdev_unlock(wdev);
5042
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005043 if (err)
Johannes Berg4c476992010-10-04 21:36:35 +02005044 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005045
5046 /* Draw up a netlink message to send back */
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -07005047 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02005048 if (!msg)
5049 return -ENOMEM;
Eric W. Biederman15e47302012-09-07 20:12:54 +00005050 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005051 NL80211_CMD_GET_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005052 if (!hdr)
Julia Lawallefe1cf02011-01-28 15:17:11 +01005053 goto out;
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005054 pinfoattr = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005055 if (!pinfoattr)
5056 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04005057 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
5058 nla_put_u16(msg, NL80211_MESHCONF_RETRY_TIMEOUT,
5059 cur_params.dot11MeshRetryTimeout) ||
5060 nla_put_u16(msg, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5061 cur_params.dot11MeshConfirmTimeout) ||
5062 nla_put_u16(msg, NL80211_MESHCONF_HOLDING_TIMEOUT,
5063 cur_params.dot11MeshHoldingTimeout) ||
5064 nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
5065 cur_params.dot11MeshMaxPeerLinks) ||
5066 nla_put_u8(msg, NL80211_MESHCONF_MAX_RETRIES,
5067 cur_params.dot11MeshMaxRetries) ||
5068 nla_put_u8(msg, NL80211_MESHCONF_TTL,
5069 cur_params.dot11MeshTTL) ||
5070 nla_put_u8(msg, NL80211_MESHCONF_ELEMENT_TTL,
5071 cur_params.element_ttl) ||
5072 nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5073 cur_params.auto_open_plinks) ||
John W. Linville7eab0f62012-04-12 14:25:14 -04005074 nla_put_u32(msg, NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5075 cur_params.dot11MeshNbrOffsetMaxNeighbor) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005076 nla_put_u8(msg, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5077 cur_params.dot11MeshHWMPmaxPREQretries) ||
5078 nla_put_u32(msg, NL80211_MESHCONF_PATH_REFRESH_TIME,
5079 cur_params.path_refresh_time) ||
5080 nla_put_u16(msg, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5081 cur_params.min_discovery_timeout) ||
5082 nla_put_u32(msg, NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5083 cur_params.dot11MeshHWMPactivePathTimeout) ||
5084 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
5085 cur_params.dot11MeshHWMPpreqMinInterval) ||
5086 nla_put_u16(msg, NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
5087 cur_params.dot11MeshHWMPperrMinInterval) ||
5088 nla_put_u16(msg, NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5089 cur_params.dot11MeshHWMPnetDiameterTraversalTime) ||
5090 nla_put_u8(msg, NL80211_MESHCONF_HWMP_ROOTMODE,
5091 cur_params.dot11MeshHWMPRootMode) ||
5092 nla_put_u16(msg, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
5093 cur_params.dot11MeshHWMPRannInterval) ||
5094 nla_put_u8(msg, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
5095 cur_params.dot11MeshGateAnnouncementProtocol) ||
5096 nla_put_u8(msg, NL80211_MESHCONF_FORWARDING,
5097 cur_params.dot11MeshForwarding) ||
5098 nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD,
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07005099 cur_params.rssi_threshold) ||
5100 nla_put_u32(msg, NL80211_MESHCONF_HT_OPMODE,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005101 cur_params.ht_opmode) ||
5102 nla_put_u32(msg, NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5103 cur_params.dot11MeshHWMPactivePathToRootTimeout) ||
5104 nla_put_u16(msg, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005105 cur_params.dot11MeshHWMProotInterval) ||
5106 nla_put_u16(msg, NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005107 cur_params.dot11MeshHWMPconfirmationInterval) ||
5108 nla_put_u32(msg, NL80211_MESHCONF_POWER_MODE,
5109 cur_params.power_mode) ||
5110 nla_put_u16(msg, NL80211_MESHCONF_AWAKE_WINDOW,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005111 cur_params.dot11MeshAwakeWindowDuration) ||
5112 nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
5113 cur_params.plink_timeout))
David S. Miller9360ffd2012-03-29 04:41:26 -04005114 goto nla_put_failure;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005115 nla_nest_end(msg, pinfoattr);
5116 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02005117 return genlmsg_reply(msg, info);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005118
Johannes Berg3b858752009-03-12 09:55:09 +01005119 nla_put_failure:
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005120 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005121 out:
Yuri Ershovd080e272010-06-29 15:08:07 +04005122 nlmsg_free(msg);
Johannes Berg4c476992010-10-04 21:36:35 +02005123 return -ENOBUFS;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005124}
5125
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00005126static const struct nla_policy nl80211_meshconf_params_policy[NL80211_MESHCONF_ATTR_MAX+1] = {
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005127 [NL80211_MESHCONF_RETRY_TIMEOUT] = { .type = NLA_U16 },
5128 [NL80211_MESHCONF_CONFIRM_TIMEOUT] = { .type = NLA_U16 },
5129 [NL80211_MESHCONF_HOLDING_TIMEOUT] = { .type = NLA_U16 },
5130 [NL80211_MESHCONF_MAX_PEER_LINKS] = { .type = NLA_U16 },
5131 [NL80211_MESHCONF_MAX_RETRIES] = { .type = NLA_U8 },
5132 [NL80211_MESHCONF_TTL] = { .type = NLA_U8 },
Javier Cardona45904f22010-12-03 09:20:40 +01005133 [NL80211_MESHCONF_ELEMENT_TTL] = { .type = NLA_U8 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005134 [NL80211_MESHCONF_AUTO_OPEN_PLINKS] = { .type = NLA_U8 },
Javier Cardonad299a1f2012-03-31 11:31:33 -07005135 [NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005136 [NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES] = { .type = NLA_U8 },
5137 [NL80211_MESHCONF_PATH_REFRESH_TIME] = { .type = NLA_U32 },
5138 [NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT] = { .type = NLA_U16 },
5139 [NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT] = { .type = NLA_U32 },
5140 [NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL] = { .type = NLA_U16 },
Thomas Pedersendca7e942011-11-24 17:15:24 -08005141 [NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL] = { .type = NLA_U16 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005142 [NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME] = { .type = NLA_U16 },
Javier Cardona699403d2011-08-09 16:45:09 -07005143 [NL80211_MESHCONF_HWMP_ROOTMODE] = { .type = NLA_U8 },
Javier Cardona0507e152011-08-09 16:45:10 -07005144 [NL80211_MESHCONF_HWMP_RANN_INTERVAL] = { .type = NLA_U16 },
Javier Cardona16dd7262011-08-09 16:45:11 -07005145 [NL80211_MESHCONF_GATE_ANNOUNCEMENTS] = { .type = NLA_U8 },
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08005146 [NL80211_MESHCONF_FORWARDING] = { .type = NLA_U8 },
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005147 [NL80211_MESHCONF_RSSI_THRESHOLD] = { .type = NLA_U32 },
5148 [NL80211_MESHCONF_HT_OPMODE] = { .type = NLA_U16 },
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005149 [NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT] = { .type = NLA_U32 },
5150 [NL80211_MESHCONF_HWMP_ROOT_INTERVAL] = { .type = NLA_U16 },
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005151 [NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL] = { .type = NLA_U16 },
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005152 [NL80211_MESHCONF_POWER_MODE] = { .type = NLA_U32 },
5153 [NL80211_MESHCONF_AWAKE_WINDOW] = { .type = NLA_U16 },
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005154 [NL80211_MESHCONF_PLINK_TIMEOUT] = { .type = NLA_U32 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005155};
5156
Javier Cardonac80d5452010-12-16 17:37:49 -08005157static const struct nla_policy
5158 nl80211_mesh_setup_params_policy[NL80211_MESH_SETUP_ATTR_MAX+1] = {
Javier Cardonad299a1f2012-03-31 11:31:33 -07005159 [NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC] = { .type = NLA_U8 },
Javier Cardonac80d5452010-12-16 17:37:49 -08005160 [NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL] = { .type = NLA_U8 },
5161 [NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC] = { .type = NLA_U8 },
Javier Cardona15d5dda2011-04-07 15:08:28 -07005162 [NL80211_MESH_SETUP_USERSPACE_AUTH] = { .type = NLA_FLAG },
Colleen Twitty6e16d902013-05-08 11:45:59 -07005163 [NL80211_MESH_SETUP_AUTH_PROTOCOL] = { .type = NLA_U8 },
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005164 [NL80211_MESH_SETUP_USERSPACE_MPM] = { .type = NLA_FLAG },
Javier Cardona581a8b02011-04-07 15:08:27 -07005165 [NL80211_MESH_SETUP_IE] = { .type = NLA_BINARY,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005166 .len = IEEE80211_MAX_DATA_LEN },
Javier Cardonab130e5c2011-05-03 16:57:07 -07005167 [NL80211_MESH_SETUP_USERSPACE_AMPE] = { .type = NLA_FLAG },
Javier Cardonac80d5452010-12-16 17:37:49 -08005168};
5169
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005170static int nl80211_parse_mesh_config(struct genl_info *info,
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005171 struct mesh_config *cfg,
5172 u32 *mask_out)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005173{
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005174 struct nlattr *tb[NL80211_MESHCONF_ATTR_MAX + 1];
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005175 u32 mask = 0;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005176
Marco Porschea54fba2013-01-07 16:04:48 +01005177#define FILL_IN_MESH_PARAM_IF_SET(tb, cfg, param, min, max, mask, attr, fn) \
5178do { \
5179 if (tb[attr]) { \
5180 if (fn(tb[attr]) < min || fn(tb[attr]) > max) \
5181 return -EINVAL; \
5182 cfg->param = fn(tb[attr]); \
5183 mask |= (1 << (attr - 1)); \
5184 } \
5185} while (0)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005186
5187
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005188 if (!info->attrs[NL80211_ATTR_MESH_CONFIG])
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005189 return -EINVAL;
5190 if (nla_parse_nested(tb, NL80211_MESHCONF_ATTR_MAX,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005191 info->attrs[NL80211_ATTR_MESH_CONFIG],
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005192 nl80211_meshconf_params_policy))
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005193 return -EINVAL;
5194
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005195 /* This makes sure that there aren't more than 32 mesh config
5196 * parameters (otherwise our bitfield scheme would not work.) */
5197 BUILD_BUG_ON(NL80211_MESHCONF_ATTR_MAX > 32);
5198
5199 /* Fill in the params struct */
Marco Porschea54fba2013-01-07 16:04:48 +01005200 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshRetryTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005201 mask, NL80211_MESHCONF_RETRY_TIMEOUT,
5202 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005203 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshConfirmTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005204 mask, NL80211_MESHCONF_CONFIRM_TIMEOUT,
5205 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005206 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHoldingTimeout, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005207 mask, NL80211_MESHCONF_HOLDING_TIMEOUT,
5208 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005209 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxPeerLinks, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005210 mask, NL80211_MESHCONF_MAX_PEER_LINKS,
5211 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005212 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshMaxRetries, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005213 mask, NL80211_MESHCONF_MAX_RETRIES,
5214 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005215 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshTTL, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005216 mask, NL80211_MESHCONF_TTL, nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005217 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, element_ttl, 1, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005218 mask, NL80211_MESHCONF_ELEMENT_TTL,
5219 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005220 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, auto_open_plinks, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005221 mask, NL80211_MESHCONF_AUTO_OPEN_PLINKS,
5222 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005223 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshNbrOffsetMaxNeighbor,
5224 1, 255, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005225 NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR,
5226 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005227 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPmaxPREQretries, 0, 255,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005228 mask, NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES,
5229 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005230 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, path_refresh_time, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005231 mask, NL80211_MESHCONF_PATH_REFRESH_TIME,
5232 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005233 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, min_discovery_timeout, 1, 65535,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005234 mask, NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT,
5235 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005236 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathTimeout,
5237 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005238 NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT,
5239 nla_get_u32);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005240 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPpreqMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005241 1, 65535, mask,
5242 NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005243 nla_get_u16);
Thomas Pedersendca7e942011-11-24 17:15:24 -08005244 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPperrMinInterval,
Marco Porschea54fba2013-01-07 16:04:48 +01005245 1, 65535, mask,
5246 NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005247 nla_get_u16);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005248 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005249 dot11MeshHWMPnetDiameterTraversalTime,
5250 1, 65535, mask,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005251 NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
5252 nla_get_u16);
Marco Porschea54fba2013-01-07 16:04:48 +01005253 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRootMode, 0, 4,
5254 mask, NL80211_MESHCONF_HWMP_ROOTMODE,
5255 nla_get_u8);
5256 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPRannInterval, 1, 65535,
5257 mask, NL80211_MESHCONF_HWMP_RANN_INTERVAL,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005258 nla_get_u16);
Rui Paulo63c57232009-11-09 23:46:57 +00005259 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005260 dot11MeshGateAnnouncementProtocol, 0, 1,
5261 mask, NL80211_MESHCONF_GATE_ANNOUNCEMENTS,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005262 nla_get_u8);
Marco Porschea54fba2013-01-07 16:04:48 +01005263 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshForwarding, 0, 1,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005264 mask, NL80211_MESHCONF_FORWARDING,
5265 nla_get_u8);
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005266 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, rssi_threshold, -255, 0,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005267 mask, NL80211_MESHCONF_RSSI_THRESHOLD,
Chun-Yeow Yeoh83374fe2013-07-11 18:24:03 +08005268 nla_get_s32);
Marco Porschea54fba2013-01-07 16:04:48 +01005269 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, ht_opmode, 0, 16,
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08005270 mask, NL80211_MESHCONF_HT_OPMODE,
5271 nla_get_u16);
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005272 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMPactivePathToRootTimeout,
Marco Porschea54fba2013-01-07 16:04:48 +01005273 1, 65535, mask,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005274 NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT,
5275 nla_get_u32);
Marco Porschea54fba2013-01-07 16:04:48 +01005276 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshHWMProotInterval, 1, 65535,
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08005277 mask, NL80211_MESHCONF_HWMP_ROOT_INTERVAL,
5278 nla_get_u16);
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005279 FILL_IN_MESH_PARAM_IF_SET(tb, cfg,
Marco Porschea54fba2013-01-07 16:04:48 +01005280 dot11MeshHWMPconfirmationInterval,
5281 1, 65535, mask,
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08005282 NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL,
5283 nla_get_u16);
Marco Porsch3b1c5a52013-01-07 16:04:52 +01005284 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, power_mode,
5285 NL80211_MESH_POWER_ACTIVE,
5286 NL80211_MESH_POWER_MAX,
5287 mask, NL80211_MESHCONF_POWER_MODE,
5288 nla_get_u32);
5289 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, dot11MeshAwakeWindowDuration,
5290 0, 65535, mask,
5291 NL80211_MESHCONF_AWAKE_WINDOW, nla_get_u16);
Masashi Honma31f909a2015-02-24 22:42:16 +09005292 FILL_IN_MESH_PARAM_IF_SET(tb, cfg, plink_timeout, 0, 0xffffffff,
Colleen Twitty8e7c0532013-06-03 09:53:39 -07005293 mask, NL80211_MESHCONF_PLINK_TIMEOUT,
5294 nla_get_u32);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005295 if (mask_out)
5296 *mask_out = mask;
Javier Cardonac80d5452010-12-16 17:37:49 -08005297
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005298 return 0;
5299
5300#undef FILL_IN_MESH_PARAM_IF_SET
5301}
5302
Javier Cardonac80d5452010-12-16 17:37:49 -08005303static int nl80211_parse_mesh_setup(struct genl_info *info,
5304 struct mesh_setup *setup)
5305{
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005306 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Javier Cardonac80d5452010-12-16 17:37:49 -08005307 struct nlattr *tb[NL80211_MESH_SETUP_ATTR_MAX + 1];
5308
5309 if (!info->attrs[NL80211_ATTR_MESH_SETUP])
5310 return -EINVAL;
5311 if (nla_parse_nested(tb, NL80211_MESH_SETUP_ATTR_MAX,
5312 info->attrs[NL80211_ATTR_MESH_SETUP],
5313 nl80211_mesh_setup_params_policy))
5314 return -EINVAL;
5315
Javier Cardonad299a1f2012-03-31 11:31:33 -07005316 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])
5317 setup->sync_method =
5318 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_SYNC])) ?
5319 IEEE80211_SYNC_METHOD_VENDOR :
5320 IEEE80211_SYNC_METHOD_NEIGHBOR_OFFSET;
5321
Javier Cardonac80d5452010-12-16 17:37:49 -08005322 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])
5323 setup->path_sel_proto =
5324 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_PATH_SEL])) ?
5325 IEEE80211_PATH_PROTOCOL_VENDOR :
5326 IEEE80211_PATH_PROTOCOL_HWMP;
5327
5328 if (tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])
5329 setup->path_metric =
5330 (nla_get_u8(tb[NL80211_MESH_SETUP_ENABLE_VENDOR_METRIC])) ?
5331 IEEE80211_PATH_METRIC_VENDOR :
5332 IEEE80211_PATH_METRIC_AIRTIME;
5333
Javier Cardona581a8b02011-04-07 15:08:27 -07005334
5335 if (tb[NL80211_MESH_SETUP_IE]) {
Javier Cardonac80d5452010-12-16 17:37:49 -08005336 struct nlattr *ieattr =
Javier Cardona581a8b02011-04-07 15:08:27 -07005337 tb[NL80211_MESH_SETUP_IE];
Javier Cardonac80d5452010-12-16 17:37:49 -08005338 if (!is_valid_ie_attr(ieattr))
5339 return -EINVAL;
Javier Cardona581a8b02011-04-07 15:08:27 -07005340 setup->ie = nla_data(ieattr);
5341 setup->ie_len = nla_len(ieattr);
Javier Cardonac80d5452010-12-16 17:37:49 -08005342 }
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005343 if (tb[NL80211_MESH_SETUP_USERSPACE_MPM] &&
5344 !(rdev->wiphy.features & NL80211_FEATURE_USERSPACE_MPM))
5345 return -EINVAL;
5346 setup->user_mpm = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_MPM]);
Javier Cardonab130e5c2011-05-03 16:57:07 -07005347 setup->is_authenticated = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AUTH]);
5348 setup->is_secure = nla_get_flag(tb[NL80211_MESH_SETUP_USERSPACE_AMPE]);
Thomas Pedersenbb2798d2013-03-04 13:06:10 -08005349 if (setup->is_secure)
5350 setup->user_mpm = true;
Javier Cardonac80d5452010-12-16 17:37:49 -08005351
Colleen Twitty6e16d902013-05-08 11:45:59 -07005352 if (tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]) {
5353 if (!setup->user_mpm)
5354 return -EINVAL;
5355 setup->auth_id =
5356 nla_get_u8(tb[NL80211_MESH_SETUP_AUTH_PROTOCOL]);
5357 }
5358
Javier Cardonac80d5452010-12-16 17:37:49 -08005359 return 0;
5360}
5361
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005362static int nl80211_update_mesh_config(struct sk_buff *skb,
Johannes Berg29cbe682010-12-03 09:20:44 +01005363 struct genl_info *info)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005364{
5365 struct cfg80211_registered_device *rdev = info->user_ptr[0];
5366 struct net_device *dev = info->user_ptr[1];
Johannes Berg29cbe682010-12-03 09:20:44 +01005367 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005368 struct mesh_config cfg;
5369 u32 mask;
5370 int err;
5371
Johannes Berg29cbe682010-12-03 09:20:44 +01005372 if (wdev->iftype != NL80211_IFTYPE_MESH_POINT)
5373 return -EOPNOTSUPP;
5374
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005375 if (!rdev->ops->update_mesh_config)
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005376 return -EOPNOTSUPP;
5377
Javier Cardona24bdd9f2010-12-16 17:37:48 -08005378 err = nl80211_parse_mesh_config(info, &cfg, &mask);
Johannes Bergbd90fdc2010-12-03 09:20:43 +01005379 if (err)
5380 return err;
5381
Johannes Berg29cbe682010-12-03 09:20:44 +01005382 wdev_lock(wdev);
5383 if (!wdev->mesh_id_len)
5384 err = -ENOLINK;
5385
5386 if (!err)
Hila Gonene35e4d22012-06-27 17:19:42 +03005387 err = rdev_update_mesh_config(rdev, dev, mask, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01005388
5389 wdev_unlock(wdev);
5390
5391 return err;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07005392}
5393
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005394static int nl80211_put_regdom(const struct ieee80211_regdomain *regdom,
5395 struct sk_buff *msg)
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005396{
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005397 struct nlattr *nl_reg_rules;
5398 unsigned int i;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005399
Johannes Berg458f4f92012-12-06 15:47:38 +01005400 if (nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, regdom->alpha2) ||
5401 (regdom->dfs_region &&
5402 nla_put_u8(msg, NL80211_ATTR_DFS_REGION, regdom->dfs_region)))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005403 goto nla_put_failure;
Johannes Berg458f4f92012-12-06 15:47:38 +01005404
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005405 nl_reg_rules = nla_nest_start(msg, NL80211_ATTR_REG_RULES);
5406 if (!nl_reg_rules)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005407 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005408
Johannes Berg458f4f92012-12-06 15:47:38 +01005409 for (i = 0; i < regdom->n_reg_rules; i++) {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005410 struct nlattr *nl_reg_rule;
5411 const struct ieee80211_reg_rule *reg_rule;
5412 const struct ieee80211_freq_range *freq_range;
5413 const struct ieee80211_power_rule *power_rule;
Janusz Dziedzic97524822014-01-30 09:52:20 +01005414 unsigned int max_bandwidth_khz;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005415
Johannes Berg458f4f92012-12-06 15:47:38 +01005416 reg_rule = &regdom->reg_rules[i];
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005417 freq_range = &reg_rule->freq_range;
5418 power_rule = &reg_rule->power_rule;
5419
5420 nl_reg_rule = nla_nest_start(msg, i);
5421 if (!nl_reg_rule)
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005422 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005423
Janusz Dziedzic97524822014-01-30 09:52:20 +01005424 max_bandwidth_khz = freq_range->max_bandwidth_khz;
5425 if (!max_bandwidth_khz)
5426 max_bandwidth_khz = reg_get_max_bandwidth(regdom,
5427 reg_rule);
5428
David S. Miller9360ffd2012-03-29 04:41:26 -04005429 if (nla_put_u32(msg, NL80211_ATTR_REG_RULE_FLAGS,
5430 reg_rule->flags) ||
5431 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_START,
5432 freq_range->start_freq_khz) ||
5433 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_END,
5434 freq_range->end_freq_khz) ||
5435 nla_put_u32(msg, NL80211_ATTR_FREQ_RANGE_MAX_BW,
Janusz Dziedzic97524822014-01-30 09:52:20 +01005436 max_bandwidth_khz) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04005437 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_ANT_GAIN,
5438 power_rule->max_antenna_gain) ||
5439 nla_put_u32(msg, NL80211_ATTR_POWER_RULE_MAX_EIRP,
Janusz Dziedzic089027e2014-02-21 19:46:12 +01005440 power_rule->max_eirp) ||
5441 nla_put_u32(msg, NL80211_ATTR_DFS_CAC_TIME,
5442 reg_rule->dfs_cac_ms))
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005443 goto nla_put_failure;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005444
5445 nla_nest_end(msg, nl_reg_rule);
5446 }
5447
5448 nla_nest_end(msg, nl_reg_rules);
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005449 return 0;
5450
5451nla_put_failure:
5452 return -EMSGSIZE;
5453}
5454
5455static int nl80211_get_reg_do(struct sk_buff *skb, struct genl_info *info)
5456{
5457 const struct ieee80211_regdomain *regdom = NULL;
5458 struct cfg80211_registered_device *rdev;
5459 struct wiphy *wiphy = NULL;
5460 struct sk_buff *msg;
5461 void *hdr;
5462
5463 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
5464 if (!msg)
5465 return -ENOBUFS;
5466
5467 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
5468 NL80211_CMD_GET_REG);
5469 if (!hdr)
5470 goto put_failure;
5471
5472 if (info->attrs[NL80211_ATTR_WIPHY]) {
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005473 bool self_managed;
5474
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005475 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
5476 if (IS_ERR(rdev)) {
5477 nlmsg_free(msg);
5478 return PTR_ERR(rdev);
5479 }
5480
5481 wiphy = &rdev->wiphy;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005482 self_managed = wiphy->regulatory_flags &
5483 REGULATORY_WIPHY_SELF_MANAGED;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005484 regdom = get_wiphy_regdom(wiphy);
5485
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005486 /* a self-managed-reg device must have a private regdom */
5487 if (WARN_ON(!regdom && self_managed)) {
5488 nlmsg_free(msg);
5489 return -EINVAL;
5490 }
5491
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005492 if (regdom &&
5493 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5494 goto nla_put_failure;
5495 }
5496
5497 if (!wiphy && reg_last_request_cell_base() &&
5498 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5499 NL80211_USER_REG_HINT_CELL_BASE))
5500 goto nla_put_failure;
5501
5502 rcu_read_lock();
5503
5504 if (!regdom)
5505 regdom = rcu_dereference(cfg80211_regdomain);
5506
5507 if (nl80211_put_regdom(regdom, msg))
5508 goto nla_put_failure_rcu;
5509
5510 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005511
5512 genlmsg_end(msg, hdr);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005513 return genlmsg_reply(msg, info);
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005514
Johannes Berg458f4f92012-12-06 15:47:38 +01005515nla_put_failure_rcu:
5516 rcu_read_unlock();
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005517nla_put_failure:
5518 genlmsg_cancel(msg, hdr);
Julia Lawallefe1cf02011-01-28 15:17:11 +01005519put_failure:
Yuri Ershovd080e272010-06-29 15:08:07 +04005520 nlmsg_free(msg);
Johannes Berg5fe231e2013-05-08 21:45:15 +02005521 return -EMSGSIZE;
Luis R. Rodriguezf1303472009-01-30 09:26:42 -08005522}
5523
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005524static int nl80211_send_regdom(struct sk_buff *msg, struct netlink_callback *cb,
5525 u32 seq, int flags, struct wiphy *wiphy,
5526 const struct ieee80211_regdomain *regdom)
5527{
5528 void *hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
5529 NL80211_CMD_GET_REG);
5530
5531 if (!hdr)
5532 return -1;
5533
5534 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
5535
5536 if (nl80211_put_regdom(regdom, msg))
5537 goto nla_put_failure;
5538
5539 if (!wiphy && reg_last_request_cell_base() &&
5540 nla_put_u32(msg, NL80211_ATTR_USER_REG_HINT_TYPE,
5541 NL80211_USER_REG_HINT_CELL_BASE))
5542 goto nla_put_failure;
5543
5544 if (wiphy &&
5545 nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
5546 goto nla_put_failure;
5547
Arik Nemtsov1bdd7162014-12-15 19:26:01 +02005548 if (wiphy && wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
5549 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
5550 goto nla_put_failure;
5551
Johannes Berg053c0952015-01-16 22:09:00 +01005552 genlmsg_end(msg, hdr);
5553 return 0;
Arik Nemtsovad30ca22014-12-15 19:25:59 +02005554
5555nla_put_failure:
5556 genlmsg_cancel(msg, hdr);
5557 return -EMSGSIZE;
5558}
5559
5560static int nl80211_get_reg_dump(struct sk_buff *skb,
5561 struct netlink_callback *cb)
5562{
5563 const struct ieee80211_regdomain *regdom = NULL;
5564 struct cfg80211_registered_device *rdev;
5565 int err, reg_idx, start = cb->args[2];
5566
5567 rtnl_lock();
5568
5569 if (cfg80211_regdomain && start == 0) {
5570 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5571 NLM_F_MULTI, NULL,
5572 rtnl_dereference(cfg80211_regdomain));
5573 if (err < 0)
5574 goto out_err;
5575 }
5576
5577 /* the global regdom is idx 0 */
5578 reg_idx = 1;
5579 list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
5580 regdom = get_wiphy_regdom(&rdev->wiphy);
5581 if (!regdom)
5582 continue;
5583
5584 if (++reg_idx <= start)
5585 continue;
5586
5587 err = nl80211_send_regdom(skb, cb, cb->nlh->nlmsg_seq,
5588 NLM_F_MULTI, &rdev->wiphy, regdom);
5589 if (err < 0) {
5590 reg_idx--;
5591 break;
5592 }
5593 }
5594
5595 cb->args[2] = reg_idx;
5596 err = skb->len;
5597out_err:
5598 rtnl_unlock();
5599 return err;
5600}
5601
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005602static int nl80211_set_reg(struct sk_buff *skb, struct genl_info *info)
5603{
5604 struct nlattr *tb[NL80211_REG_RULE_ATTR_MAX + 1];
5605 struct nlattr *nl_reg_rule;
Johannes Bergea372c52014-11-28 14:54:31 +01005606 char *alpha2;
5607 int rem_reg_rules, r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005608 u32 num_rules = 0, rule_idx = 0, size_of_regd;
Luis R. Rodriguez4c7d3982013-11-13 18:54:02 +01005609 enum nl80211_dfs_regions dfs_region = NL80211_DFS_UNSET;
Johannes Bergea372c52014-11-28 14:54:31 +01005610 struct ieee80211_regdomain *rd;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005611
5612 if (!info->attrs[NL80211_ATTR_REG_ALPHA2])
5613 return -EINVAL;
5614
5615 if (!info->attrs[NL80211_ATTR_REG_RULES])
5616 return -EINVAL;
5617
5618 alpha2 = nla_data(info->attrs[NL80211_ATTR_REG_ALPHA2]);
5619
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005620 if (info->attrs[NL80211_ATTR_DFS_REGION])
5621 dfs_region = nla_get_u8(info->attrs[NL80211_ATTR_DFS_REGION]);
5622
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005623 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005624 rem_reg_rules) {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005625 num_rules++;
5626 if (num_rules > NL80211_MAX_SUPP_REG_RULES)
Luis R. Rodriguez4776c6e2009-05-13 17:04:39 -04005627 return -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005628 }
5629
Luis R. Rodrigueze4387682013-11-05 09:18:01 -08005630 if (!reg_is_valid_request(alpha2))
5631 return -EINVAL;
5632
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005633 size_of_regd = sizeof(struct ieee80211_regdomain) +
Johannes Berg1a919312012-12-03 17:21:11 +01005634 num_rules * sizeof(struct ieee80211_reg_rule);
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005635
5636 rd = kzalloc(size_of_regd, GFP_KERNEL);
Johannes Berg6913b492012-12-04 00:48:59 +01005637 if (!rd)
5638 return -ENOMEM;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005639
5640 rd->n_reg_rules = num_rules;
5641 rd->alpha2[0] = alpha2[0];
5642 rd->alpha2[1] = alpha2[1];
5643
Luis R. Rodriguez8b60b072011-10-11 10:59:02 -07005644 /*
5645 * Disable DFS master mode if the DFS region was
5646 * not supported or known on this kernel.
5647 */
5648 if (reg_supported_dfs_region(dfs_region))
5649 rd->dfs_region = dfs_region;
5650
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005651 nla_for_each_nested(nl_reg_rule, info->attrs[NL80211_ATTR_REG_RULES],
Johannes Berg1a919312012-12-03 17:21:11 +01005652 rem_reg_rules) {
Johannes Bergae811e22014-01-24 10:17:47 +01005653 r = nla_parse(tb, NL80211_REG_RULE_ATTR_MAX,
5654 nla_data(nl_reg_rule), nla_len(nl_reg_rule),
5655 reg_rule_policy);
5656 if (r)
5657 goto bad_reg;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005658 r = parse_reg_rule(tb, &rd->reg_rules[rule_idx]);
5659 if (r)
5660 goto bad_reg;
5661
5662 rule_idx++;
5663
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005664 if (rule_idx > NL80211_MAX_SUPP_REG_RULES) {
5665 r = -EINVAL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005666 goto bad_reg;
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005667 }
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005668 }
5669
Ilan peerc37722b2015-03-30 15:15:49 +03005670 r = set_regdom(rd, REGD_SOURCE_CRDA);
Johannes Berg6913b492012-12-04 00:48:59 +01005671 /* set_regdom took ownership */
Johannes Berg1a919312012-12-03 17:21:11 +01005672 rd = NULL;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005673
Johannes Bergd2372b32008-10-24 20:32:20 +02005674 bad_reg:
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005675 kfree(rd);
Luis R. Rodriguezd0e18f82009-05-13 17:04:40 -04005676 return r;
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -07005677}
5678
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005679static int validate_scan_freqs(struct nlattr *freqs)
5680{
5681 struct nlattr *attr1, *attr2;
5682 int n_channels = 0, tmp1, tmp2;
5683
5684 nla_for_each_nested(attr1, freqs, tmp1) {
5685 n_channels++;
5686 /*
5687 * Some hardware has a limited channel list for
5688 * scanning, and it is pretty much nonsensical
5689 * to scan for a channel twice, so disallow that
5690 * and don't require drivers to check that the
5691 * channel list they get isn't longer than what
5692 * they can scan, as long as they can scan all
5693 * the channels they registered at once.
5694 */
5695 nla_for_each_nested(attr2, freqs, tmp2)
5696 if (attr1 != attr2 &&
5697 nla_get_u32(attr1) == nla_get_u32(attr2))
5698 return 0;
5699 }
5700
5701 return n_channels;
5702}
5703
Johannes Bergad2b26a2014-06-12 21:39:05 +02005704static int nl80211_parse_random_mac(struct nlattr **attrs,
5705 u8 *mac_addr, u8 *mac_addr_mask)
5706{
5707 int i;
5708
5709 if (!attrs[NL80211_ATTR_MAC] && !attrs[NL80211_ATTR_MAC_MASK]) {
Joe Perchesd2beae12015-03-02 19:54:58 -08005710 eth_zero_addr(mac_addr);
5711 eth_zero_addr(mac_addr_mask);
Johannes Bergad2b26a2014-06-12 21:39:05 +02005712 mac_addr[0] = 0x2;
5713 mac_addr_mask[0] = 0x3;
5714
5715 return 0;
5716 }
5717
5718 /* need both or none */
5719 if (!attrs[NL80211_ATTR_MAC] || !attrs[NL80211_ATTR_MAC_MASK])
5720 return -EINVAL;
5721
5722 memcpy(mac_addr, nla_data(attrs[NL80211_ATTR_MAC]), ETH_ALEN);
5723 memcpy(mac_addr_mask, nla_data(attrs[NL80211_ATTR_MAC_MASK]), ETH_ALEN);
5724
5725 /* don't allow or configure an mcast address */
5726 if (!is_multicast_ether_addr(mac_addr_mask) ||
5727 is_multicast_ether_addr(mac_addr))
5728 return -EINVAL;
5729
5730 /*
5731 * allow users to pass a MAC address that has bits set outside
5732 * of the mask, but don't bother drivers with having to deal
5733 * with such bits
5734 */
5735 for (i = 0; i < ETH_ALEN; i++)
5736 mac_addr[i] &= mac_addr_mask[i];
5737
5738 return 0;
5739}
5740
Johannes Berg2a519312009-02-10 21:25:55 +01005741static int nl80211_trigger_scan(struct sk_buff *skb, struct genl_info *info)
5742{
Johannes Berg4c476992010-10-04 21:36:35 +02005743 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Bergfd014282012-06-18 19:17:03 +02005744 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2a519312009-02-10 21:25:55 +01005745 struct cfg80211_scan_request *request;
Johannes Berg2a519312009-02-10 21:25:55 +01005746 struct nlattr *attr;
5747 struct wiphy *wiphy;
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005748 int err, tmp, n_ssids = 0, n_channels, i;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005749 size_t ie_len;
Johannes Berg2a519312009-02-10 21:25:55 +01005750
Johannes Bergf4a11bb2009-03-27 12:40:28 +01005751 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
5752 return -EINVAL;
5753
Johannes Berg79c97e92009-07-07 03:56:12 +02005754 wiphy = &rdev->wiphy;
Johannes Berg2a519312009-02-10 21:25:55 +01005755
Johannes Berg4c476992010-10-04 21:36:35 +02005756 if (!rdev->ops->scan)
5757 return -EOPNOTSUPP;
Johannes Berg2a519312009-02-10 21:25:55 +01005758
Johannes Bergf9d15d12014-01-22 11:14:19 +02005759 if (rdev->scan_req || rdev->scan_msg) {
Johannes Bergf9f47522013-03-19 15:04:07 +01005760 err = -EBUSY;
5761 goto unlock;
5762 }
Johannes Berg2a519312009-02-10 21:25:55 +01005763
5764 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Johannes Berg83f5e2c2009-06-17 17:41:49 +02005765 n_channels = validate_scan_freqs(
5766 info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Johannes Bergf9f47522013-03-19 15:04:07 +01005767 if (!n_channels) {
5768 err = -EINVAL;
5769 goto unlock;
5770 }
Johannes Berg2a519312009-02-10 21:25:55 +01005771 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005772 n_channels = ieee80211_get_num_supported_channels(wiphy);
Johannes Berg2a519312009-02-10 21:25:55 +01005773 }
5774
5775 if (info->attrs[NL80211_ATTR_SCAN_SSIDS])
5776 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp)
5777 n_ssids++;
5778
Johannes Bergf9f47522013-03-19 15:04:07 +01005779 if (n_ssids > wiphy->max_scan_ssids) {
5780 err = -EINVAL;
5781 goto unlock;
5782 }
Johannes Berg2a519312009-02-10 21:25:55 +01005783
Jouni Malinen70692ad2009-02-16 19:39:13 +02005784 if (info->attrs[NL80211_ATTR_IE])
5785 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
5786 else
5787 ie_len = 0;
5788
Johannes Bergf9f47522013-03-19 15:04:07 +01005789 if (ie_len > wiphy->max_scan_ie_len) {
5790 err = -EINVAL;
5791 goto unlock;
5792 }
Johannes Berg18a83652009-03-31 12:12:05 +02005793
Johannes Berg2a519312009-02-10 21:25:55 +01005794 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03005795 + sizeof(*request->ssids) * n_ssids
5796 + sizeof(*request->channels) * n_channels
Jouni Malinen70692ad2009-02-16 19:39:13 +02005797 + ie_len, GFP_KERNEL);
Johannes Bergf9f47522013-03-19 15:04:07 +01005798 if (!request) {
5799 err = -ENOMEM;
5800 goto unlock;
5801 }
Johannes Berg2a519312009-02-10 21:25:55 +01005802
Johannes Berg2a519312009-02-10 21:25:55 +01005803 if (n_ssids)
Johannes Berg5ba63532009-08-07 17:54:07 +02005804 request->ssids = (void *)&request->channels[n_channels];
Johannes Berg2a519312009-02-10 21:25:55 +01005805 request->n_ssids = n_ssids;
Jouni Malinen70692ad2009-02-16 19:39:13 +02005806 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01005807 if (n_ssids)
Jouni Malinen70692ad2009-02-16 19:39:13 +02005808 request->ie = (void *)(request->ssids + n_ssids);
5809 else
5810 request->ie = (void *)(request->channels + n_channels);
5811 }
Johannes Berg2a519312009-02-10 21:25:55 +01005812
Johannes Berg584991d2009-11-02 13:32:03 +01005813 i = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01005814 if (info->attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
5815 /* user specified, bail out if channel not found */
Johannes Berg2a519312009-02-10 21:25:55 +01005816 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_FREQUENCIES], tmp) {
Johannes Berg584991d2009-11-02 13:32:03 +01005817 struct ieee80211_channel *chan;
5818
5819 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
5820
5821 if (!chan) {
Johannes Berg2a519312009-02-10 21:25:55 +01005822 err = -EINVAL;
5823 goto out_free;
5824 }
Johannes Berg584991d2009-11-02 13:32:03 +01005825
5826 /* ignore disabled channels */
5827 if (chan->flags & IEEE80211_CHAN_DISABLED)
5828 continue;
5829
5830 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005831 i++;
5832 }
5833 } else {
Johannes Berg34850ab2011-07-18 18:08:35 +02005834 enum ieee80211_band band;
5835
Johannes Berg2a519312009-02-10 21:25:55 +01005836 /* all channels */
Johannes Berg2a519312009-02-10 21:25:55 +01005837 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
5838 int j;
5839 if (!wiphy->bands[band])
5840 continue;
5841 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
Johannes Berg584991d2009-11-02 13:32:03 +01005842 struct ieee80211_channel *chan;
5843
5844 chan = &wiphy->bands[band]->channels[j];
5845
5846 if (chan->flags & IEEE80211_CHAN_DISABLED)
5847 continue;
5848
5849 request->channels[i] = chan;
Johannes Berg2a519312009-02-10 21:25:55 +01005850 i++;
5851 }
5852 }
5853 }
5854
Johannes Berg584991d2009-11-02 13:32:03 +01005855 if (!i) {
5856 err = -EINVAL;
5857 goto out_free;
5858 }
5859
5860 request->n_channels = i;
5861
Johannes Berg2a519312009-02-10 21:25:55 +01005862 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01005863 if (n_ssids) {
Johannes Berg2a519312009-02-10 21:25:55 +01005864 nla_for_each_nested(attr, info->attrs[NL80211_ATTR_SCAN_SSIDS], tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03005865 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Johannes Berg2a519312009-02-10 21:25:55 +01005866 err = -EINVAL;
5867 goto out_free;
5868 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03005869 request->ssids[i].ssid_len = nla_len(attr);
Johannes Berg2a519312009-02-10 21:25:55 +01005870 memcpy(request->ssids[i].ssid, nla_data(attr), nla_len(attr));
Johannes Berg2a519312009-02-10 21:25:55 +01005871 i++;
5872 }
5873 }
5874
Jouni Malinen70692ad2009-02-16 19:39:13 +02005875 if (info->attrs[NL80211_ATTR_IE]) {
5876 request->ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Johannes Bergde95a542009-04-01 11:58:36 +02005877 memcpy((void *)request->ie,
5878 nla_data(info->attrs[NL80211_ATTR_IE]),
Jouni Malinen70692ad2009-02-16 19:39:13 +02005879 request->ie_len);
5880 }
5881
Johannes Berg34850ab2011-07-18 18:08:35 +02005882 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
Johannes Berga401d2b2011-07-20 00:52:16 +02005883 if (wiphy->bands[i])
5884 request->rates[i] =
5885 (1 << wiphy->bands[i]->n_bitrates) - 1;
Johannes Berg34850ab2011-07-18 18:08:35 +02005886
5887 if (info->attrs[NL80211_ATTR_SCAN_SUPP_RATES]) {
5888 nla_for_each_nested(attr,
5889 info->attrs[NL80211_ATTR_SCAN_SUPP_RATES],
5890 tmp) {
5891 enum ieee80211_band band = nla_type(attr);
5892
Dan Carpenter84404622011-07-29 11:52:18 +03005893 if (band < 0 || band >= IEEE80211_NUM_BANDS) {
Johannes Berg34850ab2011-07-18 18:08:35 +02005894 err = -EINVAL;
5895 goto out_free;
5896 }
Felix Fietkau1b09cd82013-11-20 19:40:41 +01005897
5898 if (!wiphy->bands[band])
5899 continue;
5900
Johannes Berg34850ab2011-07-18 18:08:35 +02005901 err = ieee80211_get_ratemask(wiphy->bands[band],
5902 nla_data(attr),
5903 nla_len(attr),
5904 &request->rates[band]);
5905 if (err)
5906 goto out_free;
5907 }
5908 }
5909
Sam Leffler46856bb2012-10-11 21:03:32 -07005910 if (info->attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07005911 request->flags = nla_get_u32(
5912 info->attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02005913 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
5914 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07005915 err = -EOPNOTSUPP;
5916 goto out_free;
5917 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02005918
5919 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
5920 if (!(wiphy->features &
5921 NL80211_FEATURE_SCAN_RANDOM_MAC_ADDR)) {
5922 err = -EOPNOTSUPP;
5923 goto out_free;
5924 }
5925
5926 if (wdev->current_bss) {
5927 err = -EOPNOTSUPP;
5928 goto out_free;
5929 }
5930
5931 err = nl80211_parse_random_mac(info->attrs,
5932 request->mac_addr,
5933 request->mac_addr_mask);
5934 if (err)
5935 goto out_free;
5936 }
Sam Leffler46856bb2012-10-11 21:03:32 -07005937 }
Sam Lefflered4737712012-10-11 21:03:31 -07005938
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05305939 request->no_cck =
5940 nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
5941
Johannes Bergfd014282012-06-18 19:17:03 +02005942 request->wdev = wdev;
Johannes Berg79c97e92009-07-07 03:56:12 +02005943 request->wiphy = &rdev->wiphy;
Sam Leffler15d60302012-10-11 21:03:34 -07005944 request->scan_start = jiffies;
Johannes Berg2a519312009-02-10 21:25:55 +01005945
Johannes Berg79c97e92009-07-07 03:56:12 +02005946 rdev->scan_req = request;
Hila Gonene35e4d22012-06-27 17:19:42 +03005947 err = rdev_scan(rdev, request);
Johannes Berg2a519312009-02-10 21:25:55 +01005948
Johannes Berg463d0182009-07-14 00:33:35 +02005949 if (!err) {
Johannes Bergfd014282012-06-18 19:17:03 +02005950 nl80211_send_scan_start(rdev, wdev);
5951 if (wdev->netdev)
5952 dev_hold(wdev->netdev);
Johannes Berg4c476992010-10-04 21:36:35 +02005953 } else {
Johannes Berg2a519312009-02-10 21:25:55 +01005954 out_free:
Johannes Berg79c97e92009-07-07 03:56:12 +02005955 rdev->scan_req = NULL;
Johannes Berg2a519312009-02-10 21:25:55 +01005956 kfree(request);
5957 }
Johannes Berg3b858752009-03-12 09:55:09 +01005958
Johannes Bergf9f47522013-03-19 15:04:07 +01005959 unlock:
Johannes Berg2a519312009-02-10 21:25:55 +01005960 return err;
5961}
5962
Luciano Coelho256da022014-11-10 16:13:46 +02005963static struct cfg80211_sched_scan_request *
Johannes Bergad2b26a2014-06-12 21:39:05 +02005964nl80211_parse_sched_scan(struct wiphy *wiphy, struct wireless_dev *wdev,
Luciano Coelho256da022014-11-10 16:13:46 +02005965 struct nlattr **attrs)
Luciano Coelho807f8a82011-05-11 17:09:35 +03005966{
5967 struct cfg80211_sched_scan_request *request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005968 struct nlattr *attr;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005969 int err, tmp, n_ssids = 0, n_match_sets = 0, n_channels, i;
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005970 u32 interval;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005971 enum ieee80211_band band;
5972 size_t ie_len;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03005973 struct nlattr *tb[NL80211_SCHED_SCAN_MATCH_ATTR_MAX + 1];
Johannes Bergea73cbc2014-01-24 10:53:53 +01005974 s32 default_match_rssi = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelho807f8a82011-05-11 17:09:35 +03005975
Luciano Coelho256da022014-11-10 16:13:46 +02005976 if (!is_valid_ie_attr(attrs[NL80211_ATTR_IE]))
5977 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005978
Luciano Coelho256da022014-11-10 16:13:46 +02005979 if (!attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL])
5980 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005981
Luciano Coelho256da022014-11-10 16:13:46 +02005982 interval = nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_INTERVAL]);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005983 if (interval == 0)
Luciano Coelho256da022014-11-10 16:13:46 +02005984 return ERR_PTR(-EINVAL);
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03005985
Luciano Coelho256da022014-11-10 16:13:46 +02005986 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03005987 n_channels = validate_scan_freqs(
Luciano Coelho256da022014-11-10 16:13:46 +02005988 attrs[NL80211_ATTR_SCAN_FREQUENCIES]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005989 if (!n_channels)
Luciano Coelho256da022014-11-10 16:13:46 +02005990 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005991 } else {
Ilan Peerbdfbec22014-01-09 11:37:23 +02005992 n_channels = ieee80211_get_num_supported_channels(wiphy);
Luciano Coelho807f8a82011-05-11 17:09:35 +03005993 }
5994
Luciano Coelho256da022014-11-10 16:13:46 +02005995 if (attrs[NL80211_ATTR_SCAN_SSIDS])
5996 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03005997 tmp)
5998 n_ssids++;
5999
Luciano Coelho93b6aa62011-07-13 14:57:28 +03006000 if (n_ssids > wiphy->max_sched_scan_ssids)
Luciano Coelho256da022014-11-10 16:13:46 +02006001 return ERR_PTR(-EINVAL);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006002
Johannes Bergea73cbc2014-01-24 10:53:53 +01006003 /*
6004 * First, count the number of 'real' matchsets. Due to an issue with
6005 * the old implementation, matchsets containing only the RSSI attribute
6006 * (NL80211_SCHED_SCAN_MATCH_ATTR_RSSI) are considered as the 'default'
6007 * RSSI for all matchsets, rather than their own matchset for reporting
6008 * all APs with a strong RSSI. This is needed to be compatible with
6009 * older userspace that treated a matchset with only the RSSI as the
6010 * global RSSI for all other matchsets - if there are other matchsets.
6011 */
Luciano Coelho256da022014-11-10 16:13:46 +02006012 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006013 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006014 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Johannes Bergea73cbc2014-01-24 10:53:53 +01006015 tmp) {
6016 struct nlattr *rssi;
6017
6018 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6019 nla_data(attr), nla_len(attr),
6020 nl80211_match_policy);
6021 if (err)
Luciano Coelho256da022014-11-10 16:13:46 +02006022 return ERR_PTR(err);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006023 /* add other standalone attributes here */
6024 if (tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID]) {
6025 n_match_sets++;
6026 continue;
6027 }
6028 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6029 if (rssi)
6030 default_match_rssi = nla_get_s32(rssi);
6031 }
6032 }
6033
6034 /* However, if there's no other matchset, add the RSSI one */
6035 if (!n_match_sets && default_match_rssi != NL80211_SCAN_RSSI_THOLD_OFF)
6036 n_match_sets = 1;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006037
6038 if (n_match_sets > wiphy->max_match_sets)
Luciano Coelho256da022014-11-10 16:13:46 +02006039 return ERR_PTR(-EINVAL);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006040
Luciano Coelho256da022014-11-10 16:13:46 +02006041 if (attrs[NL80211_ATTR_IE])
6042 ie_len = nla_len(attrs[NL80211_ATTR_IE]);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006043 else
6044 ie_len = 0;
6045
Luciano Coelho5a865ba2011-07-13 14:57:29 +03006046 if (ie_len > wiphy->max_sched_scan_ie_len)
Luciano Coelho256da022014-11-10 16:13:46 +02006047 return ERR_PTR(-EINVAL);
Luciano Coelhoc10841c2011-06-30 08:32:41 +03006048
Luciano Coelho807f8a82011-05-11 17:09:35 +03006049 request = kzalloc(sizeof(*request)
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006050 + sizeof(*request->ssids) * n_ssids
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006051 + sizeof(*request->match_sets) * n_match_sets
Luciano Coelhoa2cd43c2011-05-18 11:42:03 +03006052 + sizeof(*request->channels) * n_channels
Luciano Coelho807f8a82011-05-11 17:09:35 +03006053 + ie_len, GFP_KERNEL);
Luciano Coelho256da022014-11-10 16:13:46 +02006054 if (!request)
6055 return ERR_PTR(-ENOMEM);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006056
6057 if (n_ssids)
6058 request->ssids = (void *)&request->channels[n_channels];
6059 request->n_ssids = n_ssids;
6060 if (ie_len) {
Johannes Berg13874e42015-01-23 11:25:20 +01006061 if (n_ssids)
Luciano Coelho807f8a82011-05-11 17:09:35 +03006062 request->ie = (void *)(request->ssids + n_ssids);
6063 else
6064 request->ie = (void *)(request->channels + n_channels);
6065 }
6066
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006067 if (n_match_sets) {
6068 if (request->ie)
6069 request->match_sets = (void *)(request->ie + ie_len);
Johannes Berg13874e42015-01-23 11:25:20 +01006070 else if (n_ssids)
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006071 request->match_sets =
6072 (void *)(request->ssids + n_ssids);
6073 else
6074 request->match_sets =
6075 (void *)(request->channels + n_channels);
6076 }
6077 request->n_match_sets = n_match_sets;
6078
Luciano Coelho807f8a82011-05-11 17:09:35 +03006079 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006080 if (attrs[NL80211_ATTR_SCAN_FREQUENCIES]) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006081 /* user specified, bail out if channel not found */
6082 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006083 attrs[NL80211_ATTR_SCAN_FREQUENCIES],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006084 tmp) {
6085 struct ieee80211_channel *chan;
6086
6087 chan = ieee80211_get_channel(wiphy, nla_get_u32(attr));
6088
6089 if (!chan) {
6090 err = -EINVAL;
6091 goto out_free;
6092 }
6093
6094 /* ignore disabled channels */
6095 if (chan->flags & IEEE80211_CHAN_DISABLED)
6096 continue;
6097
6098 request->channels[i] = chan;
6099 i++;
6100 }
6101 } else {
6102 /* all channels */
6103 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
6104 int j;
6105 if (!wiphy->bands[band])
6106 continue;
6107 for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
6108 struct ieee80211_channel *chan;
6109
6110 chan = &wiphy->bands[band]->channels[j];
6111
6112 if (chan->flags & IEEE80211_CHAN_DISABLED)
6113 continue;
6114
6115 request->channels[i] = chan;
6116 i++;
6117 }
6118 }
6119 }
6120
6121 if (!i) {
6122 err = -EINVAL;
6123 goto out_free;
6124 }
6125
6126 request->n_channels = i;
6127
6128 i = 0;
Johannes Berg13874e42015-01-23 11:25:20 +01006129 if (n_ssids) {
Luciano Coelho256da022014-11-10 16:13:46 +02006130 nla_for_each_nested(attr, attrs[NL80211_ATTR_SCAN_SSIDS],
Luciano Coelho807f8a82011-05-11 17:09:35 +03006131 tmp) {
Luciano Coelho57a27e12011-06-07 20:42:26 +03006132 if (nla_len(attr) > IEEE80211_MAX_SSID_LEN) {
Luciano Coelho807f8a82011-05-11 17:09:35 +03006133 err = -EINVAL;
6134 goto out_free;
6135 }
Luciano Coelho57a27e12011-06-07 20:42:26 +03006136 request->ssids[i].ssid_len = nla_len(attr);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006137 memcpy(request->ssids[i].ssid, nla_data(attr),
6138 nla_len(attr));
Luciano Coelho807f8a82011-05-11 17:09:35 +03006139 i++;
6140 }
6141 }
6142
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006143 i = 0;
Luciano Coelho256da022014-11-10 16:13:46 +02006144 if (attrs[NL80211_ATTR_SCHED_SCAN_MATCH]) {
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006145 nla_for_each_nested(attr,
Luciano Coelho256da022014-11-10 16:13:46 +02006146 attrs[NL80211_ATTR_SCHED_SCAN_MATCH],
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006147 tmp) {
Thomas Pedersen88e920b2012-06-21 11:09:54 -07006148 struct nlattr *ssid, *rssi;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006149
Johannes Bergae811e22014-01-24 10:17:47 +01006150 err = nla_parse(tb, NL80211_SCHED_SCAN_MATCH_ATTR_MAX,
6151 nla_data(attr), nla_len(attr),
6152 nl80211_match_policy);
6153 if (err)
6154 goto out_free;
Johannes Berg4a4ab0d2012-06-13 11:17:11 +02006155 ssid = tb[NL80211_SCHED_SCAN_MATCH_ATTR_SSID];
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006156 if (ssid) {
Johannes Bergea73cbc2014-01-24 10:53:53 +01006157 if (WARN_ON(i >= n_match_sets)) {
6158 /* this indicates a programming error,
6159 * the loop above should have verified
6160 * things properly
6161 */
6162 err = -EINVAL;
6163 goto out_free;
6164 }
6165
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006166 if (nla_len(ssid) > IEEE80211_MAX_SSID_LEN) {
6167 err = -EINVAL;
6168 goto out_free;
6169 }
6170 memcpy(request->match_sets[i].ssid.ssid,
6171 nla_data(ssid), nla_len(ssid));
6172 request->match_sets[i].ssid.ssid_len =
6173 nla_len(ssid);
Johannes Bergea73cbc2014-01-24 10:53:53 +01006174 /* special attribute - old implemenation w/a */
6175 request->match_sets[i].rssi_thold =
6176 default_match_rssi;
6177 rssi = tb[NL80211_SCHED_SCAN_MATCH_ATTR_RSSI];
6178 if (rssi)
6179 request->match_sets[i].rssi_thold =
6180 nla_get_s32(rssi);
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006181 }
6182 i++;
6183 }
Johannes Bergea73cbc2014-01-24 10:53:53 +01006184
6185 /* there was no other matchset, so the RSSI one is alone */
Luciano Coelhof89f46c2014-12-01 11:32:09 +02006186 if (i == 0 && n_match_sets)
Johannes Bergea73cbc2014-01-24 10:53:53 +01006187 request->match_sets[0].rssi_thold = default_match_rssi;
6188
6189 request->min_rssi_thold = INT_MAX;
6190 for (i = 0; i < n_match_sets; i++)
6191 request->min_rssi_thold =
6192 min(request->match_sets[i].rssi_thold,
6193 request->min_rssi_thold);
6194 } else {
6195 request->min_rssi_thold = NL80211_SCAN_RSSI_THOLD_OFF;
Luciano Coelhoa1f1c212011-08-31 16:01:48 +03006196 }
6197
Johannes Berg9900e482014-02-04 21:01:25 +01006198 if (ie_len) {
6199 request->ie_len = ie_len;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006200 memcpy((void *)request->ie,
Luciano Coelho256da022014-11-10 16:13:46 +02006201 nla_data(attrs[NL80211_ATTR_IE]),
Luciano Coelho807f8a82011-05-11 17:09:35 +03006202 request->ie_len);
6203 }
6204
Luciano Coelho256da022014-11-10 16:13:46 +02006205 if (attrs[NL80211_ATTR_SCAN_FLAGS]) {
Sam Lefflered4737712012-10-11 21:03:31 -07006206 request->flags = nla_get_u32(
Luciano Coelho256da022014-11-10 16:13:46 +02006207 attrs[NL80211_ATTR_SCAN_FLAGS]);
Johannes Berg00c3a6e2013-10-26 17:14:38 +02006208 if ((request->flags & NL80211_SCAN_FLAG_LOW_PRIORITY) &&
6209 !(wiphy->features & NL80211_FEATURE_LOW_PRIORITY_SCAN)) {
Sam Leffler46856bb2012-10-11 21:03:32 -07006210 err = -EOPNOTSUPP;
6211 goto out_free;
6212 }
Johannes Bergad2b26a2014-06-12 21:39:05 +02006213
6214 if (request->flags & NL80211_SCAN_FLAG_RANDOM_ADDR) {
6215 u32 flg = NL80211_FEATURE_SCHED_SCAN_RANDOM_MAC_ADDR;
6216
6217 if (!wdev) /* must be net-detect */
6218 flg = NL80211_FEATURE_ND_RANDOM_MAC_ADDR;
6219
6220 if (!(wiphy->features & flg)) {
6221 err = -EOPNOTSUPP;
6222 goto out_free;
6223 }
6224
6225 if (wdev && wdev->current_bss) {
6226 err = -EOPNOTSUPP;
6227 goto out_free;
6228 }
6229
6230 err = nl80211_parse_random_mac(attrs, request->mac_addr,
6231 request->mac_addr_mask);
6232 if (err)
6233 goto out_free;
6234 }
Sam Leffler46856bb2012-10-11 21:03:32 -07006235 }
Sam Lefflered4737712012-10-11 21:03:31 -07006236
Luciano Coelho9c748932015-01-16 16:04:09 +02006237 if (attrs[NL80211_ATTR_SCHED_SCAN_DELAY])
6238 request->delay =
6239 nla_get_u32(attrs[NL80211_ATTR_SCHED_SCAN_DELAY]);
6240
Luciano Coelhobbe6ad62011-05-11 17:09:37 +03006241 request->interval = interval;
Sam Leffler15d60302012-10-11 21:03:34 -07006242 request->scan_start = jiffies;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006243
Luciano Coelho256da022014-11-10 16:13:46 +02006244 return request;
Luciano Coelho807f8a82011-05-11 17:09:35 +03006245
6246out_free:
6247 kfree(request);
Luciano Coelho256da022014-11-10 16:13:46 +02006248 return ERR_PTR(err);
6249}
6250
6251static int nl80211_start_sched_scan(struct sk_buff *skb,
6252 struct genl_info *info)
6253{
6254 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6255 struct net_device *dev = info->user_ptr[1];
Johannes Bergad2b26a2014-06-12 21:39:05 +02006256 struct wireless_dev *wdev = dev->ieee80211_ptr;
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006257 struct cfg80211_sched_scan_request *sched_scan_req;
Luciano Coelho256da022014-11-10 16:13:46 +02006258 int err;
6259
6260 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6261 !rdev->ops->sched_scan_start)
6262 return -EOPNOTSUPP;
6263
6264 if (rdev->sched_scan_req)
6265 return -EINPROGRESS;
6266
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006267 sched_scan_req = nl80211_parse_sched_scan(&rdev->wiphy, wdev,
6268 info->attrs);
6269
6270 err = PTR_ERR_OR_ZERO(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006271 if (err)
6272 goto out_err;
6273
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006274 err = rdev_sched_scan_start(rdev, dev, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006275 if (err)
6276 goto out_free;
6277
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006278 sched_scan_req->dev = dev;
6279 sched_scan_req->wiphy = &rdev->wiphy;
6280
Jukka Rissanen93a1e862014-12-15 13:25:39 +02006281 if (info->attrs[NL80211_ATTR_SOCKET_OWNER])
6282 sched_scan_req->owner_nlportid = info->snd_portid;
6283
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006284 rcu_assign_pointer(rdev->sched_scan_req, sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006285
6286 nl80211_send_sched_scan(rdev, dev,
6287 NL80211_CMD_START_SCHED_SCAN);
6288 return 0;
6289
6290out_free:
Jukka Rissanen31a60ed2014-12-15 13:25:38 +02006291 kfree(sched_scan_req);
Luciano Coelho256da022014-11-10 16:13:46 +02006292out_err:
Luciano Coelho807f8a82011-05-11 17:09:35 +03006293 return err;
6294}
6295
6296static int nl80211_stop_sched_scan(struct sk_buff *skb,
6297 struct genl_info *info)
6298{
6299 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6300
6301 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN) ||
6302 !rdev->ops->sched_scan_stop)
6303 return -EOPNOTSUPP;
6304
Johannes Berg5fe231e2013-05-08 21:45:15 +02006305 return __cfg80211_stop_sched_scan(rdev, false);
Luciano Coelho807f8a82011-05-11 17:09:35 +03006306}
6307
Simon Wunderlich04f39042013-02-08 18:16:19 +01006308static int nl80211_start_radar_detection(struct sk_buff *skb,
6309 struct genl_info *info)
6310{
6311 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6312 struct net_device *dev = info->user_ptr[1];
6313 struct wireless_dev *wdev = dev->ieee80211_ptr;
6314 struct cfg80211_chan_def chandef;
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006315 enum nl80211_dfs_regions dfs_region;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006316 unsigned int cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006317 int err;
6318
Luis R. Rodriguez55f74352013-11-25 20:56:10 +01006319 dfs_region = reg_get_dfs_region(wdev->wiphy);
6320 if (dfs_region == NL80211_DFS_UNSET)
6321 return -EINVAL;
6322
Simon Wunderlich04f39042013-02-08 18:16:19 +01006323 err = nl80211_parse_chandef(rdev, info, &chandef);
6324 if (err)
6325 return err;
6326
Simon Wunderlichff311bc2013-09-03 19:43:18 +02006327 if (netif_carrier_ok(dev))
6328 return -EBUSY;
6329
Simon Wunderlich04f39042013-02-08 18:16:19 +01006330 if (wdev->cac_started)
6331 return -EBUSY;
6332
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006333 err = cfg80211_chandef_dfs_required(wdev->wiphy, &chandef,
Luciano Coelho00ec75f2014-05-15 13:05:39 +03006334 wdev->iftype);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006335 if (err < 0)
6336 return err;
6337
6338 if (err == 0)
6339 return -EINVAL;
6340
Janusz Dziedzicfe7c3a12013-11-05 14:48:48 +01006341 if (!cfg80211_chandef_dfs_usable(wdev->wiphy, &chandef))
Simon Wunderlich04f39042013-02-08 18:16:19 +01006342 return -EINVAL;
6343
6344 if (!rdev->ops->start_radar_detection)
6345 return -EOPNOTSUPP;
6346
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006347 cac_time_ms = cfg80211_chandef_dfs_cac_time(&rdev->wiphy, &chandef);
6348 if (WARN_ON(!cac_time_ms))
6349 cac_time_ms = IEEE80211_DFS_MIN_CAC_TIME_MS;
6350
6351 err = rdev->ops->start_radar_detection(&rdev->wiphy, dev, &chandef,
6352 cac_time_ms);
Simon Wunderlich04f39042013-02-08 18:16:19 +01006353 if (!err) {
Michal Kazior9e0e2962014-01-29 14:22:27 +01006354 wdev->chandef = chandef;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006355 wdev->cac_started = true;
6356 wdev->cac_start_time = jiffies;
Janusz Dziedzic31559f32014-02-21 19:46:13 +01006357 wdev->cac_time_ms = cac_time_ms;
Simon Wunderlich04f39042013-02-08 18:16:19 +01006358 }
Simon Wunderlich04f39042013-02-08 18:16:19 +01006359 return err;
6360}
6361
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006362static int nl80211_channel_switch(struct sk_buff *skb, struct genl_info *info)
6363{
6364 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6365 struct net_device *dev = info->user_ptr[1];
6366 struct wireless_dev *wdev = dev->ieee80211_ptr;
6367 struct cfg80211_csa_settings params;
6368 /* csa_attrs is defined static to avoid waste of stack size - this
6369 * function is called under RTNL lock, so this should not be a problem.
6370 */
6371 static struct nlattr *csa_attrs[NL80211_ATTR_MAX+1];
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006372 int err;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006373 bool need_new_beacon = false;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006374 int len, i;
Luciano Coelho252e07c2014-10-08 09:48:34 +03006375 u32 cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006376
6377 if (!rdev->ops->channel_switch ||
6378 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_CHANNEL_SWITCH))
6379 return -EOPNOTSUPP;
6380
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006381 switch (dev->ieee80211_ptr->iftype) {
6382 case NL80211_IFTYPE_AP:
6383 case NL80211_IFTYPE_P2P_GO:
6384 need_new_beacon = true;
6385
6386 /* useless if AP is not running */
6387 if (!wdev->beacon_interval)
Johannes Berg1ff79df2014-01-22 10:05:27 +01006388 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006389 break;
6390 case NL80211_IFTYPE_ADHOC:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006391 if (!wdev->ssid_len)
6392 return -ENOTCONN;
6393 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07006394 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg1ff79df2014-01-22 10:05:27 +01006395 if (!wdev->mesh_id_len)
6396 return -ENOTCONN;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006397 break;
6398 default:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006399 return -EOPNOTSUPP;
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006400 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006401
6402 memset(&params, 0, sizeof(params));
6403
6404 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
6405 !info->attrs[NL80211_ATTR_CH_SWITCH_COUNT])
6406 return -EINVAL;
6407
6408 /* only important for AP, IBSS and mesh create IEs internally */
Andrei Otcheretianskid0a361a2013-10-17 10:52:17 +02006409 if (need_new_beacon && !info->attrs[NL80211_ATTR_CSA_IES])
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006410 return -EINVAL;
6411
Luciano Coelho252e07c2014-10-08 09:48:34 +03006412 /* Even though the attribute is u32, the specification says
6413 * u8, so let's make sure we don't overflow.
6414 */
6415 cs_count = nla_get_u32(info->attrs[NL80211_ATTR_CH_SWITCH_COUNT]);
6416 if (cs_count > 255)
6417 return -EINVAL;
6418
6419 params.count = cs_count;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006420
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006421 if (!need_new_beacon)
6422 goto skip_beacons;
6423
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006424 err = nl80211_parse_beacon(info->attrs, &params.beacon_after);
6425 if (err)
6426 return err;
6427
6428 err = nla_parse_nested(csa_attrs, NL80211_ATTR_MAX,
6429 info->attrs[NL80211_ATTR_CSA_IES],
6430 nl80211_policy);
6431 if (err)
6432 return err;
6433
6434 err = nl80211_parse_beacon(csa_attrs, &params.beacon_csa);
6435 if (err)
6436 return err;
6437
6438 if (!csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON])
6439 return -EINVAL;
6440
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006441 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6442 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006443 return -EINVAL;
6444
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006445 params.n_counter_offsets_beacon = len / sizeof(u16);
6446 if (rdev->wiphy.max_num_csa_counters &&
6447 (params.n_counter_offsets_beacon >
6448 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006449 return -EINVAL;
6450
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006451 params.counter_offsets_beacon =
6452 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_BEACON]);
6453
6454 /* sanity checks - counters should fit and be the same */
6455 for (i = 0; i < params.n_counter_offsets_beacon; i++) {
6456 u16 offset = params.counter_offsets_beacon[i];
6457
6458 if (offset >= params.beacon_csa.tail_len)
6459 return -EINVAL;
6460
6461 if (params.beacon_csa.tail[offset] != params.count)
6462 return -EINVAL;
6463 }
6464
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006465 if (csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]) {
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006466 len = nla_len(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6467 if (!len || (len % sizeof(u16)))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006468 return -EINVAL;
6469
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006470 params.n_counter_offsets_presp = len / sizeof(u16);
6471 if (rdev->wiphy.max_num_csa_counters &&
6472 (params.n_counter_offsets_beacon >
6473 rdev->wiphy.max_num_csa_counters))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006474 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03006475
6476 params.counter_offsets_presp =
6477 nla_data(csa_attrs[NL80211_ATTR_CSA_C_OFF_PRESP]);
6478
6479 /* sanity checks - counters should fit and be the same */
6480 for (i = 0; i < params.n_counter_offsets_presp; i++) {
6481 u16 offset = params.counter_offsets_presp[i];
6482
6483 if (offset >= params.beacon_csa.probe_resp_len)
6484 return -EINVAL;
6485
6486 if (params.beacon_csa.probe_resp[offset] !=
6487 params.count)
6488 return -EINVAL;
6489 }
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006490 }
6491
Simon Wunderlichee4bc9e2013-08-28 13:41:33 +02006492skip_beacons:
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006493 err = nl80211_parse_chandef(rdev, info, &params.chandef);
6494 if (err)
6495 return err;
6496
Arik Nemtsov923b3522015-07-08 15:41:44 +03006497 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &params.chandef,
6498 wdev->iftype))
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006499 return -EINVAL;
6500
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006501 err = cfg80211_chandef_dfs_required(wdev->wiphy,
6502 &params.chandef,
6503 wdev->iftype);
6504 if (err < 0)
6505 return err;
6506
Fabian Frederickdcc6c2f2014-10-25 17:57:35 +02006507 if (err > 0)
Luciano Coelho2beb6da2014-02-18 11:40:36 +02006508 params.radar_required = true;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006509
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006510 if (info->attrs[NL80211_ATTR_CH_SWITCH_BLOCK_TX])
6511 params.block_tx = true;
6512
Simon Wunderlichc56589e2013-11-21 18:19:49 +01006513 wdev_lock(wdev);
6514 err = rdev_channel_switch(rdev, dev, &params);
6515 wdev_unlock(wdev);
6516
6517 return err;
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +02006518}
6519
Johannes Berg9720bb32011-06-21 09:45:33 +02006520static int nl80211_send_bss(struct sk_buff *msg, struct netlink_callback *cb,
6521 u32 seq, int flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006522 struct cfg80211_registered_device *rdev,
Johannes Berg48ab9052009-07-10 18:42:31 +02006523 struct wireless_dev *wdev,
6524 struct cfg80211_internal_bss *intbss)
Johannes Berg2a519312009-02-10 21:25:55 +01006525{
Johannes Berg48ab9052009-07-10 18:42:31 +02006526 struct cfg80211_bss *res = &intbss->pub;
Johannes Berg9caf0362012-11-29 01:25:20 +01006527 const struct cfg80211_bss_ies *ies;
Johannes Berg2a519312009-02-10 21:25:55 +01006528 void *hdr;
6529 struct nlattr *bss;
Johannes Berg48ab9052009-07-10 18:42:31 +02006530
6531 ASSERT_WDEV_LOCK(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006532
Eric W. Biederman15e47302012-09-07 20:12:54 +00006533 hdr = nl80211hdr_put(msg, NETLINK_CB(cb->skb).portid, seq, flags,
Johannes Berg2a519312009-02-10 21:25:55 +01006534 NL80211_CMD_NEW_SCAN_RESULTS);
6535 if (!hdr)
6536 return -1;
6537
Johannes Berg9720bb32011-06-21 09:45:33 +02006538 genl_dump_check_consistent(cb, hdr, &nl80211_fam);
6539
Johannes Berg97990a02013-04-19 01:02:55 +02006540 if (nla_put_u32(msg, NL80211_ATTR_GENERATION, rdev->bss_generation))
6541 goto nla_put_failure;
6542 if (wdev->netdev &&
David S. Miller9360ffd2012-03-29 04:41:26 -04006543 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex))
6544 goto nla_put_failure;
Johannes Berg97990a02013-04-19 01:02:55 +02006545 if (nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
6546 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006547
6548 bss = nla_nest_start(msg, NL80211_ATTR_BSS);
6549 if (!bss)
6550 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -04006551 if ((!is_zero_ether_addr(res->bssid) &&
Johannes Berg9caf0362012-11-29 01:25:20 +01006552 nla_put(msg, NL80211_BSS_BSSID, ETH_ALEN, res->bssid)))
David S. Miller9360ffd2012-03-29 04:41:26 -04006553 goto nla_put_failure;
Johannes Berg9caf0362012-11-29 01:25:20 +01006554
6555 rcu_read_lock();
Johannes Berg0e227082014-08-12 20:34:30 +02006556 /* indicate whether we have probe response data or not */
6557 if (rcu_access_pointer(res->proberesp_ies) &&
6558 nla_put_flag(msg, NL80211_BSS_PRESP_DATA))
6559 goto fail_unlock_rcu;
6560
6561 /* this pointer prefers to be pointed to probe response data
6562 * but is always valid
6563 */
Johannes Berg9caf0362012-11-29 01:25:20 +01006564 ies = rcu_dereference(res->ies);
Johannes Berg8cef2c92013-02-05 16:54:31 +01006565 if (ies) {
6566 if (nla_put_u64(msg, NL80211_BSS_TSF, ies->tsf))
6567 goto fail_unlock_rcu;
Johannes Berg8cef2c92013-02-05 16:54:31 +01006568 if (ies->len && nla_put(msg, NL80211_BSS_INFORMATION_ELEMENTS,
6569 ies->len, ies->data))
6570 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006571 }
Johannes Berg0e227082014-08-12 20:34:30 +02006572
6573 /* and this pointer is always (unless driver didn't know) beacon data */
Johannes Berg9caf0362012-11-29 01:25:20 +01006574 ies = rcu_dereference(res->beacon_ies);
Johannes Berg0e227082014-08-12 20:34:30 +02006575 if (ies && ies->from_beacon) {
6576 if (nla_put_u64(msg, NL80211_BSS_BEACON_TSF, ies->tsf))
Johannes Berg8cef2c92013-02-05 16:54:31 +01006577 goto fail_unlock_rcu;
6578 if (ies->len && nla_put(msg, NL80211_BSS_BEACON_IES,
6579 ies->len, ies->data))
6580 goto fail_unlock_rcu;
Johannes Berg9caf0362012-11-29 01:25:20 +01006581 }
6582 rcu_read_unlock();
6583
David S. Miller9360ffd2012-03-29 04:41:26 -04006584 if (res->beacon_interval &&
6585 nla_put_u16(msg, NL80211_BSS_BEACON_INTERVAL, res->beacon_interval))
6586 goto nla_put_failure;
6587 if (nla_put_u16(msg, NL80211_BSS_CAPABILITY, res->capability) ||
6588 nla_put_u32(msg, NL80211_BSS_FREQUENCY, res->channel->center_freq) ||
Simon Wunderlichdcd6eac2013-07-08 16:55:49 +02006589 nla_put_u32(msg, NL80211_BSS_CHAN_WIDTH, res->scan_width) ||
David S. Miller9360ffd2012-03-29 04:41:26 -04006590 nla_put_u32(msg, NL80211_BSS_SEEN_MS_AGO,
6591 jiffies_to_msecs(jiffies - intbss->ts)))
6592 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006593
Johannes Berg77965c92009-02-18 18:45:06 +01006594 switch (rdev->wiphy.signal_type) {
Johannes Berg2a519312009-02-10 21:25:55 +01006595 case CFG80211_SIGNAL_TYPE_MBM:
David S. Miller9360ffd2012-03-29 04:41:26 -04006596 if (nla_put_u32(msg, NL80211_BSS_SIGNAL_MBM, res->signal))
6597 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006598 break;
6599 case CFG80211_SIGNAL_TYPE_UNSPEC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006600 if (nla_put_u8(msg, NL80211_BSS_SIGNAL_UNSPEC, res->signal))
6601 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +01006602 break;
6603 default:
6604 break;
6605 }
6606
Johannes Berg48ab9052009-07-10 18:42:31 +02006607 switch (wdev->iftype) {
Johannes Berg074ac8d2010-09-16 14:58:22 +02006608 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg48ab9052009-07-10 18:42:31 +02006609 case NL80211_IFTYPE_STATION:
David S. Miller9360ffd2012-03-29 04:41:26 -04006610 if (intbss == wdev->current_bss &&
6611 nla_put_u32(msg, NL80211_BSS_STATUS,
6612 NL80211_BSS_STATUS_ASSOCIATED))
6613 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006614 break;
6615 case NL80211_IFTYPE_ADHOC:
David S. Miller9360ffd2012-03-29 04:41:26 -04006616 if (intbss == wdev->current_bss &&
6617 nla_put_u32(msg, NL80211_BSS_STATUS,
6618 NL80211_BSS_STATUS_IBSS_JOINED))
6619 goto nla_put_failure;
Johannes Berg48ab9052009-07-10 18:42:31 +02006620 break;
6621 default:
6622 break;
6623 }
6624
Johannes Berg2a519312009-02-10 21:25:55 +01006625 nla_nest_end(msg, bss);
6626
Johannes Berg053c0952015-01-16 22:09:00 +01006627 genlmsg_end(msg, hdr);
6628 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006629
Johannes Berg8cef2c92013-02-05 16:54:31 +01006630 fail_unlock_rcu:
6631 rcu_read_unlock();
Johannes Berg2a519312009-02-10 21:25:55 +01006632 nla_put_failure:
6633 genlmsg_cancel(msg, hdr);
6634 return -EMSGSIZE;
6635}
6636
Johannes Berg97990a02013-04-19 01:02:55 +02006637static int nl80211_dump_scan(struct sk_buff *skb, struct netlink_callback *cb)
Johannes Berg2a519312009-02-10 21:25:55 +01006638{
Johannes Berg48ab9052009-07-10 18:42:31 +02006639 struct cfg80211_registered_device *rdev;
Johannes Berg2a519312009-02-10 21:25:55 +01006640 struct cfg80211_internal_bss *scan;
Johannes Berg48ab9052009-07-10 18:42:31 +02006641 struct wireless_dev *wdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006642 int start = cb->args[2], idx = 0;
Johannes Berg2a519312009-02-10 21:25:55 +01006643 int err;
6644
Johannes Berg97990a02013-04-19 01:02:55 +02006645 err = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006646 if (err)
6647 return err;
Johannes Berg2a519312009-02-10 21:25:55 +01006648
Johannes Berg48ab9052009-07-10 18:42:31 +02006649 wdev_lock(wdev);
6650 spin_lock_bh(&rdev->bss_lock);
6651 cfg80211_bss_expire(rdev);
6652
Johannes Berg9720bb32011-06-21 09:45:33 +02006653 cb->seq = rdev->bss_generation;
6654
Johannes Berg48ab9052009-07-10 18:42:31 +02006655 list_for_each_entry(scan, &rdev->bss_list, list) {
Johannes Berg2a519312009-02-10 21:25:55 +01006656 if (++idx <= start)
6657 continue;
Johannes Berg9720bb32011-06-21 09:45:33 +02006658 if (nl80211_send_bss(skb, cb,
Johannes Berg2a519312009-02-10 21:25:55 +01006659 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg48ab9052009-07-10 18:42:31 +02006660 rdev, wdev, scan) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +01006661 idx--;
Johannes Berg67748892010-10-04 21:14:06 +02006662 break;
Johannes Berg2a519312009-02-10 21:25:55 +01006663 }
6664 }
6665
Johannes Berg48ab9052009-07-10 18:42:31 +02006666 spin_unlock_bh(&rdev->bss_lock);
6667 wdev_unlock(wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006668
Johannes Berg97990a02013-04-19 01:02:55 +02006669 cb->args[2] = idx;
6670 nl80211_finish_wdev_dump(rdev);
Johannes Berg2a519312009-02-10 21:25:55 +01006671
Johannes Berg67748892010-10-04 21:14:06 +02006672 return skb->len;
Johannes Berg2a519312009-02-10 21:25:55 +01006673}
6674
Eric W. Biederman15e47302012-09-07 20:12:54 +00006675static int nl80211_send_survey(struct sk_buff *msg, u32 portid, u32 seq,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006676 int flags, struct net_device *dev,
6677 bool allow_radio_stats,
6678 struct survey_info *survey)
Holger Schurig61fa7132009-11-11 12:25:40 +01006679{
6680 void *hdr;
6681 struct nlattr *infoattr;
6682
Johannes Berg11f78ac2014-11-14 16:43:50 +01006683 /* skip radio stats if userspace didn't request them */
6684 if (!survey->channel && !allow_radio_stats)
6685 return 0;
6686
Eric W. Biederman15e47302012-09-07 20:12:54 +00006687 hdr = nl80211hdr_put(msg, portid, seq, flags,
Holger Schurig61fa7132009-11-11 12:25:40 +01006688 NL80211_CMD_NEW_SURVEY_RESULTS);
6689 if (!hdr)
6690 return -ENOMEM;
6691
David S. Miller9360ffd2012-03-29 04:41:26 -04006692 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
6693 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006694
6695 infoattr = nla_nest_start(msg, NL80211_ATTR_SURVEY_INFO);
6696 if (!infoattr)
6697 goto nla_put_failure;
6698
Johannes Berg11f78ac2014-11-14 16:43:50 +01006699 if (survey->channel &&
6700 nla_put_u32(msg, NL80211_SURVEY_INFO_FREQUENCY,
David S. Miller9360ffd2012-03-29 04:41:26 -04006701 survey->channel->center_freq))
6702 goto nla_put_failure;
6703
6704 if ((survey->filled & SURVEY_INFO_NOISE_DBM) &&
6705 nla_put_u8(msg, NL80211_SURVEY_INFO_NOISE, survey->noise))
6706 goto nla_put_failure;
6707 if ((survey->filled & SURVEY_INFO_IN_USE) &&
6708 nla_put_flag(msg, NL80211_SURVEY_INFO_IN_USE))
6709 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006710 if ((survey->filled & SURVEY_INFO_TIME) &&
6711 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME,
6712 survey->time))
David S. Miller9360ffd2012-03-29 04:41:26 -04006713 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006714 if ((survey->filled & SURVEY_INFO_TIME_BUSY) &&
6715 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_BUSY,
6716 survey->time_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006717 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006718 if ((survey->filled & SURVEY_INFO_TIME_EXT_BUSY) &&
6719 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_EXT_BUSY,
6720 survey->time_ext_busy))
David S. Miller9360ffd2012-03-29 04:41:26 -04006721 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006722 if ((survey->filled & SURVEY_INFO_TIME_RX) &&
6723 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_RX,
6724 survey->time_rx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006725 goto nla_put_failure;
Johannes Berg4ed20be2014-11-14 16:35:34 +01006726 if ((survey->filled & SURVEY_INFO_TIME_TX) &&
6727 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_TX,
6728 survey->time_tx))
David S. Miller9360ffd2012-03-29 04:41:26 -04006729 goto nla_put_failure;
Johannes Berg052536a2014-11-14 16:44:11 +01006730 if ((survey->filled & SURVEY_INFO_TIME_SCAN) &&
6731 nla_put_u64(msg, NL80211_SURVEY_INFO_TIME_SCAN,
6732 survey->time_scan))
6733 goto nla_put_failure;
Holger Schurig61fa7132009-11-11 12:25:40 +01006734
6735 nla_nest_end(msg, infoattr);
6736
Johannes Berg053c0952015-01-16 22:09:00 +01006737 genlmsg_end(msg, hdr);
6738 return 0;
Holger Schurig61fa7132009-11-11 12:25:40 +01006739
6740 nla_put_failure:
6741 genlmsg_cancel(msg, hdr);
6742 return -EMSGSIZE;
6743}
6744
Johannes Berg11f78ac2014-11-14 16:43:50 +01006745static int nl80211_dump_survey(struct sk_buff *skb, struct netlink_callback *cb)
Holger Schurig61fa7132009-11-11 12:25:40 +01006746{
6747 struct survey_info survey;
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006748 struct cfg80211_registered_device *rdev;
Johannes Berg97990a02013-04-19 01:02:55 +02006749 struct wireless_dev *wdev;
6750 int survey_idx = cb->args[2];
Holger Schurig61fa7132009-11-11 12:25:40 +01006751 int res;
Johannes Berg11f78ac2014-11-14 16:43:50 +01006752 bool radio_stats;
Holger Schurig61fa7132009-11-11 12:25:40 +01006753
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006754 res = nl80211_prepare_wdev_dump(skb, cb, &rdev, &wdev);
Johannes Berg67748892010-10-04 21:14:06 +02006755 if (res)
6756 return res;
Holger Schurig61fa7132009-11-11 12:25:40 +01006757
Johannes Berg11f78ac2014-11-14 16:43:50 +01006758 /* prepare_wdev_dump parsed the attributes */
6759 radio_stats = nl80211_fam.attrbuf[NL80211_ATTR_SURVEY_RADIO_STATS];
6760
Johannes Berg97990a02013-04-19 01:02:55 +02006761 if (!wdev->netdev) {
6762 res = -EINVAL;
6763 goto out_err;
6764 }
6765
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006766 if (!rdev->ops->dump_survey) {
Holger Schurig61fa7132009-11-11 12:25:40 +01006767 res = -EOPNOTSUPP;
6768 goto out_err;
6769 }
6770
6771 while (1) {
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006772 res = rdev_dump_survey(rdev, wdev->netdev, survey_idx, &survey);
Holger Schurig61fa7132009-11-11 12:25:40 +01006773 if (res == -ENOENT)
6774 break;
6775 if (res)
6776 goto out_err;
6777
Johannes Berg11f78ac2014-11-14 16:43:50 +01006778 /* don't send disabled channels, but do send non-channel data */
6779 if (survey.channel &&
6780 survey.channel->flags & IEEE80211_CHAN_DISABLED) {
Luis R. Rodriguez180cdc72011-05-27 07:24:02 -07006781 survey_idx++;
6782 continue;
6783 }
6784
Holger Schurig61fa7132009-11-11 12:25:40 +01006785 if (nl80211_send_survey(skb,
Eric W. Biederman15e47302012-09-07 20:12:54 +00006786 NETLINK_CB(cb->skb).portid,
Holger Schurig61fa7132009-11-11 12:25:40 +01006787 cb->nlh->nlmsg_seq, NLM_F_MULTI,
Johannes Berg11f78ac2014-11-14 16:43:50 +01006788 wdev->netdev, radio_stats, &survey) < 0)
Holger Schurig61fa7132009-11-11 12:25:40 +01006789 goto out;
6790 survey_idx++;
6791 }
6792
6793 out:
Johannes Berg97990a02013-04-19 01:02:55 +02006794 cb->args[2] = survey_idx;
Holger Schurig61fa7132009-11-11 12:25:40 +01006795 res = skb->len;
6796 out_err:
Zhao, Gang1b8ec872014-04-21 12:53:02 +08006797 nl80211_finish_wdev_dump(rdev);
Holger Schurig61fa7132009-11-11 12:25:40 +01006798 return res;
6799}
6800
Samuel Ortizb23aa672009-07-01 21:26:54 +02006801static bool nl80211_valid_wpa_versions(u32 wpa_versions)
6802{
6803 return !(wpa_versions & ~(NL80211_WPA_VERSION_1 |
6804 NL80211_WPA_VERSION_2));
6805}
6806
Jouni Malinen636a5d32009-03-19 13:39:22 +02006807static int nl80211_authenticate(struct sk_buff *skb, struct genl_info *info)
6808{
Johannes Berg4c476992010-10-04 21:36:35 +02006809 struct cfg80211_registered_device *rdev = info->user_ptr[0];
6810 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02006811 struct ieee80211_channel *chan;
Jouni Malinene39e5b52012-09-30 19:29:39 +03006812 const u8 *bssid, *ssid, *ie = NULL, *sae_data = NULL;
6813 int err, ssid_len, ie_len = 0, sae_data_len = 0;
Johannes Berg19957bb2009-07-02 17:20:43 +02006814 enum nl80211_auth_type auth_type;
Johannes Bergfffd0932009-07-08 14:22:54 +02006815 struct key_parse key;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006816 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006817
Johannes Bergf4a11bb2009-03-27 12:40:28 +01006818 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
6819 return -EINVAL;
6820
6821 if (!info->attrs[NL80211_ATTR_MAC])
6822 return -EINVAL;
6823
Jouni Malinen17780922009-03-27 20:52:47 +02006824 if (!info->attrs[NL80211_ATTR_AUTH_TYPE])
6825 return -EINVAL;
6826
Johannes Berg19957bb2009-07-02 17:20:43 +02006827 if (!info->attrs[NL80211_ATTR_SSID])
6828 return -EINVAL;
6829
6830 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
6831 return -EINVAL;
6832
Johannes Bergfffd0932009-07-08 14:22:54 +02006833 err = nl80211_parse_key(info, &key);
6834 if (err)
6835 return err;
6836
6837 if (key.idx >= 0) {
Johannes Berge31b8212010-10-05 19:39:30 +02006838 if (key.type != -1 && key.type != NL80211_KEYTYPE_GROUP)
6839 return -EINVAL;
Johannes Bergfffd0932009-07-08 14:22:54 +02006840 if (!key.p.key || !key.p.key_len)
6841 return -EINVAL;
6842 if ((key.p.cipher != WLAN_CIPHER_SUITE_WEP40 ||
6843 key.p.key_len != WLAN_KEY_LEN_WEP40) &&
6844 (key.p.cipher != WLAN_CIPHER_SUITE_WEP104 ||
6845 key.p.key_len != WLAN_KEY_LEN_WEP104))
6846 return -EINVAL;
6847 if (key.idx > 4)
6848 return -EINVAL;
6849 } else {
6850 key.p.key_len = 0;
6851 key.p.key = NULL;
6852 }
6853
Johannes Bergafea0b72010-08-10 09:46:42 +02006854 if (key.idx >= 0) {
6855 int i;
6856 bool ok = false;
6857 for (i = 0; i < rdev->wiphy.n_cipher_suites; i++) {
6858 if (key.p.cipher == rdev->wiphy.cipher_suites[i]) {
6859 ok = true;
6860 break;
6861 }
6862 }
Johannes Berg4c476992010-10-04 21:36:35 +02006863 if (!ok)
6864 return -EINVAL;
Johannes Bergafea0b72010-08-10 09:46:42 +02006865 }
6866
Johannes Berg4c476992010-10-04 21:36:35 +02006867 if (!rdev->ops->auth)
6868 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006869
Johannes Berg074ac8d2010-09-16 14:58:22 +02006870 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02006871 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
6872 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02006873
Johannes Berg19957bb2009-07-02 17:20:43 +02006874 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen664834d2014-01-15 00:01:44 +02006875 chan = nl80211_get_valid_chan(&rdev->wiphy,
6876 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
6877 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02006878 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006879
Johannes Berg19957bb2009-07-02 17:20:43 +02006880 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
6881 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
6882
6883 if (info->attrs[NL80211_ATTR_IE]) {
6884 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
6885 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
6886 }
6887
6888 auth_type = nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03006889 if (!nl80211_valid_auth_type(rdev, auth_type, NL80211_CMD_AUTHENTICATE))
Johannes Berg4c476992010-10-04 21:36:35 +02006890 return -EINVAL;
Johannes Berg19957bb2009-07-02 17:20:43 +02006891
Jouni Malinene39e5b52012-09-30 19:29:39 +03006892 if (auth_type == NL80211_AUTHTYPE_SAE &&
6893 !info->attrs[NL80211_ATTR_SAE_DATA])
6894 return -EINVAL;
6895
6896 if (info->attrs[NL80211_ATTR_SAE_DATA]) {
6897 if (auth_type != NL80211_AUTHTYPE_SAE)
6898 return -EINVAL;
6899 sae_data = nla_data(info->attrs[NL80211_ATTR_SAE_DATA]);
6900 sae_data_len = nla_len(info->attrs[NL80211_ATTR_SAE_DATA]);
6901 /* need to include at least Auth Transaction and Status Code */
6902 if (sae_data_len < 4)
6903 return -EINVAL;
6904 }
6905
Jouni Malinend5cdfac2010-04-04 09:37:19 +03006906 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
6907
Johannes Berg95de8172012-01-20 13:55:25 +01006908 /*
6909 * Since we no longer track auth state, ignore
6910 * requests to only change local state.
6911 */
6912 if (local_state_change)
6913 return 0;
6914
Johannes Berg91bf9b22013-05-15 17:44:01 +02006915 wdev_lock(dev->ieee80211_ptr);
6916 err = cfg80211_mlme_auth(rdev, dev, chan, auth_type, bssid,
6917 ssid, ssid_len, ie, ie_len,
6918 key.p.key, key.p.key_len, key.idx,
6919 sae_data, sae_data_len);
6920 wdev_unlock(dev->ieee80211_ptr);
6921 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02006922}
6923
Johannes Bergc0692b82010-08-27 14:26:53 +03006924static int nl80211_crypto_settings(struct cfg80211_registered_device *rdev,
6925 struct genl_info *info,
Johannes Berg3dc27d22009-07-02 21:36:37 +02006926 struct cfg80211_crypto_settings *settings,
6927 int cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006928{
Johannes Bergc0b2bbd2009-07-25 16:54:36 +02006929 memset(settings, 0, sizeof(*settings));
6930
Samuel Ortizb23aa672009-07-01 21:26:54 +02006931 settings->control_port = info->attrs[NL80211_ATTR_CONTROL_PORT];
6932
Johannes Bergc0692b82010-08-27 14:26:53 +03006933 if (info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]) {
6934 u16 proto;
6935 proto = nla_get_u16(
6936 info->attrs[NL80211_ATTR_CONTROL_PORT_ETHERTYPE]);
6937 settings->control_port_ethertype = cpu_to_be16(proto);
6938 if (!(rdev->wiphy.flags & WIPHY_FLAG_CONTROL_PORT_PROTOCOL) &&
6939 proto != ETH_P_PAE)
6940 return -EINVAL;
6941 if (info->attrs[NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT])
6942 settings->control_port_no_encrypt = true;
6943 } else
6944 settings->control_port_ethertype = cpu_to_be16(ETH_P_PAE);
6945
Samuel Ortizb23aa672009-07-01 21:26:54 +02006946 if (info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]) {
6947 void *data;
6948 int len, i;
6949
6950 data = nla_data(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6951 len = nla_len(info->attrs[NL80211_ATTR_CIPHER_SUITES_PAIRWISE]);
6952 settings->n_ciphers_pairwise = len / sizeof(u32);
6953
6954 if (len % sizeof(u32))
6955 return -EINVAL;
6956
Johannes Berg3dc27d22009-07-02 21:36:37 +02006957 if (settings->n_ciphers_pairwise > cipher_limit)
Samuel Ortizb23aa672009-07-01 21:26:54 +02006958 return -EINVAL;
6959
6960 memcpy(settings->ciphers_pairwise, data, len);
6961
6962 for (i = 0; i < settings->n_ciphers_pairwise; i++)
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006963 if (!cfg80211_supported_cipher_suite(
6964 &rdev->wiphy,
Samuel Ortizb23aa672009-07-01 21:26:54 +02006965 settings->ciphers_pairwise[i]))
6966 return -EINVAL;
6967 }
6968
6969 if (info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]) {
6970 settings->cipher_group =
6971 nla_get_u32(info->attrs[NL80211_ATTR_CIPHER_SUITE_GROUP]);
Jouni Malinen38ba3c52011-09-21 18:14:56 +03006972 if (!cfg80211_supported_cipher_suite(&rdev->wiphy,
6973 settings->cipher_group))
Samuel Ortizb23aa672009-07-01 21:26:54 +02006974 return -EINVAL;
6975 }
6976
6977 if (info->attrs[NL80211_ATTR_WPA_VERSIONS]) {
6978 settings->wpa_versions =
6979 nla_get_u32(info->attrs[NL80211_ATTR_WPA_VERSIONS]);
6980 if (!nl80211_valid_wpa_versions(settings->wpa_versions))
6981 return -EINVAL;
6982 }
6983
6984 if (info->attrs[NL80211_ATTR_AKM_SUITES]) {
6985 void *data;
Jouni Malinen6d302402011-09-21 18:11:33 +03006986 int len;
Samuel Ortizb23aa672009-07-01 21:26:54 +02006987
6988 data = nla_data(info->attrs[NL80211_ATTR_AKM_SUITES]);
6989 len = nla_len(info->attrs[NL80211_ATTR_AKM_SUITES]);
6990 settings->n_akm_suites = len / sizeof(u32);
6991
6992 if (len % sizeof(u32))
6993 return -EINVAL;
6994
Jouni Malinen1b9ca022011-09-21 16:13:07 +03006995 if (settings->n_akm_suites > NL80211_MAX_NR_AKM_SUITES)
6996 return -EINVAL;
6997
Samuel Ortizb23aa672009-07-01 21:26:54 +02006998 memcpy(settings->akm_suites, data, len);
Samuel Ortizb23aa672009-07-01 21:26:54 +02006999 }
7000
7001 return 0;
7002}
7003
Jouni Malinen636a5d32009-03-19 13:39:22 +02007004static int nl80211_associate(struct sk_buff *skb, struct genl_info *info)
7005{
Johannes Berg4c476992010-10-04 21:36:35 +02007006 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7007 struct net_device *dev = info->user_ptr[1];
Johannes Bergf444de02010-05-05 15:25:02 +02007008 struct ieee80211_channel *chan;
Johannes Bergf62fab72013-02-21 20:09:09 +01007009 struct cfg80211_assoc_request req = {};
7010 const u8 *bssid, *ssid;
7011 int err, ssid_len = 0;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007012
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007013 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7014 return -EINVAL;
7015
7016 if (!info->attrs[NL80211_ATTR_MAC] ||
Johannes Berg19957bb2009-07-02 17:20:43 +02007017 !info->attrs[NL80211_ATTR_SSID] ||
7018 !info->attrs[NL80211_ATTR_WIPHY_FREQ])
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007019 return -EINVAL;
7020
Johannes Berg4c476992010-10-04 21:36:35 +02007021 if (!rdev->ops->assoc)
7022 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007023
Johannes Berg074ac8d2010-09-16 14:58:22 +02007024 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007025 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7026 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007027
Johannes Berg19957bb2009-07-02 17:20:43 +02007028 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007029
Jouni Malinen664834d2014-01-15 00:01:44 +02007030 chan = nl80211_get_valid_chan(&rdev->wiphy,
7031 info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7032 if (!chan)
Johannes Berg4c476992010-10-04 21:36:35 +02007033 return -EINVAL;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007034
Johannes Berg19957bb2009-07-02 17:20:43 +02007035 ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7036 ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007037
7038 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007039 req.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7040 req.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007041 }
7042
Jouni Malinendc6382c2009-05-06 22:09:37 +03007043 if (info->attrs[NL80211_ATTR_USE_MFP]) {
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007044 enum nl80211_mfp mfp =
Jouni Malinendc6382c2009-05-06 22:09:37 +03007045 nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
Johannes Berg4f5dadc2009-07-07 03:56:10 +02007046 if (mfp == NL80211_MFP_REQUIRED)
Johannes Bergf62fab72013-02-21 20:09:09 +01007047 req.use_mfp = true;
Johannes Berg4c476992010-10-04 21:36:35 +02007048 else if (mfp != NL80211_MFP_NO)
7049 return -EINVAL;
Jouni Malinendc6382c2009-05-06 22:09:37 +03007050 }
7051
Johannes Berg3e5d7642009-07-07 14:37:26 +02007052 if (info->attrs[NL80211_ATTR_PREV_BSSID])
Johannes Bergf62fab72013-02-21 20:09:09 +01007053 req.prev_bssid = nla_data(info->attrs[NL80211_ATTR_PREV_BSSID]);
Johannes Berg3e5d7642009-07-07 14:37:26 +02007054
Ben Greear7e7c8922011-11-18 11:31:59 -08007055 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007056 req.flags |= ASSOC_REQ_DISABLE_HT;
Ben Greear7e7c8922011-11-18 11:31:59 -08007057
7058 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007059 memcpy(&req.ht_capa_mask,
7060 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7061 sizeof(req.ht_capa_mask));
Ben Greear7e7c8922011-11-18 11:31:59 -08007062
7063 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007064 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
Ben Greear7e7c8922011-11-18 11:31:59 -08007065 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007066 memcpy(&req.ht_capa,
7067 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7068 sizeof(req.ht_capa));
Ben Greear7e7c8922011-11-18 11:31:59 -08007069 }
7070
Johannes Bergee2aca32013-02-21 17:36:01 +01007071 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
Johannes Bergf62fab72013-02-21 20:09:09 +01007072 req.flags |= ASSOC_REQ_DISABLE_VHT;
Johannes Bergee2aca32013-02-21 17:36:01 +01007073
7074 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergf62fab72013-02-21 20:09:09 +01007075 memcpy(&req.vht_capa_mask,
7076 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7077 sizeof(req.vht_capa_mask));
Johannes Bergee2aca32013-02-21 17:36:01 +01007078
7079 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
Johannes Bergf62fab72013-02-21 20:09:09 +01007080 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
Johannes Bergee2aca32013-02-21 17:36:01 +01007081 return -EINVAL;
Johannes Bergf62fab72013-02-21 20:09:09 +01007082 memcpy(&req.vht_capa,
7083 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7084 sizeof(req.vht_capa));
Johannes Bergee2aca32013-02-21 17:36:01 +01007085 }
7086
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007087 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7088 if (!(rdev->wiphy.features &
7089 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7090 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7091 return -EINVAL;
7092 req.flags |= ASSOC_REQ_USE_RRM;
7093 }
7094
Johannes Bergf62fab72013-02-21 20:09:09 +01007095 err = nl80211_crypto_settings(rdev, info, &req.crypto, 1);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007096 if (!err) {
7097 wdev_lock(dev->ieee80211_ptr);
Johannes Bergf62fab72013-02-21 20:09:09 +01007098 err = cfg80211_mlme_assoc(rdev, dev, chan, bssid,
7099 ssid, ssid_len, &req);
Johannes Berg91bf9b22013-05-15 17:44:01 +02007100 wdev_unlock(dev->ieee80211_ptr);
7101 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007102
Jouni Malinen636a5d32009-03-19 13:39:22 +02007103 return err;
7104}
7105
7106static int nl80211_deauthenticate(struct sk_buff *skb, struct genl_info *info)
7107{
Johannes Berg4c476992010-10-04 21:36:35 +02007108 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7109 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007110 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007111 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007112 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007113 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007114
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007115 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7116 return -EINVAL;
7117
7118 if (!info->attrs[NL80211_ATTR_MAC])
7119 return -EINVAL;
7120
7121 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7122 return -EINVAL;
7123
Johannes Berg4c476992010-10-04 21:36:35 +02007124 if (!rdev->ops->deauth)
7125 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007126
Johannes Berg074ac8d2010-09-16 14:58:22 +02007127 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007128 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7129 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007130
Johannes Berg19957bb2009-07-02 17:20:43 +02007131 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007132
Johannes Berg19957bb2009-07-02 17:20:43 +02007133 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7134 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007135 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007136 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007137 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007138
7139 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007140 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7141 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007142 }
7143
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007144 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7145
Johannes Berg91bf9b22013-05-15 17:44:01 +02007146 wdev_lock(dev->ieee80211_ptr);
7147 err = cfg80211_mlme_deauth(rdev, dev, bssid, ie, ie_len, reason_code,
7148 local_state_change);
7149 wdev_unlock(dev->ieee80211_ptr);
7150 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007151}
7152
7153static int nl80211_disassociate(struct sk_buff *skb, struct genl_info *info)
7154{
Johannes Berg4c476992010-10-04 21:36:35 +02007155 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7156 struct net_device *dev = info->user_ptr[1];
Johannes Berg19957bb2009-07-02 17:20:43 +02007157 const u8 *ie = NULL, *bssid;
Johannes Berg91bf9b22013-05-15 17:44:01 +02007158 int ie_len = 0, err;
Johannes Berg19957bb2009-07-02 17:20:43 +02007159 u16 reason_code;
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007160 bool local_state_change;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007161
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007162 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7163 return -EINVAL;
7164
7165 if (!info->attrs[NL80211_ATTR_MAC])
7166 return -EINVAL;
7167
7168 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7169 return -EINVAL;
7170
Johannes Berg4c476992010-10-04 21:36:35 +02007171 if (!rdev->ops->disassoc)
7172 return -EOPNOTSUPP;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007173
Johannes Berg074ac8d2010-09-16 14:58:22 +02007174 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007175 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7176 return -EOPNOTSUPP;
Jouni Malineneec60b02009-03-20 21:21:19 +02007177
Johannes Berg19957bb2009-07-02 17:20:43 +02007178 bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007179
Johannes Berg19957bb2009-07-02 17:20:43 +02007180 reason_code = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7181 if (reason_code == 0) {
Johannes Bergf4a11bb2009-03-27 12:40:28 +01007182 /* Reason Code 0 is reserved */
Johannes Berg4c476992010-10-04 21:36:35 +02007183 return -EINVAL;
Jouni Malinen255e7372009-03-20 21:21:17 +02007184 }
Jouni Malinen636a5d32009-03-19 13:39:22 +02007185
7186 if (info->attrs[NL80211_ATTR_IE]) {
Johannes Berg19957bb2009-07-02 17:20:43 +02007187 ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7188 ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
Jouni Malinen636a5d32009-03-19 13:39:22 +02007189 }
7190
Jouni Malinend5cdfac2010-04-04 09:37:19 +03007191 local_state_change = !!info->attrs[NL80211_ATTR_LOCAL_STATE_CHANGE];
7192
Johannes Berg91bf9b22013-05-15 17:44:01 +02007193 wdev_lock(dev->ieee80211_ptr);
7194 err = cfg80211_mlme_disassoc(rdev, dev, bssid, ie, ie_len, reason_code,
7195 local_state_change);
7196 wdev_unlock(dev->ieee80211_ptr);
7197 return err;
Jouni Malinen636a5d32009-03-19 13:39:22 +02007198}
7199
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007200static bool
7201nl80211_parse_mcast_rate(struct cfg80211_registered_device *rdev,
7202 int mcast_rate[IEEE80211_NUM_BANDS],
7203 int rateval)
7204{
7205 struct wiphy *wiphy = &rdev->wiphy;
7206 bool found = false;
7207 int band, i;
7208
7209 for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
7210 struct ieee80211_supported_band *sband;
7211
7212 sband = wiphy->bands[band];
7213 if (!sband)
7214 continue;
7215
7216 for (i = 0; i < sband->n_bitrates; i++) {
7217 if (sband->bitrates[i].bitrate == rateval) {
7218 mcast_rate[band] = i + 1;
7219 found = true;
7220 break;
7221 }
7222 }
7223 }
7224
7225 return found;
7226}
7227
Johannes Berg04a773a2009-04-19 21:24:32 +02007228static int nl80211_join_ibss(struct sk_buff *skb, struct genl_info *info)
7229{
Johannes Berg4c476992010-10-04 21:36:35 +02007230 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7231 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007232 struct cfg80211_ibss_params ibss;
7233 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007234 struct cfg80211_cached_keys *connkeys = NULL;
Johannes Berg04a773a2009-04-19 21:24:32 +02007235 int err;
7236
Johannes Berg8e30bc52009-04-22 17:45:38 +02007237 memset(&ibss, 0, sizeof(ibss));
7238
Johannes Berg04a773a2009-04-19 21:24:32 +02007239 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7240 return -EINVAL;
7241
Johannes Berg683b6d32012-11-08 21:25:48 +01007242 if (!info->attrs[NL80211_ATTR_SSID] ||
Johannes Berg04a773a2009-04-19 21:24:32 +02007243 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7244 return -EINVAL;
7245
Johannes Berg8e30bc52009-04-22 17:45:38 +02007246 ibss.beacon_interval = 100;
7247
7248 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
7249 ibss.beacon_interval =
7250 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
7251 if (ibss.beacon_interval < 1 || ibss.beacon_interval > 10000)
7252 return -EINVAL;
7253 }
7254
Johannes Berg4c476992010-10-04 21:36:35 +02007255 if (!rdev->ops->join_ibss)
7256 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007257
Johannes Berg4c476992010-10-04 21:36:35 +02007258 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7259 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007260
Johannes Berg79c97e92009-07-07 03:56:12 +02007261 wiphy = &rdev->wiphy;
Johannes Berg04a773a2009-04-19 21:24:32 +02007262
Johannes Berg39193492011-09-16 13:45:25 +02007263 if (info->attrs[NL80211_ATTR_MAC]) {
Johannes Berg04a773a2009-04-19 21:24:32 +02007264 ibss.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Johannes Berg39193492011-09-16 13:45:25 +02007265
7266 if (!is_valid_ether_addr(ibss.bssid))
7267 return -EINVAL;
7268 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007269 ibss.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7270 ibss.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7271
7272 if (info->attrs[NL80211_ATTR_IE]) {
7273 ibss.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7274 ibss.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7275 }
7276
Johannes Berg683b6d32012-11-08 21:25:48 +01007277 err = nl80211_parse_chandef(rdev, info, &ibss.chandef);
7278 if (err)
7279 return err;
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007280
Ilan Peer174e0cd2014-02-23 09:13:01 +02007281 if (!cfg80211_reg_can_beacon(&rdev->wiphy, &ibss.chandef,
7282 NL80211_IFTYPE_ADHOC))
Alexander Simon54858ee5b2011-11-30 16:56:32 +01007283 return -EINVAL;
7284
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007285 switch (ibss.chandef.width) {
Simon Wunderlichbf372642013-07-08 16:55:58 +02007286 case NL80211_CHAN_WIDTH_5:
7287 case NL80211_CHAN_WIDTH_10:
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007288 case NL80211_CHAN_WIDTH_20_NOHT:
7289 break;
7290 case NL80211_CHAN_WIDTH_20:
7291 case NL80211_CHAN_WIDTH_40:
Janusz.Dziedzic@tieto.comffc11992015-02-21 16:52:39 +01007292 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7293 return -EINVAL;
7294 break;
7295 case NL80211_CHAN_WIDTH_80:
7296 case NL80211_CHAN_WIDTH_80P80:
7297 case NL80211_CHAN_WIDTH_160:
7298 if (!(rdev->wiphy.features & NL80211_FEATURE_HT_IBSS))
7299 return -EINVAL;
7300 if (!wiphy_ext_feature_isset(&rdev->wiphy,
7301 NL80211_EXT_FEATURE_VHT_IBSS))
7302 return -EINVAL;
7303 break;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007304 default:
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007305 return -EINVAL;
Simon Wunderlich2f301ab2013-05-16 13:00:28 +02007306 }
Johannes Bergdb9c64c2012-11-09 14:56:41 +01007307
Johannes Berg04a773a2009-04-19 21:24:32 +02007308 ibss.channel_fixed = !!info->attrs[NL80211_ATTR_FREQ_FIXED];
Johannes Bergfffd0932009-07-08 14:22:54 +02007309 ibss.privacy = !!info->attrs[NL80211_ATTR_PRIVACY];
Johannes Berg04a773a2009-04-19 21:24:32 +02007310
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007311 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
7312 u8 *rates =
7313 nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7314 int n_rates =
7315 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
7316 struct ieee80211_supported_band *sband =
Johannes Berg683b6d32012-11-08 21:25:48 +01007317 wiphy->bands[ibss.chandef.chan->band];
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007318
Johannes Berg34850ab2011-07-18 18:08:35 +02007319 err = ieee80211_get_ratemask(sband, rates, n_rates,
7320 &ibss.basic_rates);
7321 if (err)
7322 return err;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007323 }
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007324
Simon Wunderlich803768f2013-06-28 10:39:58 +02007325 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7326 memcpy(&ibss.ht_capa_mask,
7327 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7328 sizeof(ibss.ht_capa_mask));
7329
7330 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
7331 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7332 return -EINVAL;
7333 memcpy(&ibss.ht_capa,
7334 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7335 sizeof(ibss.ht_capa));
7336 }
7337
Felix Fietkaudd5b4cc2010-11-22 20:58:24 +01007338 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
7339 !nl80211_parse_mcast_rate(rdev, ibss.mcast_rate,
7340 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
7341 return -EINVAL;
Teemu Paasikivifbd2c8d2010-06-14 12:55:31 +03007342
Johannes Berg4c476992010-10-04 21:36:35 +02007343 if (ibss.privacy && info->attrs[NL80211_ATTR_KEYS]) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307344 bool no_ht = false;
7345
Johannes Berg4c476992010-10-04 21:36:35 +02007346 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307347 info->attrs[NL80211_ATTR_KEYS],
7348 &no_ht);
Johannes Berg4c476992010-10-04 21:36:35 +02007349 if (IS_ERR(connkeys))
7350 return PTR_ERR(connkeys);
Sujith Manoharande7044e2012-10-18 10:19:28 +05307351
Johannes Berg3d9d1d62012-11-08 23:14:50 +01007352 if ((ibss.chandef.width != NL80211_CHAN_WIDTH_20_NOHT) &&
7353 no_ht) {
Sujith Manoharande7044e2012-10-18 10:19:28 +05307354 kfree(connkeys);
7355 return -EINVAL;
7356 }
Johannes Berg4c476992010-10-04 21:36:35 +02007357 }
Johannes Berg04a773a2009-04-19 21:24:32 +02007358
Antonio Quartulli267335d2012-01-31 20:25:47 +01007359 ibss.control_port =
7360 nla_get_flag(info->attrs[NL80211_ATTR_CONTROL_PORT]);
7361
Simon Wunderlich5336fa82013-10-07 18:41:05 +02007362 ibss.userspace_handles_dfs =
7363 nla_get_flag(info->attrs[NL80211_ATTR_HANDLE_DFS]);
7364
Johannes Berg4c476992010-10-04 21:36:35 +02007365 err = cfg80211_join_ibss(rdev, dev, &ibss, connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007366 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007367 kzfree(connkeys);
Johannes Berg04a773a2009-04-19 21:24:32 +02007368 return err;
7369}
7370
7371static int nl80211_leave_ibss(struct sk_buff *skb, struct genl_info *info)
7372{
Johannes Berg4c476992010-10-04 21:36:35 +02007373 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7374 struct net_device *dev = info->user_ptr[1];
Johannes Berg04a773a2009-04-19 21:24:32 +02007375
Johannes Berg4c476992010-10-04 21:36:35 +02007376 if (!rdev->ops->leave_ibss)
7377 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007378
Johannes Berg4c476992010-10-04 21:36:35 +02007379 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC)
7380 return -EOPNOTSUPP;
Johannes Berg04a773a2009-04-19 21:24:32 +02007381
Johannes Berg4c476992010-10-04 21:36:35 +02007382 return cfg80211_leave_ibss(rdev, dev, false);
Johannes Berg04a773a2009-04-19 21:24:32 +02007383}
7384
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007385static int nl80211_set_mcast_rate(struct sk_buff *skb, struct genl_info *info)
7386{
7387 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7388 struct net_device *dev = info->user_ptr[1];
7389 int mcast_rate[IEEE80211_NUM_BANDS];
7390 u32 nla_rate;
7391 int err;
7392
7393 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_ADHOC &&
Bertold Van den Bergh876dc932015-08-05 16:02:21 +02007394 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_MESH_POINT &&
7395 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_OCB)
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007396 return -EOPNOTSUPP;
7397
7398 if (!rdev->ops->set_mcast_rate)
7399 return -EOPNOTSUPP;
7400
7401 memset(mcast_rate, 0, sizeof(mcast_rate));
7402
7403 if (!info->attrs[NL80211_ATTR_MCAST_RATE])
7404 return -EINVAL;
7405
7406 nla_rate = nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE]);
7407 if (!nl80211_parse_mcast_rate(rdev, mcast_rate, nla_rate))
7408 return -EINVAL;
7409
7410 err = rdev->ops->set_mcast_rate(&rdev->wiphy, dev, mcast_rate);
7411
7412 return err;
7413}
7414
Johannes Bergad7e7182013-11-13 13:37:47 +01007415static struct sk_buff *
7416__cfg80211_alloc_vendor_skb(struct cfg80211_registered_device *rdev,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007417 struct wireless_dev *wdev, int approxlen,
7418 u32 portid, u32 seq, enum nl80211_commands cmd,
Johannes Berg567ffc32013-12-18 14:43:31 +01007419 enum nl80211_attrs attr,
7420 const struct nl80211_vendor_cmd_info *info,
7421 gfp_t gfp)
Johannes Bergad7e7182013-11-13 13:37:47 +01007422{
7423 struct sk_buff *skb;
7424 void *hdr;
7425 struct nlattr *data;
7426
7427 skb = nlmsg_new(approxlen + 100, gfp);
7428 if (!skb)
7429 return NULL;
7430
7431 hdr = nl80211hdr_put(skb, portid, seq, 0, cmd);
7432 if (!hdr) {
7433 kfree_skb(skb);
7434 return NULL;
7435 }
7436
7437 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
7438 goto nla_put_failure;
Johannes Berg567ffc32013-12-18 14:43:31 +01007439
7440 if (info) {
7441 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_ID,
7442 info->vendor_id))
7443 goto nla_put_failure;
7444 if (nla_put_u32(skb, NL80211_ATTR_VENDOR_SUBCMD,
7445 info->subcmd))
7446 goto nla_put_failure;
7447 }
7448
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007449 if (wdev) {
7450 if (nla_put_u64(skb, NL80211_ATTR_WDEV,
7451 wdev_id(wdev)))
7452 goto nla_put_failure;
7453 if (wdev->netdev &&
7454 nla_put_u32(skb, NL80211_ATTR_IFINDEX,
7455 wdev->netdev->ifindex))
7456 goto nla_put_failure;
7457 }
7458
Johannes Bergad7e7182013-11-13 13:37:47 +01007459 data = nla_nest_start(skb, attr);
7460
7461 ((void **)skb->cb)[0] = rdev;
7462 ((void **)skb->cb)[1] = hdr;
7463 ((void **)skb->cb)[2] = data;
7464
7465 return skb;
7466
7467 nla_put_failure:
7468 kfree_skb(skb);
7469 return NULL;
7470}
Antonio Quartullif4e583c2012-11-02 13:27:48 +01007471
Johannes Berge03ad6e2014-01-01 17:22:30 +01007472struct sk_buff *__cfg80211_alloc_event_skb(struct wiphy *wiphy,
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007473 struct wireless_dev *wdev,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007474 enum nl80211_commands cmd,
7475 enum nl80211_attrs attr,
7476 int vendor_event_idx,
7477 int approxlen, gfp_t gfp)
7478{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08007479 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berge03ad6e2014-01-01 17:22:30 +01007480 const struct nl80211_vendor_cmd_info *info;
7481
7482 switch (cmd) {
7483 case NL80211_CMD_TESTMODE:
7484 if (WARN_ON(vendor_event_idx != -1))
7485 return NULL;
7486 info = NULL;
7487 break;
7488 case NL80211_CMD_VENDOR:
7489 if (WARN_ON(vendor_event_idx < 0 ||
7490 vendor_event_idx >= wiphy->n_vendor_events))
7491 return NULL;
7492 info = &wiphy->vendor_events[vendor_event_idx];
7493 break;
7494 default:
7495 WARN_ON(1);
7496 return NULL;
7497 }
7498
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02007499 return __cfg80211_alloc_vendor_skb(rdev, wdev, approxlen, 0, 0,
Johannes Berge03ad6e2014-01-01 17:22:30 +01007500 cmd, attr, info, gfp);
7501}
7502EXPORT_SYMBOL(__cfg80211_alloc_event_skb);
7503
7504void __cfg80211_send_event_skb(struct sk_buff *skb, gfp_t gfp)
7505{
7506 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
7507 void *hdr = ((void **)skb->cb)[1];
7508 struct nlattr *data = ((void **)skb->cb)[2];
7509 enum nl80211_multicast_groups mcgrp = NL80211_MCGRP_TESTMODE;
7510
Johannes Bergbd8c78e2014-07-30 14:55:26 +02007511 /* clear CB data for netlink core to own from now on */
7512 memset(skb->cb, 0, sizeof(skb->cb));
7513
Johannes Berge03ad6e2014-01-01 17:22:30 +01007514 nla_nest_end(skb, data);
7515 genlmsg_end(skb, hdr);
7516
7517 if (data->nla_type == NL80211_ATTR_VENDOR_DATA)
7518 mcgrp = NL80211_MCGRP_VENDOR;
7519
7520 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), skb, 0,
7521 mcgrp, gfp);
7522}
7523EXPORT_SYMBOL(__cfg80211_send_event_skb);
7524
Johannes Bergaff89a92009-07-01 21:26:51 +02007525#ifdef CONFIG_NL80211_TESTMODE
Johannes Bergaff89a92009-07-01 21:26:51 +02007526static int nl80211_testmode_do(struct sk_buff *skb, struct genl_info *info)
7527{
Johannes Berg4c476992010-10-04 21:36:35 +02007528 struct cfg80211_registered_device *rdev = info->user_ptr[0];
David Spinadelfc73f112013-07-31 18:04:15 +03007529 struct wireless_dev *wdev =
7530 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
Johannes Bergaff89a92009-07-01 21:26:51 +02007531 int err;
7532
David Spinadelfc73f112013-07-31 18:04:15 +03007533 if (!rdev->ops->testmode_cmd)
7534 return -EOPNOTSUPP;
7535
7536 if (IS_ERR(wdev)) {
7537 err = PTR_ERR(wdev);
7538 if (err != -EINVAL)
7539 return err;
7540 wdev = NULL;
7541 } else if (wdev->wiphy != &rdev->wiphy) {
7542 return -EINVAL;
7543 }
7544
Johannes Bergaff89a92009-07-01 21:26:51 +02007545 if (!info->attrs[NL80211_ATTR_TESTDATA])
7546 return -EINVAL;
7547
Johannes Bergad7e7182013-11-13 13:37:47 +01007548 rdev->cur_cmd_info = info;
David Spinadelfc73f112013-07-31 18:04:15 +03007549 err = rdev_testmode_cmd(rdev, wdev,
Johannes Bergaff89a92009-07-01 21:26:51 +02007550 nla_data(info->attrs[NL80211_ATTR_TESTDATA]),
7551 nla_len(info->attrs[NL80211_ATTR_TESTDATA]));
Johannes Bergad7e7182013-11-13 13:37:47 +01007552 rdev->cur_cmd_info = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02007553
Johannes Bergaff89a92009-07-01 21:26:51 +02007554 return err;
7555}
7556
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007557static int nl80211_testmode_dump(struct sk_buff *skb,
7558 struct netlink_callback *cb)
7559{
Johannes Berg00918d32011-12-13 17:22:05 +01007560 struct cfg80211_registered_device *rdev;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007561 int err;
7562 long phy_idx;
7563 void *data = NULL;
7564 int data_len = 0;
7565
Johannes Berg5fe231e2013-05-08 21:45:15 +02007566 rtnl_lock();
7567
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007568 if (cb->args[0]) {
7569 /*
7570 * 0 is a valid index, but not valid for args[0],
7571 * so we need to offset by 1.
7572 */
7573 phy_idx = cb->args[0] - 1;
7574 } else {
7575 err = nlmsg_parse(cb->nlh, GENL_HDRLEN + nl80211_fam.hdrsize,
7576 nl80211_fam.attrbuf, nl80211_fam.maxattr,
7577 nl80211_policy);
7578 if (err)
Johannes Berg5fe231e2013-05-08 21:45:15 +02007579 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007580
Johannes Berg2bd7e352012-06-15 14:23:16 +02007581 rdev = __cfg80211_rdev_from_attrs(sock_net(skb->sk),
7582 nl80211_fam.attrbuf);
7583 if (IS_ERR(rdev)) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007584 err = PTR_ERR(rdev);
7585 goto out_err;
Johannes Berg00918d32011-12-13 17:22:05 +01007586 }
Johannes Berg2bd7e352012-06-15 14:23:16 +02007587 phy_idx = rdev->wiphy_idx;
7588 rdev = NULL;
Johannes Berg2bd7e352012-06-15 14:23:16 +02007589
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007590 if (nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA])
7591 cb->args[1] =
7592 (long)nl80211_fam.attrbuf[NL80211_ATTR_TESTDATA];
7593 }
7594
7595 if (cb->args[1]) {
7596 data = nla_data((void *)cb->args[1]);
7597 data_len = nla_len((void *)cb->args[1]);
7598 }
7599
Johannes Berg00918d32011-12-13 17:22:05 +01007600 rdev = cfg80211_rdev_by_wiphy_idx(phy_idx);
7601 if (!rdev) {
Johannes Berg5fe231e2013-05-08 21:45:15 +02007602 err = -ENOENT;
7603 goto out_err;
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007604 }
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007605
Johannes Berg00918d32011-12-13 17:22:05 +01007606 if (!rdev->ops->testmode_dump) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007607 err = -EOPNOTSUPP;
7608 goto out_err;
7609 }
7610
7611 while (1) {
Eric W. Biederman15e47302012-09-07 20:12:54 +00007612 void *hdr = nl80211hdr_put(skb, NETLINK_CB(cb->skb).portid,
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007613 cb->nlh->nlmsg_seq, NLM_F_MULTI,
7614 NL80211_CMD_TESTMODE);
7615 struct nlattr *tmdata;
7616
Dan Carpentercb35fba2013-08-14 14:50:01 +03007617 if (!hdr)
7618 break;
7619
David S. Miller9360ffd2012-03-29 04:41:26 -04007620 if (nla_put_u32(skb, NL80211_ATTR_WIPHY, phy_idx)) {
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007621 genlmsg_cancel(skb, hdr);
7622 break;
7623 }
7624
7625 tmdata = nla_nest_start(skb, NL80211_ATTR_TESTDATA);
7626 if (!tmdata) {
7627 genlmsg_cancel(skb, hdr);
7628 break;
7629 }
Hila Gonene35e4d22012-06-27 17:19:42 +03007630 err = rdev_testmode_dump(rdev, skb, cb, data, data_len);
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007631 nla_nest_end(skb, tmdata);
7632
7633 if (err == -ENOBUFS || err == -ENOENT) {
7634 genlmsg_cancel(skb, hdr);
7635 break;
7636 } else if (err) {
7637 genlmsg_cancel(skb, hdr);
7638 goto out_err;
7639 }
7640
7641 genlmsg_end(skb, hdr);
7642 }
7643
7644 err = skb->len;
7645 /* see above */
7646 cb->args[0] = phy_idx + 1;
7647 out_err:
Johannes Berg5fe231e2013-05-08 21:45:15 +02007648 rtnl_unlock();
Wey-Yi Guy71063f02011-05-20 09:05:54 -07007649 return err;
7650}
Johannes Bergaff89a92009-07-01 21:26:51 +02007651#endif
7652
Samuel Ortizb23aa672009-07-01 21:26:54 +02007653static int nl80211_connect(struct sk_buff *skb, struct genl_info *info)
7654{
Johannes Berg4c476992010-10-04 21:36:35 +02007655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7656 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007657 struct cfg80211_connect_params connect;
7658 struct wiphy *wiphy;
Johannes Bergfffd0932009-07-08 14:22:54 +02007659 struct cfg80211_cached_keys *connkeys = NULL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007660 int err;
7661
7662 memset(&connect, 0, sizeof(connect));
7663
7664 if (!is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
7665 return -EINVAL;
7666
7667 if (!info->attrs[NL80211_ATTR_SSID] ||
7668 !nla_len(info->attrs[NL80211_ATTR_SSID]))
7669 return -EINVAL;
7670
7671 if (info->attrs[NL80211_ATTR_AUTH_TYPE]) {
7672 connect.auth_type =
7673 nla_get_u32(info->attrs[NL80211_ATTR_AUTH_TYPE]);
Jouni Malinene39e5b52012-09-30 19:29:39 +03007674 if (!nl80211_valid_auth_type(rdev, connect.auth_type,
7675 NL80211_CMD_CONNECT))
Samuel Ortizb23aa672009-07-01 21:26:54 +02007676 return -EINVAL;
7677 } else
7678 connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
7679
7680 connect.privacy = info->attrs[NL80211_ATTR_PRIVACY];
7681
Johannes Bergc0692b82010-08-27 14:26:53 +03007682 err = nl80211_crypto_settings(rdev, info, &connect.crypto,
Johannes Berg3dc27d22009-07-02 21:36:37 +02007683 NL80211_MAX_NR_CIPHER_SUITES);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007684 if (err)
7685 return err;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007686
Johannes Berg074ac8d2010-09-16 14:58:22 +02007687 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007688 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7689 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007690
Johannes Berg79c97e92009-07-07 03:56:12 +02007691 wiphy = &rdev->wiphy;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007692
Bala Shanmugam4486ea92012-03-07 17:27:12 +05307693 connect.bg_scan_period = -1;
7694 if (info->attrs[NL80211_ATTR_BG_SCAN_PERIOD] &&
7695 (wiphy->flags & WIPHY_FLAG_SUPPORTS_FW_ROAM)) {
7696 connect.bg_scan_period =
7697 nla_get_u16(info->attrs[NL80211_ATTR_BG_SCAN_PERIOD]);
7698 }
7699
Samuel Ortizb23aa672009-07-01 21:26:54 +02007700 if (info->attrs[NL80211_ATTR_MAC])
7701 connect.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
Jouni Malinen1df4a512014-01-15 00:00:47 +02007702 else if (info->attrs[NL80211_ATTR_MAC_HINT])
7703 connect.bssid_hint =
7704 nla_data(info->attrs[NL80211_ATTR_MAC_HINT]);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007705 connect.ssid = nla_data(info->attrs[NL80211_ATTR_SSID]);
7706 connect.ssid_len = nla_len(info->attrs[NL80211_ATTR_SSID]);
7707
7708 if (info->attrs[NL80211_ATTR_IE]) {
7709 connect.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
7710 connect.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
7711 }
7712
Jouni Malinencee00a92013-01-15 17:15:57 +02007713 if (info->attrs[NL80211_ATTR_USE_MFP]) {
7714 connect.mfp = nla_get_u32(info->attrs[NL80211_ATTR_USE_MFP]);
7715 if (connect.mfp != NL80211_MFP_REQUIRED &&
7716 connect.mfp != NL80211_MFP_NO)
7717 return -EINVAL;
7718 } else {
7719 connect.mfp = NL80211_MFP_NO;
7720 }
7721
Samuel Ortizb23aa672009-07-01 21:26:54 +02007722 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007723 connect.channel = nl80211_get_valid_chan(
7724 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ]);
7725 if (!connect.channel)
Johannes Berg4c476992010-10-04 21:36:35 +02007726 return -EINVAL;
Jouni Malinen1df4a512014-01-15 00:00:47 +02007727 } else if (info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]) {
Jouni Malinen664834d2014-01-15 00:01:44 +02007728 connect.channel_hint = nl80211_get_valid_chan(
7729 wiphy, info->attrs[NL80211_ATTR_WIPHY_FREQ_HINT]);
7730 if (!connect.channel_hint)
Jouni Malinen1df4a512014-01-15 00:00:47 +02007731 return -EINVAL;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007732 }
7733
Johannes Bergfffd0932009-07-08 14:22:54 +02007734 if (connect.privacy && info->attrs[NL80211_ATTR_KEYS]) {
7735 connkeys = nl80211_parse_connkeys(rdev,
Sujith Manoharande7044e2012-10-18 10:19:28 +05307736 info->attrs[NL80211_ATTR_KEYS], NULL);
Johannes Berg4c476992010-10-04 21:36:35 +02007737 if (IS_ERR(connkeys))
7738 return PTR_ERR(connkeys);
Johannes Bergfffd0932009-07-08 14:22:54 +02007739 }
7740
Ben Greear7e7c8922011-11-18 11:31:59 -08007741 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_HT]))
7742 connect.flags |= ASSOC_REQ_DISABLE_HT;
7743
7744 if (info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK])
7745 memcpy(&connect.ht_capa_mask,
7746 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]),
7747 sizeof(connect.ht_capa_mask));
7748
7749 if (info->attrs[NL80211_ATTR_HT_CAPABILITY]) {
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007750 if (!info->attrs[NL80211_ATTR_HT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007751 kzfree(connkeys);
Ben Greear7e7c8922011-11-18 11:31:59 -08007752 return -EINVAL;
Wei Yongjunb4e4f472012-09-02 21:41:04 +08007753 }
Ben Greear7e7c8922011-11-18 11:31:59 -08007754 memcpy(&connect.ht_capa,
7755 nla_data(info->attrs[NL80211_ATTR_HT_CAPABILITY]),
7756 sizeof(connect.ht_capa));
7757 }
7758
Johannes Bergee2aca32013-02-21 17:36:01 +01007759 if (nla_get_flag(info->attrs[NL80211_ATTR_DISABLE_VHT]))
7760 connect.flags |= ASSOC_REQ_DISABLE_VHT;
7761
7762 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK])
7763 memcpy(&connect.vht_capa_mask,
7764 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]),
7765 sizeof(connect.vht_capa_mask));
7766
7767 if (info->attrs[NL80211_ATTR_VHT_CAPABILITY]) {
7768 if (!info->attrs[NL80211_ATTR_VHT_CAPABILITY_MASK]) {
Johannes Bergb47f6102014-09-10 13:39:54 +03007769 kzfree(connkeys);
Johannes Bergee2aca32013-02-21 17:36:01 +01007770 return -EINVAL;
7771 }
7772 memcpy(&connect.vht_capa,
7773 nla_data(info->attrs[NL80211_ATTR_VHT_CAPABILITY]),
7774 sizeof(connect.vht_capa));
7775 }
7776
Assaf Kraussbab5ab72014-09-03 15:25:01 +03007777 if (nla_get_flag(info->attrs[NL80211_ATTR_USE_RRM])) {
7778 if (!(rdev->wiphy.features &
7779 NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES) ||
7780 !(rdev->wiphy.features & NL80211_FEATURE_QUIET))
7781 return -EINVAL;
7782 connect.flags |= ASSOC_REQ_USE_RRM;
7783 }
7784
Johannes Berg83739b02013-05-15 17:44:01 +02007785 wdev_lock(dev->ieee80211_ptr);
7786 err = cfg80211_connect(rdev, dev, &connect, connkeys, NULL);
7787 wdev_unlock(dev->ieee80211_ptr);
Johannes Bergfffd0932009-07-08 14:22:54 +02007788 if (err)
Johannes Bergb47f6102014-09-10 13:39:54 +03007789 kzfree(connkeys);
Samuel Ortizb23aa672009-07-01 21:26:54 +02007790 return err;
7791}
7792
7793static int nl80211_disconnect(struct sk_buff *skb, struct genl_info *info)
7794{
Johannes Berg4c476992010-10-04 21:36:35 +02007795 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7796 struct net_device *dev = info->user_ptr[1];
Samuel Ortizb23aa672009-07-01 21:26:54 +02007797 u16 reason;
Johannes Berg83739b02013-05-15 17:44:01 +02007798 int ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007799
7800 if (!info->attrs[NL80211_ATTR_REASON_CODE])
7801 reason = WLAN_REASON_DEAUTH_LEAVING;
7802 else
7803 reason = nla_get_u16(info->attrs[NL80211_ATTR_REASON_CODE]);
7804
7805 if (reason == 0)
7806 return -EINVAL;
7807
Johannes Berg074ac8d2010-09-16 14:58:22 +02007808 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007809 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7810 return -EOPNOTSUPP;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007811
Johannes Berg83739b02013-05-15 17:44:01 +02007812 wdev_lock(dev->ieee80211_ptr);
7813 ret = cfg80211_disconnect(rdev, dev, reason, true);
7814 wdev_unlock(dev->ieee80211_ptr);
7815 return ret;
Samuel Ortizb23aa672009-07-01 21:26:54 +02007816}
7817
Johannes Berg463d0182009-07-14 00:33:35 +02007818static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
7819{
Johannes Berg4c476992010-10-04 21:36:35 +02007820 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg463d0182009-07-14 00:33:35 +02007821 struct net *net;
7822 int err;
Johannes Berg463d0182009-07-14 00:33:35 +02007823
Vadim Kochan4b681c82015-01-12 16:34:05 +02007824 if (info->attrs[NL80211_ATTR_PID]) {
7825 u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
7826
7827 net = get_net_ns_by_pid(pid);
7828 } else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
7829 u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
7830
7831 net = get_net_ns_by_fd(fd);
7832 } else {
Johannes Berg463d0182009-07-14 00:33:35 +02007833 return -EINVAL;
Vadim Kochan4b681c82015-01-12 16:34:05 +02007834 }
Johannes Berg463d0182009-07-14 00:33:35 +02007835
Johannes Berg4c476992010-10-04 21:36:35 +02007836 if (IS_ERR(net))
7837 return PTR_ERR(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007838
7839 err = 0;
7840
7841 /* check if anything to do */
Johannes Berg4c476992010-10-04 21:36:35 +02007842 if (!net_eq(wiphy_net(&rdev->wiphy), net))
7843 err = cfg80211_switch_netns(rdev, net);
Johannes Berg463d0182009-07-14 00:33:35 +02007844
Johannes Berg463d0182009-07-14 00:33:35 +02007845 put_net(net);
Johannes Berg463d0182009-07-14 00:33:35 +02007846 return err;
7847}
7848
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007849static int nl80211_setdel_pmksa(struct sk_buff *skb, struct genl_info *info)
7850{
Johannes Berg4c476992010-10-04 21:36:35 +02007851 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007852 int (*rdev_ops)(struct wiphy *wiphy, struct net_device *dev,
7853 struct cfg80211_pmksa *pmksa) = NULL;
Johannes Berg4c476992010-10-04 21:36:35 +02007854 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007855 struct cfg80211_pmksa pmksa;
7856
7857 memset(&pmksa, 0, sizeof(struct cfg80211_pmksa));
7858
7859 if (!info->attrs[NL80211_ATTR_MAC])
7860 return -EINVAL;
7861
7862 if (!info->attrs[NL80211_ATTR_PMKID])
7863 return -EINVAL;
7864
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007865 pmksa.pmkid = nla_data(info->attrs[NL80211_ATTR_PMKID]);
7866 pmksa.bssid = nla_data(info->attrs[NL80211_ATTR_MAC]);
7867
Johannes Berg074ac8d2010-09-16 14:58:22 +02007868 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007869 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7870 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007871
7872 switch (info->genlhdr->cmd) {
7873 case NL80211_CMD_SET_PMKSA:
7874 rdev_ops = rdev->ops->set_pmksa;
7875 break;
7876 case NL80211_CMD_DEL_PMKSA:
7877 rdev_ops = rdev->ops->del_pmksa;
7878 break;
7879 default:
7880 WARN_ON(1);
7881 break;
7882 }
7883
Johannes Berg4c476992010-10-04 21:36:35 +02007884 if (!rdev_ops)
7885 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007886
Johannes Berg4c476992010-10-04 21:36:35 +02007887 return rdev_ops(&rdev->wiphy, dev, &pmksa);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007888}
7889
7890static int nl80211_flush_pmksa(struct sk_buff *skb, struct genl_info *info)
7891{
Johannes Berg4c476992010-10-04 21:36:35 +02007892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7893 struct net_device *dev = info->user_ptr[1];
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007894
Johannes Berg074ac8d2010-09-16 14:58:22 +02007895 if (dev->ieee80211_ptr->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02007896 dev->ieee80211_ptr->iftype != NL80211_IFTYPE_P2P_CLIENT)
7897 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007898
Johannes Berg4c476992010-10-04 21:36:35 +02007899 if (!rdev->ops->flush_pmksa)
7900 return -EOPNOTSUPP;
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007901
Hila Gonene35e4d22012-06-27 17:19:42 +03007902 return rdev_flush_pmksa(rdev, dev);
Samuel Ortiz67fbb162009-11-24 23:59:15 +01007903}
7904
Arik Nemtsov109086c2011-09-28 14:12:50 +03007905static int nl80211_tdls_mgmt(struct sk_buff *skb, struct genl_info *info)
7906{
7907 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7908 struct net_device *dev = info->user_ptr[1];
7909 u8 action_code, dialog_token;
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307910 u32 peer_capability = 0;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007911 u16 status_code;
7912 u8 *peer;
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007913 bool initiator;
Arik Nemtsov109086c2011-09-28 14:12:50 +03007914
7915 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7916 !rdev->ops->tdls_mgmt)
7917 return -EOPNOTSUPP;
7918
7919 if (!info->attrs[NL80211_ATTR_TDLS_ACTION] ||
7920 !info->attrs[NL80211_ATTR_STATUS_CODE] ||
7921 !info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN] ||
7922 !info->attrs[NL80211_ATTR_IE] ||
7923 !info->attrs[NL80211_ATTR_MAC])
7924 return -EINVAL;
7925
7926 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7927 action_code = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_ACTION]);
7928 status_code = nla_get_u16(info->attrs[NL80211_ATTR_STATUS_CODE]);
7929 dialog_token = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_DIALOG_TOKEN]);
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007930 initiator = nla_get_flag(info->attrs[NL80211_ATTR_TDLS_INITIATOR]);
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307931 if (info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY])
7932 peer_capability =
7933 nla_get_u32(info->attrs[NL80211_ATTR_TDLS_PEER_CAPABILITY]);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007934
Hila Gonene35e4d22012-06-27 17:19:42 +03007935 return rdev_tdls_mgmt(rdev, dev, peer, action_code,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05307936 dialog_token, status_code, peer_capability,
Arik Nemtsov31fa97c2014-06-11 17:18:21 +03007937 initiator,
Hila Gonene35e4d22012-06-27 17:19:42 +03007938 nla_data(info->attrs[NL80211_ATTR_IE]),
7939 nla_len(info->attrs[NL80211_ATTR_IE]));
Arik Nemtsov109086c2011-09-28 14:12:50 +03007940}
7941
7942static int nl80211_tdls_oper(struct sk_buff *skb, struct genl_info *info)
7943{
7944 struct cfg80211_registered_device *rdev = info->user_ptr[0];
7945 struct net_device *dev = info->user_ptr[1];
7946 enum nl80211_tdls_operation operation;
7947 u8 *peer;
7948
7949 if (!(rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_TDLS) ||
7950 !rdev->ops->tdls_oper)
7951 return -EOPNOTSUPP;
7952
7953 if (!info->attrs[NL80211_ATTR_TDLS_OPERATION] ||
7954 !info->attrs[NL80211_ATTR_MAC])
7955 return -EINVAL;
7956
7957 operation = nla_get_u8(info->attrs[NL80211_ATTR_TDLS_OPERATION]);
7958 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
7959
Hila Gonene35e4d22012-06-27 17:19:42 +03007960 return rdev_tdls_oper(rdev, dev, peer, operation);
Arik Nemtsov109086c2011-09-28 14:12:50 +03007961}
7962
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007963static int nl80211_remain_on_channel(struct sk_buff *skb,
7964 struct genl_info *info)
7965{
Johannes Berg4c476992010-10-04 21:36:35 +02007966 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02007967 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01007968 struct cfg80211_chan_def chandef;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007969 struct sk_buff *msg;
7970 void *hdr;
7971 u64 cookie;
Johannes Berg683b6d32012-11-08 21:25:48 +01007972 u32 duration;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007973 int err;
7974
7975 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ] ||
7976 !info->attrs[NL80211_ATTR_DURATION])
7977 return -EINVAL;
7978
7979 duration = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
7980
Johannes Berg7c4ef712011-11-18 15:33:48 +01007981 if (!rdev->ops->remain_on_channel ||
7982 !(rdev->wiphy.flags & WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL))
Johannes Berg4c476992010-10-04 21:36:35 +02007983 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007984
Johannes Bergebf348f2012-06-01 12:50:54 +02007985 /*
7986 * We should be on that channel for at least a minimum amount of
7987 * time (10ms) but no longer than the driver supports.
7988 */
7989 if (duration < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
7990 duration > rdev->wiphy.max_remain_on_channel_duration)
7991 return -EINVAL;
7992
Johannes Berg683b6d32012-11-08 21:25:48 +01007993 err = nl80211_parse_chandef(rdev, info, &chandef);
7994 if (err)
7995 return err;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01007996
7997 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02007998 if (!msg)
7999 return -ENOMEM;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008000
Eric W. Biederman15e47302012-09-07 20:12:54 +00008001 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008002 NL80211_CMD_REMAIN_ON_CHANNEL);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008003 if (!hdr) {
8004 err = -ENOBUFS;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008005 goto free_msg;
8006 }
8007
Johannes Berg683b6d32012-11-08 21:25:48 +01008008 err = rdev_remain_on_channel(rdev, wdev, chandef.chan,
8009 duration, &cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008010
8011 if (err)
8012 goto free_msg;
8013
David S. Miller9360ffd2012-03-29 04:41:26 -04008014 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8015 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008016
8017 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008018
8019 return genlmsg_reply(msg, info);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008020
8021 nla_put_failure:
8022 err = -ENOBUFS;
8023 free_msg:
8024 nlmsg_free(msg);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008025 return err;
8026}
8027
8028static int nl80211_cancel_remain_on_channel(struct sk_buff *skb,
8029 struct genl_info *info)
8030{
Johannes Berg4c476992010-10-04 21:36:35 +02008031 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008032 struct wireless_dev *wdev = info->user_ptr[1];
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008033 u64 cookie;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008034
8035 if (!info->attrs[NL80211_ATTR_COOKIE])
8036 return -EINVAL;
8037
Johannes Berg4c476992010-10-04 21:36:35 +02008038 if (!rdev->ops->cancel_remain_on_channel)
8039 return -EOPNOTSUPP;
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008040
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008041 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8042
Hila Gonene35e4d22012-06-27 17:19:42 +03008043 return rdev_cancel_remain_on_channel(rdev, wdev, cookie);
Jouni Malinen9588bbd2009-12-23 13:15:41 +01008044}
8045
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008046static u32 rateset_to_mask(struct ieee80211_supported_band *sband,
8047 u8 *rates, u8 rates_len)
8048{
8049 u8 i;
8050 u32 mask = 0;
8051
8052 for (i = 0; i < rates_len; i++) {
8053 int rate = (rates[i] & 0x7f) * 5;
8054 int ridx;
8055 for (ridx = 0; ridx < sband->n_bitrates; ridx++) {
8056 struct ieee80211_rate *srate =
8057 &sband->bitrates[ridx];
8058 if (rate == srate->bitrate) {
8059 mask |= 1 << ridx;
8060 break;
8061 }
8062 }
8063 if (ridx == sband->n_bitrates)
8064 return 0; /* rate not found */
8065 }
8066
8067 return mask;
8068}
8069
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008070static bool ht_rateset_to_mask(struct ieee80211_supported_band *sband,
8071 u8 *rates, u8 rates_len,
8072 u8 mcs[IEEE80211_HT_MCS_MASK_LEN])
8073{
8074 u8 i;
8075
8076 memset(mcs, 0, IEEE80211_HT_MCS_MASK_LEN);
8077
8078 for (i = 0; i < rates_len; i++) {
8079 int ridx, rbit;
8080
8081 ridx = rates[i] / 8;
8082 rbit = BIT(rates[i] % 8);
8083
8084 /* check validity */
Dan Carpenter910570b52012-02-01 10:42:11 +03008085 if ((ridx < 0) || (ridx >= IEEE80211_HT_MCS_MASK_LEN))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008086 return false;
8087
8088 /* check availability */
8089 if (sband->ht_cap.mcs.rx_mask[ridx] & rbit)
8090 mcs[ridx] |= rbit;
8091 else
8092 return false;
8093 }
8094
8095 return true;
8096}
8097
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008098static u16 vht_mcs_map_to_mcs_mask(u8 vht_mcs_map)
8099{
8100 u16 mcs_mask = 0;
8101
8102 switch (vht_mcs_map) {
8103 case IEEE80211_VHT_MCS_NOT_SUPPORTED:
8104 break;
8105 case IEEE80211_VHT_MCS_SUPPORT_0_7:
8106 mcs_mask = 0x00FF;
8107 break;
8108 case IEEE80211_VHT_MCS_SUPPORT_0_8:
8109 mcs_mask = 0x01FF;
8110 break;
8111 case IEEE80211_VHT_MCS_SUPPORT_0_9:
8112 mcs_mask = 0x03FF;
8113 break;
8114 default:
8115 break;
8116 }
8117
8118 return mcs_mask;
8119}
8120
8121static void vht_build_mcs_mask(u16 vht_mcs_map,
8122 u16 vht_mcs_mask[NL80211_VHT_NSS_MAX])
8123{
8124 u8 nss;
8125
8126 for (nss = 0; nss < NL80211_VHT_NSS_MAX; nss++) {
8127 vht_mcs_mask[nss] = vht_mcs_map_to_mcs_mask(vht_mcs_map & 0x03);
8128 vht_mcs_map >>= 2;
8129 }
8130}
8131
8132static bool vht_set_mcs_mask(struct ieee80211_supported_band *sband,
8133 struct nl80211_txrate_vht *txrate,
8134 u16 mcs[NL80211_VHT_NSS_MAX])
8135{
8136 u16 tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8137 u16 tx_mcs_mask[NL80211_VHT_NSS_MAX] = {};
8138 u8 i;
8139
8140 if (!sband->vht_cap.vht_supported)
8141 return false;
8142
8143 memset(mcs, 0, sizeof(u16) * NL80211_VHT_NSS_MAX);
8144
8145 /* Build vht_mcs_mask from VHT capabilities */
8146 vht_build_mcs_mask(tx_mcs_map, tx_mcs_mask);
8147
8148 for (i = 0; i < NL80211_VHT_NSS_MAX; i++) {
8149 if ((tx_mcs_mask[i] & txrate->mcs[i]) == txrate->mcs[i])
8150 mcs[i] = txrate->mcs[i];
8151 else
8152 return false;
8153 }
8154
8155 return true;
8156}
8157
Alexey Dobriyanb54452b2010-02-18 08:14:31 +00008158static const struct nla_policy nl80211_txattr_policy[NL80211_TXRATE_MAX + 1] = {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008159 [NL80211_TXRATE_LEGACY] = { .type = NLA_BINARY,
8160 .len = NL80211_MAX_SUPP_RATES },
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008161 [NL80211_TXRATE_HT] = { .type = NLA_BINARY,
8162 .len = NL80211_MAX_SUPP_HT_RATES },
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008163 [NL80211_TXRATE_VHT] = { .len = sizeof(struct nl80211_txrate_vht)},
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008164 [NL80211_TXRATE_GI] = { .type = NLA_U8 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008165};
8166
8167static int nl80211_set_tx_bitrate_mask(struct sk_buff *skb,
8168 struct genl_info *info)
8169{
8170 struct nlattr *tb[NL80211_TXRATE_MAX + 1];
Johannes Berg4c476992010-10-04 21:36:35 +02008171 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008172 struct cfg80211_bitrate_mask mask;
Johannes Berg4c476992010-10-04 21:36:35 +02008173 int rem, i;
8174 struct net_device *dev = info->user_ptr[1];
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008175 struct nlattr *tx_rates;
8176 struct ieee80211_supported_band *sband;
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008177 u16 vht_tx_mcs_map;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008178
Johannes Berg4c476992010-10-04 21:36:35 +02008179 if (!rdev->ops->set_bitrate_mask)
8180 return -EOPNOTSUPP;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008181
8182 memset(&mask, 0, sizeof(mask));
8183 /* Default to all rates enabled */
8184 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
8185 sband = rdev->wiphy.bands[i];
Janusz Dziedzic78693032013-12-03 09:50:44 +01008186
8187 if (!sband)
8188 continue;
8189
8190 mask.control[i].legacy = (1 << sband->n_bitrates) - 1;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008191 memcpy(mask.control[i].ht_mcs,
Janusz Dziedzic78693032013-12-03 09:50:44 +01008192 sband->ht_cap.mcs.rx_mask,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008193 sizeof(mask.control[i].ht_mcs));
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008194
8195 if (!sband->vht_cap.vht_supported)
8196 continue;
8197
8198 vht_tx_mcs_map = le16_to_cpu(sband->vht_cap.vht_mcs.tx_mcs_map);
8199 vht_build_mcs_mask(vht_tx_mcs_map, mask.control[i].vht_mcs);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008200 }
8201
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008202 /* if no rates are given set it back to the defaults */
8203 if (!info->attrs[NL80211_ATTR_TX_RATES])
8204 goto out;
8205
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008206 /*
8207 * The nested attribute uses enum nl80211_band as the index. This maps
8208 * directly to the enum ieee80211_band values used in cfg80211.
8209 */
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008210 BUILD_BUG_ON(NL80211_MAX_SUPP_HT_RATES > IEEE80211_HT_MCS_MASK_LEN * 8);
Johannes Bergae811e22014-01-24 10:17:47 +01008211 nla_for_each_nested(tx_rates, info->attrs[NL80211_ATTR_TX_RATES], rem) {
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008212 enum ieee80211_band band = nla_type(tx_rates);
Johannes Bergae811e22014-01-24 10:17:47 +01008213 int err;
8214
Johannes Berg4c476992010-10-04 21:36:35 +02008215 if (band < 0 || band >= IEEE80211_NUM_BANDS)
8216 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008217 sband = rdev->wiphy.bands[band];
Johannes Berg4c476992010-10-04 21:36:35 +02008218 if (sband == NULL)
8219 return -EINVAL;
Johannes Bergae811e22014-01-24 10:17:47 +01008220 err = nla_parse(tb, NL80211_TXRATE_MAX, nla_data(tx_rates),
8221 nla_len(tx_rates), nl80211_txattr_policy);
8222 if (err)
8223 return err;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008224 if (tb[NL80211_TXRATE_LEGACY]) {
8225 mask.control[band].legacy = rateset_to_mask(
8226 sband,
8227 nla_data(tb[NL80211_TXRATE_LEGACY]),
8228 nla_len(tb[NL80211_TXRATE_LEGACY]));
Bala Shanmugam218d2e22012-04-20 19:12:58 +05308229 if ((mask.control[band].legacy == 0) &&
8230 nla_len(tb[NL80211_TXRATE_LEGACY]))
8231 return -EINVAL;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008232 }
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008233 if (tb[NL80211_TXRATE_HT]) {
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008234 if (!ht_rateset_to_mask(
8235 sband,
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008236 nla_data(tb[NL80211_TXRATE_HT]),
8237 nla_len(tb[NL80211_TXRATE_HT]),
8238 mask.control[band].ht_mcs))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008239 return -EINVAL;
8240 }
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008241 if (tb[NL80211_TXRATE_VHT]) {
8242 if (!vht_set_mcs_mask(
8243 sband,
8244 nla_data(tb[NL80211_TXRATE_VHT]),
8245 mask.control[band].vht_mcs))
8246 return -EINVAL;
8247 }
Janusz Dziedzic0b9323f2014-01-08 08:46:02 +01008248 if (tb[NL80211_TXRATE_GI]) {
8249 mask.control[band].gi =
8250 nla_get_u8(tb[NL80211_TXRATE_GI]);
8251 if (mask.control[band].gi > NL80211_TXRATE_FORCE_LGI)
8252 return -EINVAL;
8253 }
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008254
8255 if (mask.control[band].legacy == 0) {
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008256 /* don't allow empty legacy rates if HT or VHT
8257 * are not even supported.
8258 */
8259 if (!(rdev->wiphy.bands[band]->ht_cap.ht_supported ||
8260 rdev->wiphy.bands[band]->vht_cap.vht_supported))
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008261 return -EINVAL;
8262
8263 for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++)
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01008264 if (mask.control[band].ht_mcs[i])
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008265 goto out;
8266
8267 for (i = 0; i < NL80211_VHT_NSS_MAX; i++)
8268 if (mask.control[band].vht_mcs[i])
8269 goto out;
Simon Wunderlich24db78c2012-01-28 17:25:32 +01008270
8271 /* legacy and mcs rates may not be both empty */
Janusz Dziedzic204e35a2013-12-05 20:42:58 +01008272 return -EINVAL;
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008273 }
8274 }
8275
Janusz Dziedzicb9243ab2013-12-05 10:02:14 +01008276out:
Hila Gonene35e4d22012-06-27 17:19:42 +03008277 return rdev_set_bitrate_mask(rdev, dev, NULL, &mask);
Jouni Malinen13ae75b2009-12-29 12:59:45 +02008278}
8279
Johannes Berg2e161f72010-08-12 15:38:38 +02008280static int nl80211_register_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008281{
Johannes Berg4c476992010-10-04 21:36:35 +02008282 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008283 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg2e161f72010-08-12 15:38:38 +02008284 u16 frame_type = IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_ACTION;
Jouni Malinen026331c2010-02-15 12:53:10 +02008285
8286 if (!info->attrs[NL80211_ATTR_FRAME_MATCH])
8287 return -EINVAL;
8288
Johannes Berg2e161f72010-08-12 15:38:38 +02008289 if (info->attrs[NL80211_ATTR_FRAME_TYPE])
8290 frame_type = nla_get_u16(info->attrs[NL80211_ATTR_FRAME_TYPE]);
Jouni Malinen026331c2010-02-15 12:53:10 +02008291
Johannes Berg71bbc992012-06-15 15:30:18 +02008292 switch (wdev->iftype) {
8293 case NL80211_IFTYPE_STATION:
8294 case NL80211_IFTYPE_ADHOC:
8295 case NL80211_IFTYPE_P2P_CLIENT:
8296 case NL80211_IFTYPE_AP:
8297 case NL80211_IFTYPE_AP_VLAN:
8298 case NL80211_IFTYPE_MESH_POINT:
8299 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008300 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008301 break;
8302 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008303 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008304 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008305
8306 /* not much point in registering if we can't reply */
Johannes Berg4c476992010-10-04 21:36:35 +02008307 if (!rdev->ops->mgmt_tx)
8308 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008309
Eric W. Biederman15e47302012-09-07 20:12:54 +00008310 return cfg80211_mlme_register_mgmt(wdev, info->snd_portid, frame_type,
Jouni Malinen026331c2010-02-15 12:53:10 +02008311 nla_data(info->attrs[NL80211_ATTR_FRAME_MATCH]),
8312 nla_len(info->attrs[NL80211_ATTR_FRAME_MATCH]));
Jouni Malinen026331c2010-02-15 12:53:10 +02008313}
8314
Johannes Berg2e161f72010-08-12 15:38:38 +02008315static int nl80211_tx_mgmt(struct sk_buff *skb, struct genl_info *info)
Jouni Malinen026331c2010-02-15 12:53:10 +02008316{
Johannes Berg4c476992010-10-04 21:36:35 +02008317 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008318 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Berg683b6d32012-11-08 21:25:48 +01008319 struct cfg80211_chan_def chandef;
Jouni Malinen026331c2010-02-15 12:53:10 +02008320 int err;
Johannes Bergd64d3732011-11-10 09:44:46 +01008321 void *hdr = NULL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008322 u64 cookie;
Johannes Berge247bd902011-11-04 11:18:21 +01008323 struct sk_buff *msg = NULL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008324 struct cfg80211_mgmt_tx_params params = {
8325 .dont_wait_for_ack =
8326 info->attrs[NL80211_ATTR_DONT_WAIT_FOR_ACK],
8327 };
Jouni Malinen026331c2010-02-15 12:53:10 +02008328
Johannes Berg683b6d32012-11-08 21:25:48 +01008329 if (!info->attrs[NL80211_ATTR_FRAME])
Jouni Malinen026331c2010-02-15 12:53:10 +02008330 return -EINVAL;
8331
Johannes Berg4c476992010-10-04 21:36:35 +02008332 if (!rdev->ops->mgmt_tx)
8333 return -EOPNOTSUPP;
Jouni Malinen026331c2010-02-15 12:53:10 +02008334
Johannes Berg71bbc992012-06-15 15:30:18 +02008335 switch (wdev->iftype) {
Antonio Quartulliea141b752013-06-11 14:20:03 +02008336 case NL80211_IFTYPE_P2P_DEVICE:
8337 if (!info->attrs[NL80211_ATTR_WIPHY_FREQ])
8338 return -EINVAL;
Johannes Berg71bbc992012-06-15 15:30:18 +02008339 case NL80211_IFTYPE_STATION:
8340 case NL80211_IFTYPE_ADHOC:
8341 case NL80211_IFTYPE_P2P_CLIENT:
8342 case NL80211_IFTYPE_AP:
8343 case NL80211_IFTYPE_AP_VLAN:
8344 case NL80211_IFTYPE_MESH_POINT:
8345 case NL80211_IFTYPE_P2P_GO:
8346 break;
8347 default:
Johannes Berg4c476992010-10-04 21:36:35 +02008348 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008349 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008350
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008351 if (info->attrs[NL80211_ATTR_DURATION]) {
Johannes Berg7c4ef712011-11-18 15:33:48 +01008352 if (!(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008353 return -EINVAL;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008354 params.wait = nla_get_u32(info->attrs[NL80211_ATTR_DURATION]);
Johannes Bergebf348f2012-06-01 12:50:54 +02008355
8356 /*
8357 * We should wait on the channel for at least a minimum amount
8358 * of time (10ms) but no longer than the driver supports.
8359 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008360 if (params.wait < NL80211_MIN_REMAIN_ON_CHANNEL_TIME ||
8361 params.wait > rdev->wiphy.max_remain_on_channel_duration)
Johannes Bergebf348f2012-06-01 12:50:54 +02008362 return -EINVAL;
8363
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008364 }
8365
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008366 params.offchan = info->attrs[NL80211_ATTR_OFFCHANNEL_TX_OK];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008367
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008368 if (params.offchan && !(rdev->wiphy.flags & WIPHY_FLAG_OFFCHAN_TX))
Johannes Berg7c4ef712011-11-18 15:33:48 +01008369 return -EINVAL;
8370
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008371 params.no_cck = nla_get_flag(info->attrs[NL80211_ATTR_TX_NO_CCK_RATE]);
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05308372
Antonio Quartulliea141b752013-06-11 14:20:03 +02008373 /* get the channel if any has been specified, otherwise pass NULL to
8374 * the driver. The latter will use the current one
8375 */
8376 chandef.chan = NULL;
8377 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
8378 err = nl80211_parse_chandef(rdev, info, &chandef);
8379 if (err)
8380 return err;
8381 }
8382
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008383 if (!chandef.chan && params.offchan)
Antonio Quartulliea141b752013-06-11 14:20:03 +02008384 return -EINVAL;
Jouni Malinen026331c2010-02-15 12:53:10 +02008385
Andrei Otcheretianski34d22ce2014-05-09 14:11:44 +03008386 params.buf = nla_data(info->attrs[NL80211_ATTR_FRAME]);
8387 params.len = nla_len(info->attrs[NL80211_ATTR_FRAME]);
8388
8389 if (info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]) {
8390 int len = nla_len(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8391 int i;
8392
8393 if (len % sizeof(u16))
8394 return -EINVAL;
8395
8396 params.n_csa_offsets = len / sizeof(u16);
8397 params.csa_offsets =
8398 nla_data(info->attrs[NL80211_ATTR_CSA_C_OFFSETS_TX]);
8399
8400 /* check that all the offsets fit the frame */
8401 for (i = 0; i < params.n_csa_offsets; i++) {
8402 if (params.csa_offsets[i] >= params.len)
8403 return -EINVAL;
8404 }
8405 }
8406
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008407 if (!params.dont_wait_for_ack) {
Johannes Berge247bd902011-11-04 11:18:21 +01008408 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
8409 if (!msg)
8410 return -ENOMEM;
Jouni Malinen026331c2010-02-15 12:53:10 +02008411
Eric W. Biederman15e47302012-09-07 20:12:54 +00008412 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berge247bd902011-11-04 11:18:21 +01008413 NL80211_CMD_FRAME);
Dan Carpentercb35fba2013-08-14 14:50:01 +03008414 if (!hdr) {
8415 err = -ENOBUFS;
Johannes Berge247bd902011-11-04 11:18:21 +01008416 goto free_msg;
8417 }
Jouni Malinen026331c2010-02-15 12:53:10 +02008418 }
Johannes Berge247bd902011-11-04 11:18:21 +01008419
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02008420 params.chan = chandef.chan;
8421 err = cfg80211_mlme_mgmt_tx(rdev, wdev, &params, &cookie);
Jouni Malinen026331c2010-02-15 12:53:10 +02008422 if (err)
8423 goto free_msg;
8424
Johannes Berge247bd902011-11-04 11:18:21 +01008425 if (msg) {
David S. Miller9360ffd2012-03-29 04:41:26 -04008426 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
8427 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +02008428
Johannes Berge247bd902011-11-04 11:18:21 +01008429 genlmsg_end(msg, hdr);
8430 return genlmsg_reply(msg, info);
8431 }
8432
8433 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02008434
8435 nla_put_failure:
8436 err = -ENOBUFS;
8437 free_msg:
8438 nlmsg_free(msg);
Jouni Malinen026331c2010-02-15 12:53:10 +02008439 return err;
8440}
8441
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008442static int nl80211_tx_mgmt_cancel_wait(struct sk_buff *skb, struct genl_info *info)
8443{
8444 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg71bbc992012-06-15 15:30:18 +02008445 struct wireless_dev *wdev = info->user_ptr[1];
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008446 u64 cookie;
8447
8448 if (!info->attrs[NL80211_ATTR_COOKIE])
8449 return -EINVAL;
8450
8451 if (!rdev->ops->mgmt_tx_cancel_wait)
8452 return -EOPNOTSUPP;
8453
Johannes Berg71bbc992012-06-15 15:30:18 +02008454 switch (wdev->iftype) {
8455 case NL80211_IFTYPE_STATION:
8456 case NL80211_IFTYPE_ADHOC:
8457 case NL80211_IFTYPE_P2P_CLIENT:
8458 case NL80211_IFTYPE_AP:
8459 case NL80211_IFTYPE_AP_VLAN:
8460 case NL80211_IFTYPE_P2P_GO:
Johannes Berg98104fde2012-06-16 00:19:54 +02008461 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg71bbc992012-06-15 15:30:18 +02008462 break;
8463 default:
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008464 return -EOPNOTSUPP;
Johannes Berg71bbc992012-06-15 15:30:18 +02008465 }
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008466
8467 cookie = nla_get_u64(info->attrs[NL80211_ATTR_COOKIE]);
8468
Hila Gonene35e4d22012-06-27 17:19:42 +03008469 return rdev_mgmt_tx_cancel_wait(rdev, wdev, cookie);
Johannes Bergf7ca38d2010-11-25 10:02:29 +01008470}
8471
Kalle Valoffb9eb32010-02-17 17:58:10 +02008472static int nl80211_set_power_save(struct sk_buff *skb, struct genl_info *info)
8473{
Johannes Berg4c476992010-10-04 21:36:35 +02008474 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008475 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008476 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008477 u8 ps_state;
8478 bool state;
8479 int err;
8480
Johannes Berg4c476992010-10-04 21:36:35 +02008481 if (!info->attrs[NL80211_ATTR_PS_STATE])
8482 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008483
8484 ps_state = nla_get_u32(info->attrs[NL80211_ATTR_PS_STATE]);
8485
Johannes Berg4c476992010-10-04 21:36:35 +02008486 if (ps_state != NL80211_PS_DISABLED && ps_state != NL80211_PS_ENABLED)
8487 return -EINVAL;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008488
8489 wdev = dev->ieee80211_ptr;
8490
Johannes Berg4c476992010-10-04 21:36:35 +02008491 if (!rdev->ops->set_power_mgmt)
8492 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008493
8494 state = (ps_state == NL80211_PS_ENABLED) ? true : false;
8495
8496 if (state == wdev->ps)
Johannes Berg4c476992010-10-04 21:36:35 +02008497 return 0;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008498
Hila Gonene35e4d22012-06-27 17:19:42 +03008499 err = rdev_set_power_mgmt(rdev, dev, state, wdev->ps_timeout);
Johannes Berg4c476992010-10-04 21:36:35 +02008500 if (!err)
8501 wdev->ps = state;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008502 return err;
8503}
8504
8505static int nl80211_get_power_save(struct sk_buff *skb, struct genl_info *info)
8506{
Johannes Berg4c476992010-10-04 21:36:35 +02008507 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008508 enum nl80211_ps_state ps_state;
8509 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +02008510 struct net_device *dev = info->user_ptr[1];
Kalle Valoffb9eb32010-02-17 17:58:10 +02008511 struct sk_buff *msg;
8512 void *hdr;
8513 int err;
8514
Kalle Valoffb9eb32010-02-17 17:58:10 +02008515 wdev = dev->ieee80211_ptr;
8516
Johannes Berg4c476992010-10-04 21:36:35 +02008517 if (!rdev->ops->set_power_mgmt)
8518 return -EOPNOTSUPP;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008519
8520 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg4c476992010-10-04 21:36:35 +02008521 if (!msg)
8522 return -ENOMEM;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008523
Eric W. Biederman15e47302012-09-07 20:12:54 +00008524 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Kalle Valoffb9eb32010-02-17 17:58:10 +02008525 NL80211_CMD_GET_POWER_SAVE);
8526 if (!hdr) {
Johannes Berg4c476992010-10-04 21:36:35 +02008527 err = -ENOBUFS;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008528 goto free_msg;
8529 }
8530
8531 if (wdev->ps)
8532 ps_state = NL80211_PS_ENABLED;
8533 else
8534 ps_state = NL80211_PS_DISABLED;
8535
David S. Miller9360ffd2012-03-29 04:41:26 -04008536 if (nla_put_u32(msg, NL80211_ATTR_PS_STATE, ps_state))
8537 goto nla_put_failure;
Kalle Valoffb9eb32010-02-17 17:58:10 +02008538
8539 genlmsg_end(msg, hdr);
Johannes Berg4c476992010-10-04 21:36:35 +02008540 return genlmsg_reply(msg, info);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008541
Johannes Berg4c476992010-10-04 21:36:35 +02008542 nla_put_failure:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008543 err = -ENOBUFS;
Johannes Berg4c476992010-10-04 21:36:35 +02008544 free_msg:
Kalle Valoffb9eb32010-02-17 17:58:10 +02008545 nlmsg_free(msg);
Kalle Valoffb9eb32010-02-17 17:58:10 +02008546 return err;
8547}
8548
Johannes Berg94e860f2014-01-20 23:58:15 +01008549static const struct nla_policy
8550nl80211_attr_cqm_policy[NL80211_ATTR_CQM_MAX + 1] = {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008551 [NL80211_ATTR_CQM_RSSI_THOLD] = { .type = NLA_U32 },
8552 [NL80211_ATTR_CQM_RSSI_HYST] = { .type = NLA_U32 },
8553 [NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT] = { .type = NLA_U32 },
Thomas Pedersen84f10702012-07-12 16:17:33 -07008554 [NL80211_ATTR_CQM_TXE_RATE] = { .type = NLA_U32 },
8555 [NL80211_ATTR_CQM_TXE_PKTS] = { .type = NLA_U32 },
8556 [NL80211_ATTR_CQM_TXE_INTVL] = { .type = NLA_U32 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008557};
8558
Thomas Pedersen84f10702012-07-12 16:17:33 -07008559static int nl80211_set_cqm_txe(struct genl_info *info,
Johannes Bergd9d8b012012-11-26 12:51:52 +01008560 u32 rate, u32 pkts, u32 intvl)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008561{
8562 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Thomas Pedersen84f10702012-07-12 16:17:33 -07008563 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008564 struct wireless_dev *wdev = dev->ieee80211_ptr;
Thomas Pedersen84f10702012-07-12 16:17:33 -07008565
Johannes Bergd9d8b012012-11-26 12:51:52 +01008566 if (rate > 100 || intvl > NL80211_CQM_TXE_MAX_INTVL)
Thomas Pedersen84f10702012-07-12 16:17:33 -07008567 return -EINVAL;
8568
Thomas Pedersen84f10702012-07-12 16:17:33 -07008569 if (!rdev->ops->set_cqm_txe_config)
8570 return -EOPNOTSUPP;
8571
8572 if (wdev->iftype != NL80211_IFTYPE_STATION &&
8573 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8574 return -EOPNOTSUPP;
8575
Hila Gonene35e4d22012-06-27 17:19:42 +03008576 return rdev_set_cqm_txe_config(rdev, dev, rate, pkts, intvl);
Thomas Pedersen84f10702012-07-12 16:17:33 -07008577}
8578
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008579static int nl80211_set_cqm_rssi(struct genl_info *info,
8580 s32 threshold, u32 hysteresis)
8581{
Johannes Berg4c476992010-10-04 21:36:35 +02008582 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Johannes Berg4c476992010-10-04 21:36:35 +02008583 struct net_device *dev = info->user_ptr[1];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008584 struct wireless_dev *wdev = dev->ieee80211_ptr;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008585
8586 if (threshold > 0)
8587 return -EINVAL;
8588
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008589 /* disabling - hysteresis should also be zero then */
8590 if (threshold == 0)
8591 hysteresis = 0;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008592
Johannes Berg4c476992010-10-04 21:36:35 +02008593 if (!rdev->ops->set_cqm_rssi_config)
8594 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008595
Johannes Berg074ac8d2010-09-16 14:58:22 +02008596 if (wdev->iftype != NL80211_IFTYPE_STATION &&
Johannes Berg4c476992010-10-04 21:36:35 +02008597 wdev->iftype != NL80211_IFTYPE_P2P_CLIENT)
8598 return -EOPNOTSUPP;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008599
Hila Gonene35e4d22012-06-27 17:19:42 +03008600 return rdev_set_cqm_rssi_config(rdev, dev, threshold, hysteresis);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008601}
8602
8603static int nl80211_set_cqm(struct sk_buff *skb, struct genl_info *info)
8604{
8605 struct nlattr *attrs[NL80211_ATTR_CQM_MAX + 1];
8606 struct nlattr *cqm;
8607 int err;
8608
8609 cqm = info->attrs[NL80211_ATTR_CQM];
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008610 if (!cqm)
8611 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008612
8613 err = nla_parse_nested(attrs, NL80211_ATTR_CQM_MAX, cqm,
8614 nl80211_attr_cqm_policy);
8615 if (err)
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008616 return err;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008617
8618 if (attrs[NL80211_ATTR_CQM_RSSI_THOLD] &&
8619 attrs[NL80211_ATTR_CQM_RSSI_HYST]) {
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008620 s32 threshold = nla_get_s32(attrs[NL80211_ATTR_CQM_RSSI_THOLD]);
8621 u32 hysteresis = nla_get_u32(attrs[NL80211_ATTR_CQM_RSSI_HYST]);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008622
Johannes Berg1da5fcc2013-08-06 14:10:48 +02008623 return nl80211_set_cqm_rssi(info, threshold, hysteresis);
8624 }
8625
8626 if (attrs[NL80211_ATTR_CQM_TXE_RATE] &&
8627 attrs[NL80211_ATTR_CQM_TXE_PKTS] &&
8628 attrs[NL80211_ATTR_CQM_TXE_INTVL]) {
8629 u32 rate = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_RATE]);
8630 u32 pkts = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_PKTS]);
8631 u32 intvl = nla_get_u32(attrs[NL80211_ATTR_CQM_TXE_INTVL]);
8632
8633 return nl80211_set_cqm_txe(info, rate, pkts, intvl);
8634 }
8635
8636 return -EINVAL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +02008637}
8638
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +01008639static int nl80211_join_ocb(struct sk_buff *skb, struct genl_info *info)
8640{
8641 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8642 struct net_device *dev = info->user_ptr[1];
8643 struct ocb_setup setup = {};
8644 int err;
8645
8646 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8647 if (err)
8648 return err;
8649
8650 return cfg80211_join_ocb(rdev, dev, &setup);
8651}
8652
8653static int nl80211_leave_ocb(struct sk_buff *skb, struct genl_info *info)
8654{
8655 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8656 struct net_device *dev = info->user_ptr[1];
8657
8658 return cfg80211_leave_ocb(rdev, dev);
8659}
8660
Johannes Berg29cbe682010-12-03 09:20:44 +01008661static int nl80211_join_mesh(struct sk_buff *skb, struct genl_info *info)
8662{
8663 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8664 struct net_device *dev = info->user_ptr[1];
8665 struct mesh_config cfg;
Javier Cardonac80d5452010-12-16 17:37:49 -08008666 struct mesh_setup setup;
Johannes Berg29cbe682010-12-03 09:20:44 +01008667 int err;
8668
8669 /* start with default */
8670 memcpy(&cfg, &default_mesh_config, sizeof(cfg));
Javier Cardonac80d5452010-12-16 17:37:49 -08008671 memcpy(&setup, &default_mesh_setup, sizeof(setup));
Johannes Berg29cbe682010-12-03 09:20:44 +01008672
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008673 if (info->attrs[NL80211_ATTR_MESH_CONFIG]) {
Johannes Berg29cbe682010-12-03 09:20:44 +01008674 /* and parse parameters if given */
Javier Cardona24bdd9f2010-12-16 17:37:48 -08008675 err = nl80211_parse_mesh_config(info, &cfg, NULL);
Johannes Berg29cbe682010-12-03 09:20:44 +01008676 if (err)
8677 return err;
8678 }
8679
8680 if (!info->attrs[NL80211_ATTR_MESH_ID] ||
8681 !nla_len(info->attrs[NL80211_ATTR_MESH_ID]))
8682 return -EINVAL;
8683
Javier Cardonac80d5452010-12-16 17:37:49 -08008684 setup.mesh_id = nla_data(info->attrs[NL80211_ATTR_MESH_ID]);
8685 setup.mesh_id_len = nla_len(info->attrs[NL80211_ATTR_MESH_ID]);
8686
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08008687 if (info->attrs[NL80211_ATTR_MCAST_RATE] &&
8688 !nl80211_parse_mcast_rate(rdev, setup.mcast_rate,
8689 nla_get_u32(info->attrs[NL80211_ATTR_MCAST_RATE])))
8690 return -EINVAL;
8691
Marco Porsch9bdbf042013-01-07 16:04:51 +01008692 if (info->attrs[NL80211_ATTR_BEACON_INTERVAL]) {
8693 setup.beacon_interval =
8694 nla_get_u32(info->attrs[NL80211_ATTR_BEACON_INTERVAL]);
8695 if (setup.beacon_interval < 10 ||
8696 setup.beacon_interval > 10000)
8697 return -EINVAL;
8698 }
8699
8700 if (info->attrs[NL80211_ATTR_DTIM_PERIOD]) {
8701 setup.dtim_period =
8702 nla_get_u32(info->attrs[NL80211_ATTR_DTIM_PERIOD]);
8703 if (setup.dtim_period < 1 || setup.dtim_period > 100)
8704 return -EINVAL;
8705 }
8706
Javier Cardonac80d5452010-12-16 17:37:49 -08008707 if (info->attrs[NL80211_ATTR_MESH_SETUP]) {
8708 /* parse additional setup parameters if given */
8709 err = nl80211_parse_mesh_setup(info, &setup);
8710 if (err)
8711 return err;
8712 }
8713
Thomas Pedersend37bb182013-03-04 13:06:13 -08008714 if (setup.user_mpm)
8715 cfg.auto_open_plinks = false;
8716
Johannes Bergcc1d2802012-05-16 23:50:20 +02008717 if (info->attrs[NL80211_ATTR_WIPHY_FREQ]) {
Johannes Berg683b6d32012-11-08 21:25:48 +01008718 err = nl80211_parse_chandef(rdev, info, &setup.chandef);
8719 if (err)
8720 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008721 } else {
8722 /* cfg80211_join_mesh() will sort it out */
Johannes Berg683b6d32012-11-08 21:25:48 +01008723 setup.chandef.chan = NULL;
Johannes Bergcc1d2802012-05-16 23:50:20 +02008724 }
8725
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07008726 if (info->attrs[NL80211_ATTR_BSS_BASIC_RATES]) {
8727 u8 *rates = nla_data(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8728 int n_rates =
8729 nla_len(info->attrs[NL80211_ATTR_BSS_BASIC_RATES]);
8730 struct ieee80211_supported_band *sband;
8731
8732 if (!setup.chandef.chan)
8733 return -EINVAL;
8734
8735 sband = rdev->wiphy.bands[setup.chandef.chan->band];
8736
8737 err = ieee80211_get_ratemask(sband, rates, n_rates,
8738 &setup.basic_rates);
8739 if (err)
8740 return err;
8741 }
8742
Javier Cardonac80d5452010-12-16 17:37:49 -08008743 return cfg80211_join_mesh(rdev, dev, &setup, &cfg);
Johannes Berg29cbe682010-12-03 09:20:44 +01008744}
8745
8746static int nl80211_leave_mesh(struct sk_buff *skb, struct genl_info *info)
8747{
8748 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8749 struct net_device *dev = info->user_ptr[1];
8750
8751 return cfg80211_leave_mesh(rdev, dev);
8752}
8753
Johannes Bergdfb89c52012-06-27 09:23:48 +02008754#ifdef CONFIG_PM
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008755static int nl80211_send_wowlan_patterns(struct sk_buff *msg,
8756 struct cfg80211_registered_device *rdev)
8757{
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008758 struct cfg80211_wowlan *wowlan = rdev->wiphy.wowlan_config;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008759 struct nlattr *nl_pats, *nl_pat;
8760 int i, pat_len;
8761
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008762 if (!wowlan->n_patterns)
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008763 return 0;
8764
8765 nl_pats = nla_nest_start(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN);
8766 if (!nl_pats)
8767 return -ENOBUFS;
8768
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008769 for (i = 0; i < wowlan->n_patterns; i++) {
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008770 nl_pat = nla_nest_start(msg, i + 1);
8771 if (!nl_pat)
8772 return -ENOBUFS;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008773 pat_len = wowlan->patterns[i].pattern_len;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008774 if (nla_put(msg, NL80211_PKTPAT_MASK, DIV_ROUND_UP(pat_len, 8),
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008775 wowlan->patterns[i].mask) ||
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07008776 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
8777 wowlan->patterns[i].pattern) ||
8778 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008779 wowlan->patterns[i].pkt_offset))
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008780 return -ENOBUFS;
8781 nla_nest_end(msg, nl_pat);
8782 }
8783 nla_nest_end(msg, nl_pats);
8784
8785 return 0;
8786}
8787
Johannes Berg2a0e0472013-01-23 22:57:40 +01008788static int nl80211_send_wowlan_tcp(struct sk_buff *msg,
8789 struct cfg80211_wowlan_tcp *tcp)
8790{
8791 struct nlattr *nl_tcp;
8792
8793 if (!tcp)
8794 return 0;
8795
8796 nl_tcp = nla_nest_start(msg, NL80211_WOWLAN_TRIG_TCP_CONNECTION);
8797 if (!nl_tcp)
8798 return -ENOBUFS;
8799
Jiri Benc930345e2015-03-29 16:59:25 +02008800 if (nla_put_in_addr(msg, NL80211_WOWLAN_TCP_SRC_IPV4, tcp->src) ||
8801 nla_put_in_addr(msg, NL80211_WOWLAN_TCP_DST_IPV4, tcp->dst) ||
Johannes Berg2a0e0472013-01-23 22:57:40 +01008802 nla_put(msg, NL80211_WOWLAN_TCP_DST_MAC, ETH_ALEN, tcp->dst_mac) ||
8803 nla_put_u16(msg, NL80211_WOWLAN_TCP_SRC_PORT, tcp->src_port) ||
8804 nla_put_u16(msg, NL80211_WOWLAN_TCP_DST_PORT, tcp->dst_port) ||
8805 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD,
8806 tcp->payload_len, tcp->payload) ||
8807 nla_put_u32(msg, NL80211_WOWLAN_TCP_DATA_INTERVAL,
8808 tcp->data_interval) ||
8809 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_PAYLOAD,
8810 tcp->wake_len, tcp->wake_data) ||
8811 nla_put(msg, NL80211_WOWLAN_TCP_WAKE_MASK,
8812 DIV_ROUND_UP(tcp->wake_len, 8), tcp->wake_mask))
8813 return -ENOBUFS;
8814
8815 if (tcp->payload_seq.len &&
8816 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ,
8817 sizeof(tcp->payload_seq), &tcp->payload_seq))
8818 return -ENOBUFS;
8819
8820 if (tcp->payload_tok.len &&
8821 nla_put(msg, NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN,
8822 sizeof(tcp->payload_tok) + tcp->tokens_size,
8823 &tcp->payload_tok))
8824 return -ENOBUFS;
8825
Johannes Berge248ad32013-05-16 10:24:28 +02008826 nla_nest_end(msg, nl_tcp);
8827
Johannes Berg2a0e0472013-01-23 22:57:40 +01008828 return 0;
8829}
8830
Luciano Coelho75453cc2015-01-09 14:06:37 +02008831static int nl80211_send_wowlan_nd(struct sk_buff *msg,
8832 struct cfg80211_sched_scan_request *req)
8833{
8834 struct nlattr *nd, *freqs, *matches, *match;
8835 int i;
8836
8837 if (!req)
8838 return 0;
8839
8840 nd = nla_nest_start(msg, NL80211_WOWLAN_TRIG_NET_DETECT);
8841 if (!nd)
8842 return -ENOBUFS;
8843
8844 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_INTERVAL, req->interval))
8845 return -ENOBUFS;
8846
Luciano Coelho21fea562015-03-17 16:36:01 +02008847 if (nla_put_u32(msg, NL80211_ATTR_SCHED_SCAN_DELAY, req->delay))
8848 return -ENOBUFS;
8849
Luciano Coelho75453cc2015-01-09 14:06:37 +02008850 freqs = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
8851 if (!freqs)
8852 return -ENOBUFS;
8853
8854 for (i = 0; i < req->n_channels; i++)
8855 nla_put_u32(msg, i, req->channels[i]->center_freq);
8856
8857 nla_nest_end(msg, freqs);
8858
8859 if (req->n_match_sets) {
8860 matches = nla_nest_start(msg, NL80211_ATTR_SCHED_SCAN_MATCH);
8861 for (i = 0; i < req->n_match_sets; i++) {
8862 match = nla_nest_start(msg, i);
8863 nla_put(msg, NL80211_SCHED_SCAN_MATCH_ATTR_SSID,
8864 req->match_sets[i].ssid.ssid_len,
8865 req->match_sets[i].ssid.ssid);
8866 nla_nest_end(msg, match);
8867 }
8868 nla_nest_end(msg, matches);
8869 }
8870
8871 nla_nest_end(msg, nd);
8872
8873 return 0;
8874}
8875
Johannes Bergff1b6e62011-05-04 15:37:28 +02008876static int nl80211_get_wowlan(struct sk_buff *skb, struct genl_info *info)
8877{
8878 struct cfg80211_registered_device *rdev = info->user_ptr[0];
8879 struct sk_buff *msg;
8880 void *hdr;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008881 u32 size = NLMSG_DEFAULT_SIZE;
Johannes Bergff1b6e62011-05-04 15:37:28 +02008882
Johannes Berg964dc9e2013-06-03 17:25:34 +02008883 if (!rdev->wiphy.wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02008884 return -EOPNOTSUPP;
8885
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008886 if (rdev->wiphy.wowlan_config && rdev->wiphy.wowlan_config->tcp) {
Johannes Berg2a0e0472013-01-23 22:57:40 +01008887 /* adjust size to have room for all the data */
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008888 size += rdev->wiphy.wowlan_config->tcp->tokens_size +
8889 rdev->wiphy.wowlan_config->tcp->payload_len +
8890 rdev->wiphy.wowlan_config->tcp->wake_len +
8891 rdev->wiphy.wowlan_config->tcp->wake_len / 8;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008892 }
8893
8894 msg = nlmsg_new(size, GFP_KERNEL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02008895 if (!msg)
8896 return -ENOMEM;
8897
Eric W. Biederman15e47302012-09-07 20:12:54 +00008898 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Bergff1b6e62011-05-04 15:37:28 +02008899 NL80211_CMD_GET_WOWLAN);
8900 if (!hdr)
8901 goto nla_put_failure;
8902
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008903 if (rdev->wiphy.wowlan_config) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02008904 struct nlattr *nl_wowlan;
8905
8906 nl_wowlan = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
8907 if (!nl_wowlan)
8908 goto nla_put_failure;
8909
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008910 if ((rdev->wiphy.wowlan_config->any &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008911 nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008912 (rdev->wiphy.wowlan_config->disconnect &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008913 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008914 (rdev->wiphy.wowlan_config->magic_pkt &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008915 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008916 (rdev->wiphy.wowlan_config->gtk_rekey_failure &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008917 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008918 (rdev->wiphy.wowlan_config->eap_identity_req &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008919 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008920 (rdev->wiphy.wowlan_config->four_way_handshake &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008921 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008922 (rdev->wiphy.wowlan_config->rfkill_release &&
David S. Miller9360ffd2012-03-29 04:41:26 -04008923 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE)))
8924 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008925
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08008926 if (nl80211_send_wowlan_patterns(msg, rdev))
8927 goto nla_put_failure;
Johannes Berg2a0e0472013-01-23 22:57:40 +01008928
Johannes Berg6abb9cb2013-05-15 09:30:07 +02008929 if (nl80211_send_wowlan_tcp(msg,
8930 rdev->wiphy.wowlan_config->tcp))
Johannes Berg2a0e0472013-01-23 22:57:40 +01008931 goto nla_put_failure;
8932
Luciano Coelho75453cc2015-01-09 14:06:37 +02008933 if (nl80211_send_wowlan_nd(
8934 msg,
8935 rdev->wiphy.wowlan_config->nd_config))
8936 goto nla_put_failure;
8937
Johannes Bergff1b6e62011-05-04 15:37:28 +02008938 nla_nest_end(msg, nl_wowlan);
8939 }
8940
8941 genlmsg_end(msg, hdr);
8942 return genlmsg_reply(msg, info);
8943
8944nla_put_failure:
8945 nlmsg_free(msg);
8946 return -ENOBUFS;
8947}
8948
Johannes Berg2a0e0472013-01-23 22:57:40 +01008949static int nl80211_parse_wowlan_tcp(struct cfg80211_registered_device *rdev,
8950 struct nlattr *attr,
8951 struct cfg80211_wowlan *trig)
8952{
8953 struct nlattr *tb[NUM_NL80211_WOWLAN_TCP];
8954 struct cfg80211_wowlan_tcp *cfg;
8955 struct nl80211_wowlan_tcp_data_token *tok = NULL;
8956 struct nl80211_wowlan_tcp_data_seq *seq = NULL;
8957 u32 size;
8958 u32 data_size, wake_size, tokens_size = 0, wake_mask_size;
8959 int err, port;
8960
Johannes Berg964dc9e2013-06-03 17:25:34 +02008961 if (!rdev->wiphy.wowlan->tcp)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008962 return -EINVAL;
8963
8964 err = nla_parse(tb, MAX_NL80211_WOWLAN_TCP,
8965 nla_data(attr), nla_len(attr),
8966 nl80211_wowlan_tcp_policy);
8967 if (err)
8968 return err;
8969
8970 if (!tb[NL80211_WOWLAN_TCP_SRC_IPV4] ||
8971 !tb[NL80211_WOWLAN_TCP_DST_IPV4] ||
8972 !tb[NL80211_WOWLAN_TCP_DST_MAC] ||
8973 !tb[NL80211_WOWLAN_TCP_DST_PORT] ||
8974 !tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD] ||
8975 !tb[NL80211_WOWLAN_TCP_DATA_INTERVAL] ||
8976 !tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD] ||
8977 !tb[NL80211_WOWLAN_TCP_WAKE_MASK])
8978 return -EINVAL;
8979
8980 data_size = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008981 if (data_size > rdev->wiphy.wowlan->tcp->data_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008982 return -EINVAL;
8983
8984 if (nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) >
Johannes Berg964dc9e2013-06-03 17:25:34 +02008985 rdev->wiphy.wowlan->tcp->data_interval_max ||
Johannes Berg723d5682013-02-26 13:56:40 +01008986 nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]) == 0)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008987 return -EINVAL;
8988
8989 wake_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02008990 if (wake_size > rdev->wiphy.wowlan->tcp->wake_payload_max)
Johannes Berg2a0e0472013-01-23 22:57:40 +01008991 return -EINVAL;
8992
8993 wake_mask_size = nla_len(tb[NL80211_WOWLAN_TCP_WAKE_MASK]);
8994 if (wake_mask_size != DIV_ROUND_UP(wake_size, 8))
8995 return -EINVAL;
8996
8997 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]) {
8998 u32 tokln = nla_len(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
8999
9000 tok = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_TOKEN]);
9001 tokens_size = tokln - sizeof(*tok);
9002
9003 if (!tok->len || tokens_size % tok->len)
9004 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009005 if (!rdev->wiphy.wowlan->tcp->tok)
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->max_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009008 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009009 if (tok->len < rdev->wiphy.wowlan->tcp->tok->min_len)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009010 return -EINVAL;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009011 if (tokens_size > rdev->wiphy.wowlan->tcp->tok->bufsize)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009012 return -EINVAL;
9013 if (tok->offset + tok->len > data_size)
9014 return -EINVAL;
9015 }
9016
9017 if (tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]) {
9018 seq = nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD_SEQ]);
Johannes Berg964dc9e2013-06-03 17:25:34 +02009019 if (!rdev->wiphy.wowlan->tcp->seq)
Johannes Berg2a0e0472013-01-23 22:57:40 +01009020 return -EINVAL;
9021 if (seq->len == 0 || seq->len > 4)
9022 return -EINVAL;
9023 if (seq->len + seq->offset > data_size)
9024 return -EINVAL;
9025 }
9026
9027 size = sizeof(*cfg);
9028 size += data_size;
9029 size += wake_size + wake_mask_size;
9030 size += tokens_size;
9031
9032 cfg = kzalloc(size, GFP_KERNEL);
9033 if (!cfg)
9034 return -ENOMEM;
Jiri Benc67b61f62015-03-29 16:59:26 +02009035 cfg->src = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_SRC_IPV4]);
9036 cfg->dst = nla_get_in_addr(tb[NL80211_WOWLAN_TCP_DST_IPV4]);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009037 memcpy(cfg->dst_mac, nla_data(tb[NL80211_WOWLAN_TCP_DST_MAC]),
9038 ETH_ALEN);
9039 if (tb[NL80211_WOWLAN_TCP_SRC_PORT])
9040 port = nla_get_u16(tb[NL80211_WOWLAN_TCP_SRC_PORT]);
9041 else
9042 port = 0;
9043#ifdef CONFIG_INET
9044 /* allocate a socket and port for it and use it */
9045 err = __sock_create(wiphy_net(&rdev->wiphy), PF_INET, SOCK_STREAM,
9046 IPPROTO_TCP, &cfg->sock, 1);
9047 if (err) {
9048 kfree(cfg);
9049 return err;
9050 }
9051 if (inet_csk_get_port(cfg->sock->sk, port)) {
9052 sock_release(cfg->sock);
9053 kfree(cfg);
9054 return -EADDRINUSE;
9055 }
9056 cfg->src_port = inet_sk(cfg->sock->sk)->inet_num;
9057#else
9058 if (!port) {
9059 kfree(cfg);
9060 return -EINVAL;
9061 }
9062 cfg->src_port = port;
9063#endif
9064
9065 cfg->dst_port = nla_get_u16(tb[NL80211_WOWLAN_TCP_DST_PORT]);
9066 cfg->payload_len = data_size;
9067 cfg->payload = (u8 *)cfg + sizeof(*cfg) + tokens_size;
9068 memcpy((void *)cfg->payload,
9069 nla_data(tb[NL80211_WOWLAN_TCP_DATA_PAYLOAD]),
9070 data_size);
9071 if (seq)
9072 cfg->payload_seq = *seq;
9073 cfg->data_interval = nla_get_u32(tb[NL80211_WOWLAN_TCP_DATA_INTERVAL]);
9074 cfg->wake_len = wake_size;
9075 cfg->wake_data = (u8 *)cfg + sizeof(*cfg) + tokens_size + data_size;
9076 memcpy((void *)cfg->wake_data,
9077 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_PAYLOAD]),
9078 wake_size);
9079 cfg->wake_mask = (u8 *)cfg + sizeof(*cfg) + tokens_size +
9080 data_size + wake_size;
9081 memcpy((void *)cfg->wake_mask,
9082 nla_data(tb[NL80211_WOWLAN_TCP_WAKE_MASK]),
9083 wake_mask_size);
9084 if (tok) {
9085 cfg->tokens_size = tokens_size;
9086 memcpy(&cfg->payload_tok, tok, sizeof(*tok) + tokens_size);
9087 }
9088
9089 trig->tcp = cfg;
9090
9091 return 0;
9092}
9093
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009094static int nl80211_parse_wowlan_nd(struct cfg80211_registered_device *rdev,
9095 const struct wiphy_wowlan_support *wowlan,
9096 struct nlattr *attr,
9097 struct cfg80211_wowlan *trig)
9098{
9099 struct nlattr **tb;
9100 int err;
9101
9102 tb = kzalloc(NUM_NL80211_ATTR * sizeof(*tb), GFP_KERNEL);
9103 if (!tb)
9104 return -ENOMEM;
9105
9106 if (!(wowlan->flags & WIPHY_WOWLAN_NET_DETECT)) {
9107 err = -EOPNOTSUPP;
9108 goto out;
9109 }
9110
9111 err = nla_parse(tb, NL80211_ATTR_MAX,
9112 nla_data(attr), nla_len(attr),
9113 nl80211_policy);
9114 if (err)
9115 goto out;
9116
Johannes Bergad2b26a2014-06-12 21:39:05 +02009117 trig->nd_config = nl80211_parse_sched_scan(&rdev->wiphy, NULL, tb);
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009118 err = PTR_ERR_OR_ZERO(trig->nd_config);
9119 if (err)
9120 trig->nd_config = NULL;
9121
9122out:
9123 kfree(tb);
9124 return err;
9125}
9126
Johannes Bergff1b6e62011-05-04 15:37:28 +02009127static int nl80211_set_wowlan(struct sk_buff *skb, struct genl_info *info)
9128{
9129 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9130 struct nlattr *tb[NUM_NL80211_WOWLAN_TRIG];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009131 struct cfg80211_wowlan new_triggers = {};
Johannes Bergae33bd82012-07-12 16:25:02 +02009132 struct cfg80211_wowlan *ntrig;
Johannes Berg964dc9e2013-06-03 17:25:34 +02009133 const struct wiphy_wowlan_support *wowlan = rdev->wiphy.wowlan;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009134 int err, i;
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009135 bool prev_enabled = rdev->wiphy.wowlan_config;
Johannes Berg98fc4382015-03-01 09:10:13 +02009136 bool regular = false;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009137
Johannes Berg964dc9e2013-06-03 17:25:34 +02009138 if (!wowlan)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009139 return -EOPNOTSUPP;
9140
Johannes Bergae33bd82012-07-12 16:25:02 +02009141 if (!info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]) {
9142 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009143 rdev->wiphy.wowlan_config = NULL;
Johannes Bergae33bd82012-07-12 16:25:02 +02009144 goto set_wakeup;
9145 }
Johannes Bergff1b6e62011-05-04 15:37:28 +02009146
9147 err = nla_parse(tb, MAX_NL80211_WOWLAN_TRIG,
9148 nla_data(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9149 nla_len(info->attrs[NL80211_ATTR_WOWLAN_TRIGGERS]),
9150 nl80211_wowlan_policy);
9151 if (err)
9152 return err;
9153
9154 if (tb[NL80211_WOWLAN_TRIG_ANY]) {
9155 if (!(wowlan->flags & WIPHY_WOWLAN_ANY))
9156 return -EINVAL;
9157 new_triggers.any = true;
9158 }
9159
9160 if (tb[NL80211_WOWLAN_TRIG_DISCONNECT]) {
9161 if (!(wowlan->flags & WIPHY_WOWLAN_DISCONNECT))
9162 return -EINVAL;
9163 new_triggers.disconnect = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009164 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009165 }
9166
9167 if (tb[NL80211_WOWLAN_TRIG_MAGIC_PKT]) {
9168 if (!(wowlan->flags & WIPHY_WOWLAN_MAGIC_PKT))
9169 return -EINVAL;
9170 new_triggers.magic_pkt = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009171 regular = true;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009172 }
9173
Johannes Berg77dbbb12011-07-13 10:48:55 +02009174 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_SUPPORTED])
9175 return -EINVAL;
9176
9177 if (tb[NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE]) {
9178 if (!(wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE))
9179 return -EINVAL;
9180 new_triggers.gtk_rekey_failure = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009181 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009182 }
9183
9184 if (tb[NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST]) {
9185 if (!(wowlan->flags & WIPHY_WOWLAN_EAP_IDENTITY_REQ))
9186 return -EINVAL;
9187 new_triggers.eap_identity_req = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009188 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009189 }
9190
9191 if (tb[NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE]) {
9192 if (!(wowlan->flags & WIPHY_WOWLAN_4WAY_HANDSHAKE))
9193 return -EINVAL;
9194 new_triggers.four_way_handshake = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009195 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009196 }
9197
9198 if (tb[NL80211_WOWLAN_TRIG_RFKILL_RELEASE]) {
9199 if (!(wowlan->flags & WIPHY_WOWLAN_RFKILL_RELEASE))
9200 return -EINVAL;
9201 new_triggers.rfkill_release = true;
Johannes Berg98fc4382015-03-01 09:10:13 +02009202 regular = true;
Johannes Berg77dbbb12011-07-13 10:48:55 +02009203 }
9204
Johannes Bergff1b6e62011-05-04 15:37:28 +02009205 if (tb[NL80211_WOWLAN_TRIG_PKT_PATTERN]) {
9206 struct nlattr *pat;
9207 int n_patterns = 0;
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009208 int rem, pat_len, mask_len, pkt_offset;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009209 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
Johannes Bergff1b6e62011-05-04 15:37:28 +02009210
Johannes Berg98fc4382015-03-01 09:10:13 +02009211 regular = true;
9212
Johannes Bergff1b6e62011-05-04 15:37:28 +02009213 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9214 rem)
9215 n_patterns++;
9216 if (n_patterns > wowlan->n_patterns)
9217 return -EINVAL;
9218
9219 new_triggers.patterns = kcalloc(n_patterns,
9220 sizeof(new_triggers.patterns[0]),
9221 GFP_KERNEL);
9222 if (!new_triggers.patterns)
9223 return -ENOMEM;
9224
9225 new_triggers.n_patterns = n_patterns;
9226 i = 0;
9227
9228 nla_for_each_nested(pat, tb[NL80211_WOWLAN_TRIG_PKT_PATTERN],
9229 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009230 u8 *mask_pat;
9231
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009232 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9233 nla_len(pat), NULL);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009234 err = -EINVAL;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009235 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9236 !pat_tb[NL80211_PKTPAT_PATTERN])
Johannes Bergff1b6e62011-05-04 15:37:28 +02009237 goto error;
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009238 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009239 mask_len = DIV_ROUND_UP(pat_len, 8);
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009240 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
Johannes Bergff1b6e62011-05-04 15:37:28 +02009241 goto error;
9242 if (pat_len > wowlan->pattern_max_len ||
9243 pat_len < wowlan->pattern_min_len)
9244 goto error;
9245
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009246 if (!pat_tb[NL80211_PKTPAT_OFFSET])
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009247 pkt_offset = 0;
9248 else
9249 pkt_offset = nla_get_u32(
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009250 pat_tb[NL80211_PKTPAT_OFFSET]);
Amitkumar Karwarbb92d192013-02-12 12:16:26 -08009251 if (pkt_offset > wowlan->max_pkt_offset)
9252 goto error;
9253 new_triggers.patterns[i].pkt_offset = pkt_offset;
9254
Johannes Berg922bd802014-05-19 17:59:50 +02009255 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9256 if (!mask_pat) {
Johannes Bergff1b6e62011-05-04 15:37:28 +02009257 err = -ENOMEM;
9258 goto error;
9259 }
Johannes Berg922bd802014-05-19 17:59:50 +02009260 new_triggers.patterns[i].mask = mask_pat;
9261 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009262 mask_len);
Johannes Berg922bd802014-05-19 17:59:50 +02009263 mask_pat += mask_len;
9264 new_triggers.patterns[i].pattern = mask_pat;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009265 new_triggers.patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009266 memcpy(mask_pat,
Amitkumar Karwar50ac6602013-06-25 19:03:56 -07009267 nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
Johannes Bergff1b6e62011-05-04 15:37:28 +02009268 pat_len);
9269 i++;
9270 }
9271 }
9272
Johannes Berg2a0e0472013-01-23 22:57:40 +01009273 if (tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009274 regular = true;
Johannes Berg2a0e0472013-01-23 22:57:40 +01009275 err = nl80211_parse_wowlan_tcp(
9276 rdev, tb[NL80211_WOWLAN_TRIG_TCP_CONNECTION],
9277 &new_triggers);
9278 if (err)
9279 goto error;
9280 }
9281
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009282 if (tb[NL80211_WOWLAN_TRIG_NET_DETECT]) {
Johannes Berg98fc4382015-03-01 09:10:13 +02009283 regular = true;
Luciano Coelho8cd4d452014-09-17 11:55:28 +03009284 err = nl80211_parse_wowlan_nd(
9285 rdev, wowlan, tb[NL80211_WOWLAN_TRIG_NET_DETECT],
9286 &new_triggers);
9287 if (err)
9288 goto error;
9289 }
9290
Johannes Berg98fc4382015-03-01 09:10:13 +02009291 /* The 'any' trigger means the device continues operating more or less
9292 * as in its normal operation mode and wakes up the host on most of the
9293 * normal interrupts (like packet RX, ...)
9294 * It therefore makes little sense to combine with the more constrained
9295 * wakeup trigger modes.
9296 */
9297 if (new_triggers.any && regular) {
9298 err = -EINVAL;
9299 goto error;
9300 }
9301
Johannes Bergae33bd82012-07-12 16:25:02 +02009302 ntrig = kmemdup(&new_triggers, sizeof(new_triggers), GFP_KERNEL);
9303 if (!ntrig) {
9304 err = -ENOMEM;
9305 goto error;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009306 }
Johannes Bergae33bd82012-07-12 16:25:02 +02009307 cfg80211_rdev_free_wowlan(rdev);
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009308 rdev->wiphy.wowlan_config = ntrig;
Johannes Bergff1b6e62011-05-04 15:37:28 +02009309
Johannes Bergae33bd82012-07-12 16:25:02 +02009310 set_wakeup:
Johannes Berg6abb9cb2013-05-15 09:30:07 +02009311 if (rdev->ops->set_wakeup &&
9312 prev_enabled != !!rdev->wiphy.wowlan_config)
9313 rdev_set_wakeup(rdev, rdev->wiphy.wowlan_config);
Johannes Berg6d525632012-04-04 15:05:25 +02009314
Johannes Bergff1b6e62011-05-04 15:37:28 +02009315 return 0;
9316 error:
9317 for (i = 0; i < new_triggers.n_patterns; i++)
9318 kfree(new_triggers.patterns[i].mask);
9319 kfree(new_triggers.patterns);
Johannes Berg2a0e0472013-01-23 22:57:40 +01009320 if (new_triggers.tcp && new_triggers.tcp->sock)
9321 sock_release(new_triggers.tcp->sock);
9322 kfree(new_triggers.tcp);
Johannes Bergff1b6e62011-05-04 15:37:28 +02009323 return err;
9324}
Johannes Bergdfb89c52012-06-27 09:23:48 +02009325#endif
Johannes Bergff1b6e62011-05-04 15:37:28 +02009326
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009327static int nl80211_send_coalesce_rules(struct sk_buff *msg,
9328 struct cfg80211_registered_device *rdev)
9329{
9330 struct nlattr *nl_pats, *nl_pat, *nl_rule, *nl_rules;
9331 int i, j, pat_len;
9332 struct cfg80211_coalesce_rules *rule;
9333
9334 if (!rdev->coalesce->n_rules)
9335 return 0;
9336
9337 nl_rules = nla_nest_start(msg, NL80211_ATTR_COALESCE_RULE);
9338 if (!nl_rules)
9339 return -ENOBUFS;
9340
9341 for (i = 0; i < rdev->coalesce->n_rules; i++) {
9342 nl_rule = nla_nest_start(msg, i + 1);
9343 if (!nl_rule)
9344 return -ENOBUFS;
9345
9346 rule = &rdev->coalesce->rules[i];
9347 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_DELAY,
9348 rule->delay))
9349 return -ENOBUFS;
9350
9351 if (nla_put_u32(msg, NL80211_ATTR_COALESCE_RULE_CONDITION,
9352 rule->condition))
9353 return -ENOBUFS;
9354
9355 nl_pats = nla_nest_start(msg,
9356 NL80211_ATTR_COALESCE_RULE_PKT_PATTERN);
9357 if (!nl_pats)
9358 return -ENOBUFS;
9359
9360 for (j = 0; j < rule->n_patterns; j++) {
9361 nl_pat = nla_nest_start(msg, j + 1);
9362 if (!nl_pat)
9363 return -ENOBUFS;
9364 pat_len = rule->patterns[j].pattern_len;
9365 if (nla_put(msg, NL80211_PKTPAT_MASK,
9366 DIV_ROUND_UP(pat_len, 8),
9367 rule->patterns[j].mask) ||
9368 nla_put(msg, NL80211_PKTPAT_PATTERN, pat_len,
9369 rule->patterns[j].pattern) ||
9370 nla_put_u32(msg, NL80211_PKTPAT_OFFSET,
9371 rule->patterns[j].pkt_offset))
9372 return -ENOBUFS;
9373 nla_nest_end(msg, nl_pat);
9374 }
9375 nla_nest_end(msg, nl_pats);
9376 nla_nest_end(msg, nl_rule);
9377 }
9378 nla_nest_end(msg, nl_rules);
9379
9380 return 0;
9381}
9382
9383static int nl80211_get_coalesce(struct sk_buff *skb, struct genl_info *info)
9384{
9385 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9386 struct sk_buff *msg;
9387 void *hdr;
9388
9389 if (!rdev->wiphy.coalesce)
9390 return -EOPNOTSUPP;
9391
9392 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9393 if (!msg)
9394 return -ENOMEM;
9395
9396 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9397 NL80211_CMD_GET_COALESCE);
9398 if (!hdr)
9399 goto nla_put_failure;
9400
9401 if (rdev->coalesce && nl80211_send_coalesce_rules(msg, rdev))
9402 goto nla_put_failure;
9403
9404 genlmsg_end(msg, hdr);
9405 return genlmsg_reply(msg, info);
9406
9407nla_put_failure:
9408 nlmsg_free(msg);
9409 return -ENOBUFS;
9410}
9411
9412void cfg80211_rdev_free_coalesce(struct cfg80211_registered_device *rdev)
9413{
9414 struct cfg80211_coalesce *coalesce = rdev->coalesce;
9415 int i, j;
9416 struct cfg80211_coalesce_rules *rule;
9417
9418 if (!coalesce)
9419 return;
9420
9421 for (i = 0; i < coalesce->n_rules; i++) {
9422 rule = &coalesce->rules[i];
9423 for (j = 0; j < rule->n_patterns; j++)
9424 kfree(rule->patterns[j].mask);
9425 kfree(rule->patterns);
9426 }
9427 kfree(coalesce->rules);
9428 kfree(coalesce);
9429 rdev->coalesce = NULL;
9430}
9431
9432static int nl80211_parse_coalesce_rule(struct cfg80211_registered_device *rdev,
9433 struct nlattr *rule,
9434 struct cfg80211_coalesce_rules *new_rule)
9435{
9436 int err, i;
9437 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9438 struct nlattr *tb[NUM_NL80211_ATTR_COALESCE_RULE], *pat;
9439 int rem, pat_len, mask_len, pkt_offset, n_patterns = 0;
9440 struct nlattr *pat_tb[NUM_NL80211_PKTPAT];
9441
9442 err = nla_parse(tb, NL80211_ATTR_COALESCE_RULE_MAX, nla_data(rule),
9443 nla_len(rule), nl80211_coalesce_policy);
9444 if (err)
9445 return err;
9446
9447 if (tb[NL80211_ATTR_COALESCE_RULE_DELAY])
9448 new_rule->delay =
9449 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_DELAY]);
9450 if (new_rule->delay > coalesce->max_delay)
9451 return -EINVAL;
9452
9453 if (tb[NL80211_ATTR_COALESCE_RULE_CONDITION])
9454 new_rule->condition =
9455 nla_get_u32(tb[NL80211_ATTR_COALESCE_RULE_CONDITION]);
9456 if (new_rule->condition != NL80211_COALESCE_CONDITION_MATCH &&
9457 new_rule->condition != NL80211_COALESCE_CONDITION_NO_MATCH)
9458 return -EINVAL;
9459
9460 if (!tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN])
9461 return -EINVAL;
9462
9463 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9464 rem)
9465 n_patterns++;
9466 if (n_patterns > coalesce->n_patterns)
9467 return -EINVAL;
9468
9469 new_rule->patterns = kcalloc(n_patterns, sizeof(new_rule->patterns[0]),
9470 GFP_KERNEL);
9471 if (!new_rule->patterns)
9472 return -ENOMEM;
9473
9474 new_rule->n_patterns = n_patterns;
9475 i = 0;
9476
9477 nla_for_each_nested(pat, tb[NL80211_ATTR_COALESCE_RULE_PKT_PATTERN],
9478 rem) {
Johannes Berg922bd802014-05-19 17:59:50 +02009479 u8 *mask_pat;
9480
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009481 nla_parse(pat_tb, MAX_NL80211_PKTPAT, nla_data(pat),
9482 nla_len(pat), NULL);
9483 if (!pat_tb[NL80211_PKTPAT_MASK] ||
9484 !pat_tb[NL80211_PKTPAT_PATTERN])
9485 return -EINVAL;
9486 pat_len = nla_len(pat_tb[NL80211_PKTPAT_PATTERN]);
9487 mask_len = DIV_ROUND_UP(pat_len, 8);
9488 if (nla_len(pat_tb[NL80211_PKTPAT_MASK]) != mask_len)
9489 return -EINVAL;
9490 if (pat_len > coalesce->pattern_max_len ||
9491 pat_len < coalesce->pattern_min_len)
9492 return -EINVAL;
9493
9494 if (!pat_tb[NL80211_PKTPAT_OFFSET])
9495 pkt_offset = 0;
9496 else
9497 pkt_offset = nla_get_u32(pat_tb[NL80211_PKTPAT_OFFSET]);
9498 if (pkt_offset > coalesce->max_pkt_offset)
9499 return -EINVAL;
9500 new_rule->patterns[i].pkt_offset = pkt_offset;
9501
Johannes Berg922bd802014-05-19 17:59:50 +02009502 mask_pat = kmalloc(mask_len + pat_len, GFP_KERNEL);
9503 if (!mask_pat)
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009504 return -ENOMEM;
Johannes Berg922bd802014-05-19 17:59:50 +02009505
9506 new_rule->patterns[i].mask = mask_pat;
9507 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_MASK]),
9508 mask_len);
9509
9510 mask_pat += mask_len;
9511 new_rule->patterns[i].pattern = mask_pat;
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009512 new_rule->patterns[i].pattern_len = pat_len;
Johannes Berg922bd802014-05-19 17:59:50 +02009513 memcpy(mask_pat, nla_data(pat_tb[NL80211_PKTPAT_PATTERN]),
9514 pat_len);
Amitkumar Karwarbe29b992013-06-28 11:51:26 -07009515 i++;
9516 }
9517
9518 return 0;
9519}
9520
9521static int nl80211_set_coalesce(struct sk_buff *skb, struct genl_info *info)
9522{
9523 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9524 const struct wiphy_coalesce_support *coalesce = rdev->wiphy.coalesce;
9525 struct cfg80211_coalesce new_coalesce = {};
9526 struct cfg80211_coalesce *n_coalesce;
9527 int err, rem_rule, n_rules = 0, i, j;
9528 struct nlattr *rule;
9529 struct cfg80211_coalesce_rules *tmp_rule;
9530
9531 if (!rdev->wiphy.coalesce || !rdev->ops->set_coalesce)
9532 return -EOPNOTSUPP;
9533
9534 if (!info->attrs[NL80211_ATTR_COALESCE_RULE]) {
9535 cfg80211_rdev_free_coalesce(rdev);
9536 rdev->ops->set_coalesce(&rdev->wiphy, NULL);
9537 return 0;
9538 }
9539
9540 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9541 rem_rule)
9542 n_rules++;
9543 if (n_rules > coalesce->n_rules)
9544 return -EINVAL;
9545
9546 new_coalesce.rules = kcalloc(n_rules, sizeof(new_coalesce.rules[0]),
9547 GFP_KERNEL);
9548 if (!new_coalesce.rules)
9549 return -ENOMEM;
9550
9551 new_coalesce.n_rules = n_rules;
9552 i = 0;
9553
9554 nla_for_each_nested(rule, info->attrs[NL80211_ATTR_COALESCE_RULE],
9555 rem_rule) {
9556 err = nl80211_parse_coalesce_rule(rdev, rule,
9557 &new_coalesce.rules[i]);
9558 if (err)
9559 goto error;
9560
9561 i++;
9562 }
9563
9564 err = rdev->ops->set_coalesce(&rdev->wiphy, &new_coalesce);
9565 if (err)
9566 goto error;
9567
9568 n_coalesce = kmemdup(&new_coalesce, sizeof(new_coalesce), GFP_KERNEL);
9569 if (!n_coalesce) {
9570 err = -ENOMEM;
9571 goto error;
9572 }
9573 cfg80211_rdev_free_coalesce(rdev);
9574 rdev->coalesce = n_coalesce;
9575
9576 return 0;
9577error:
9578 for (i = 0; i < new_coalesce.n_rules; i++) {
9579 tmp_rule = &new_coalesce.rules[i];
9580 for (j = 0; j < tmp_rule->n_patterns; j++)
9581 kfree(tmp_rule->patterns[j].mask);
9582 kfree(tmp_rule->patterns);
9583 }
9584 kfree(new_coalesce.rules);
9585
9586 return err;
9587}
9588
Johannes Berge5497d72011-07-05 16:35:40 +02009589static int nl80211_set_rekey_data(struct sk_buff *skb, struct genl_info *info)
9590{
9591 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9592 struct net_device *dev = info->user_ptr[1];
9593 struct wireless_dev *wdev = dev->ieee80211_ptr;
9594 struct nlattr *tb[NUM_NL80211_REKEY_DATA];
9595 struct cfg80211_gtk_rekey_data rekey_data;
9596 int err;
9597
9598 if (!info->attrs[NL80211_ATTR_REKEY_DATA])
9599 return -EINVAL;
9600
9601 err = nla_parse(tb, MAX_NL80211_REKEY_DATA,
9602 nla_data(info->attrs[NL80211_ATTR_REKEY_DATA]),
9603 nla_len(info->attrs[NL80211_ATTR_REKEY_DATA]),
9604 nl80211_rekey_policy);
9605 if (err)
9606 return err;
9607
9608 if (nla_len(tb[NL80211_REKEY_DATA_REPLAY_CTR]) != NL80211_REPLAY_CTR_LEN)
9609 return -ERANGE;
9610 if (nla_len(tb[NL80211_REKEY_DATA_KEK]) != NL80211_KEK_LEN)
9611 return -ERANGE;
9612 if (nla_len(tb[NL80211_REKEY_DATA_KCK]) != NL80211_KCK_LEN)
9613 return -ERANGE;
9614
Johannes Berg78f686c2014-09-10 22:28:06 +03009615 rekey_data.kek = nla_data(tb[NL80211_REKEY_DATA_KEK]);
9616 rekey_data.kck = nla_data(tb[NL80211_REKEY_DATA_KCK]);
9617 rekey_data.replay_ctr = nla_data(tb[NL80211_REKEY_DATA_REPLAY_CTR]);
Johannes Berge5497d72011-07-05 16:35:40 +02009618
9619 wdev_lock(wdev);
9620 if (!wdev->current_bss) {
9621 err = -ENOTCONN;
9622 goto out;
9623 }
9624
9625 if (!rdev->ops->set_rekey_data) {
9626 err = -EOPNOTSUPP;
9627 goto out;
9628 }
9629
Hila Gonene35e4d22012-06-27 17:19:42 +03009630 err = rdev_set_rekey_data(rdev, dev, &rekey_data);
Johannes Berge5497d72011-07-05 16:35:40 +02009631 out:
9632 wdev_unlock(wdev);
9633 return err;
9634}
9635
Johannes Berg28946da2011-11-04 11:18:12 +01009636static int nl80211_register_unexpected_frame(struct sk_buff *skb,
9637 struct genl_info *info)
9638{
9639 struct net_device *dev = info->user_ptr[1];
9640 struct wireless_dev *wdev = dev->ieee80211_ptr;
9641
9642 if (wdev->iftype != NL80211_IFTYPE_AP &&
9643 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9644 return -EINVAL;
9645
Eric W. Biederman15e47302012-09-07 20:12:54 +00009646 if (wdev->ap_unexpected_nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +01009647 return -EBUSY;
9648
Eric W. Biederman15e47302012-09-07 20:12:54 +00009649 wdev->ap_unexpected_nlportid = info->snd_portid;
Johannes Berg28946da2011-11-04 11:18:12 +01009650 return 0;
9651}
9652
Johannes Berg7f6cf312011-11-04 11:18:15 +01009653static int nl80211_probe_client(struct sk_buff *skb,
9654 struct genl_info *info)
9655{
9656 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9657 struct net_device *dev = info->user_ptr[1];
9658 struct wireless_dev *wdev = dev->ieee80211_ptr;
9659 struct sk_buff *msg;
9660 void *hdr;
9661 const u8 *addr;
9662 u64 cookie;
9663 int err;
9664
9665 if (wdev->iftype != NL80211_IFTYPE_AP &&
9666 wdev->iftype != NL80211_IFTYPE_P2P_GO)
9667 return -EOPNOTSUPP;
9668
9669 if (!info->attrs[NL80211_ATTR_MAC])
9670 return -EINVAL;
9671
9672 if (!rdev->ops->probe_client)
9673 return -EOPNOTSUPP;
9674
9675 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9676 if (!msg)
9677 return -ENOMEM;
9678
Eric W. Biederman15e47302012-09-07 20:12:54 +00009679 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
Johannes Berg7f6cf312011-11-04 11:18:15 +01009680 NL80211_CMD_PROBE_CLIENT);
Dan Carpentercb35fba2013-08-14 14:50:01 +03009681 if (!hdr) {
9682 err = -ENOBUFS;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009683 goto free_msg;
9684 }
9685
9686 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
9687
Hila Gonene35e4d22012-06-27 17:19:42 +03009688 err = rdev_probe_client(rdev, dev, addr, &cookie);
Johannes Berg7f6cf312011-11-04 11:18:15 +01009689 if (err)
9690 goto free_msg;
9691
David S. Miller9360ffd2012-03-29 04:41:26 -04009692 if (nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
9693 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +01009694
9695 genlmsg_end(msg, hdr);
9696
9697 return genlmsg_reply(msg, info);
9698
9699 nla_put_failure:
9700 err = -ENOBUFS;
9701 free_msg:
9702 nlmsg_free(msg);
9703 return err;
9704}
9705
Johannes Berg5e760232011-11-04 11:18:17 +01009706static int nl80211_register_beacons(struct sk_buff *skb, struct genl_info *info)
9707{
9708 struct cfg80211_registered_device *rdev = info->user_ptr[0];
Ben Greear37c73b52012-10-26 14:49:25 -07009709 struct cfg80211_beacon_registration *reg, *nreg;
9710 int rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009711
9712 if (!(rdev->wiphy.flags & WIPHY_FLAG_REPORTS_OBSS))
9713 return -EOPNOTSUPP;
9714
Ben Greear37c73b52012-10-26 14:49:25 -07009715 nreg = kzalloc(sizeof(*nreg), GFP_KERNEL);
9716 if (!nreg)
9717 return -ENOMEM;
Johannes Berg5e760232011-11-04 11:18:17 +01009718
Ben Greear37c73b52012-10-26 14:49:25 -07009719 /* First, check if already registered. */
9720 spin_lock_bh(&rdev->beacon_registrations_lock);
9721 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
9722 if (reg->nlportid == info->snd_portid) {
9723 rv = -EALREADY;
9724 goto out_err;
9725 }
9726 }
9727 /* Add it to the list */
9728 nreg->nlportid = info->snd_portid;
9729 list_add(&nreg->list, &rdev->beacon_registrations);
9730
9731 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +01009732
9733 return 0;
Ben Greear37c73b52012-10-26 14:49:25 -07009734out_err:
9735 spin_unlock_bh(&rdev->beacon_registrations_lock);
9736 kfree(nreg);
9737 return rv;
Johannes Berg5e760232011-11-04 11:18:17 +01009738}
9739
Johannes Berg98104fde2012-06-16 00:19:54 +02009740static int nl80211_start_p2p_device(struct sk_buff *skb, struct genl_info *info)
9741{
9742 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9743 struct wireless_dev *wdev = info->user_ptr[1];
9744 int err;
9745
9746 if (!rdev->ops->start_p2p_device)
9747 return -EOPNOTSUPP;
9748
9749 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9750 return -EOPNOTSUPP;
9751
9752 if (wdev->p2p_started)
9753 return 0;
9754
Luciano Coelhob6a55012014-02-27 11:07:21 +02009755 if (rfkill_blocked(rdev->rfkill))
9756 return -ERFKILL;
Johannes Berg98104fde2012-06-16 00:19:54 +02009757
Johannes Bergeeb126e2012-10-23 15:16:50 +02009758 err = rdev_start_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009759 if (err)
9760 return err;
9761
9762 wdev->p2p_started = true;
Johannes Berg98104fde2012-06-16 00:19:54 +02009763 rdev->opencount++;
Johannes Berg98104fde2012-06-16 00:19:54 +02009764
9765 return 0;
9766}
9767
9768static int nl80211_stop_p2p_device(struct sk_buff *skb, struct genl_info *info)
9769{
9770 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9771 struct wireless_dev *wdev = info->user_ptr[1];
9772
9773 if (wdev->iftype != NL80211_IFTYPE_P2P_DEVICE)
9774 return -EOPNOTSUPP;
9775
9776 if (!rdev->ops->stop_p2p_device)
9777 return -EOPNOTSUPP;
9778
Johannes Bergf9f47522013-03-19 15:04:07 +01009779 cfg80211_stop_p2p_device(rdev, wdev);
Johannes Berg98104fde2012-06-16 00:19:54 +02009780
9781 return 0;
9782}
9783
Johannes Berg3713b4e2013-02-14 16:19:38 +01009784static int nl80211_get_protocol_features(struct sk_buff *skb,
9785 struct genl_info *info)
9786{
9787 void *hdr;
9788 struct sk_buff *msg;
9789
9790 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
9791 if (!msg)
9792 return -ENOMEM;
9793
9794 hdr = nl80211hdr_put(msg, info->snd_portid, info->snd_seq, 0,
9795 NL80211_CMD_GET_PROTOCOL_FEATURES);
9796 if (!hdr)
9797 goto nla_put_failure;
9798
9799 if (nla_put_u32(msg, NL80211_ATTR_PROTOCOL_FEATURES,
9800 NL80211_PROTOCOL_FEATURE_SPLIT_WIPHY_DUMP))
9801 goto nla_put_failure;
9802
9803 genlmsg_end(msg, hdr);
9804 return genlmsg_reply(msg, info);
9805
9806 nla_put_failure:
9807 kfree_skb(msg);
9808 return -ENOBUFS;
9809}
9810
Jouni Malinen355199e2013-02-27 17:14:27 +02009811static int nl80211_update_ft_ies(struct sk_buff *skb, struct genl_info *info)
9812{
9813 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9814 struct cfg80211_update_ft_ies_params ft_params;
9815 struct net_device *dev = info->user_ptr[1];
9816
9817 if (!rdev->ops->update_ft_ies)
9818 return -EOPNOTSUPP;
9819
9820 if (!info->attrs[NL80211_ATTR_MDID] ||
9821 !is_valid_ie_attr(info->attrs[NL80211_ATTR_IE]))
9822 return -EINVAL;
9823
9824 memset(&ft_params, 0, sizeof(ft_params));
9825 ft_params.md = nla_get_u16(info->attrs[NL80211_ATTR_MDID]);
9826 ft_params.ie = nla_data(info->attrs[NL80211_ATTR_IE]);
9827 ft_params.ie_len = nla_len(info->attrs[NL80211_ATTR_IE]);
9828
9829 return rdev_update_ft_ies(rdev, dev, &ft_params);
9830}
9831
Arend van Spriel5de17982013-04-18 15:49:00 +02009832static int nl80211_crit_protocol_start(struct sk_buff *skb,
9833 struct genl_info *info)
9834{
9835 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9836 struct wireless_dev *wdev = info->user_ptr[1];
9837 enum nl80211_crit_proto_id proto = NL80211_CRIT_PROTO_UNSPEC;
9838 u16 duration;
9839 int ret;
9840
9841 if (!rdev->ops->crit_proto_start)
9842 return -EOPNOTSUPP;
9843
9844 if (WARN_ON(!rdev->ops->crit_proto_stop))
9845 return -EINVAL;
9846
9847 if (rdev->crit_proto_nlportid)
9848 return -EBUSY;
9849
9850 /* determine protocol if provided */
9851 if (info->attrs[NL80211_ATTR_CRIT_PROT_ID])
9852 proto = nla_get_u16(info->attrs[NL80211_ATTR_CRIT_PROT_ID]);
9853
9854 if (proto >= NUM_NL80211_CRIT_PROTO)
9855 return -EINVAL;
9856
9857 /* timeout must be provided */
9858 if (!info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION])
9859 return -EINVAL;
9860
9861 duration =
9862 nla_get_u16(info->attrs[NL80211_ATTR_MAX_CRIT_PROT_DURATION]);
9863
9864 if (duration > NL80211_CRIT_PROTO_MAX_DURATION)
9865 return -ERANGE;
9866
9867 ret = rdev_crit_proto_start(rdev, wdev, proto, duration);
9868 if (!ret)
9869 rdev->crit_proto_nlportid = info->snd_portid;
9870
9871 return ret;
9872}
9873
9874static int nl80211_crit_protocol_stop(struct sk_buff *skb,
9875 struct genl_info *info)
9876{
9877 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9878 struct wireless_dev *wdev = info->user_ptr[1];
9879
9880 if (!rdev->ops->crit_proto_stop)
9881 return -EOPNOTSUPP;
9882
9883 if (rdev->crit_proto_nlportid) {
9884 rdev->crit_proto_nlportid = 0;
9885 rdev_crit_proto_stop(rdev, wdev);
9886 }
9887 return 0;
9888}
9889
Johannes Bergad7e7182013-11-13 13:37:47 +01009890static int nl80211_vendor_cmd(struct sk_buff *skb, struct genl_info *info)
9891{
9892 struct cfg80211_registered_device *rdev = info->user_ptr[0];
9893 struct wireless_dev *wdev =
9894 __cfg80211_wdev_from_attrs(genl_info_net(info), info->attrs);
9895 int i, err;
9896 u32 vid, subcmd;
9897
9898 if (!rdev->wiphy.vendor_commands)
9899 return -EOPNOTSUPP;
9900
9901 if (IS_ERR(wdev)) {
9902 err = PTR_ERR(wdev);
9903 if (err != -EINVAL)
9904 return err;
9905 wdev = NULL;
9906 } else if (wdev->wiphy != &rdev->wiphy) {
9907 return -EINVAL;
9908 }
9909
9910 if (!info->attrs[NL80211_ATTR_VENDOR_ID] ||
9911 !info->attrs[NL80211_ATTR_VENDOR_SUBCMD])
9912 return -EINVAL;
9913
9914 vid = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_ID]);
9915 subcmd = nla_get_u32(info->attrs[NL80211_ATTR_VENDOR_SUBCMD]);
9916 for (i = 0; i < rdev->wiphy.n_vendor_commands; i++) {
9917 const struct wiphy_vendor_command *vcmd;
9918 void *data = NULL;
9919 int len = 0;
9920
9921 vcmd = &rdev->wiphy.vendor_commands[i];
9922
9923 if (vcmd->info.vendor_id != vid || vcmd->info.subcmd != subcmd)
9924 continue;
9925
9926 if (vcmd->flags & (WIPHY_VENDOR_CMD_NEED_WDEV |
9927 WIPHY_VENDOR_CMD_NEED_NETDEV)) {
9928 if (!wdev)
9929 return -EINVAL;
9930 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_NETDEV &&
9931 !wdev->netdev)
9932 return -EINVAL;
9933
9934 if (vcmd->flags & WIPHY_VENDOR_CMD_NEED_RUNNING) {
9935 if (wdev->netdev &&
9936 !netif_running(wdev->netdev))
9937 return -ENETDOWN;
9938 if (!wdev->netdev && !wdev->p2p_started)
9939 return -ENETDOWN;
9940 }
9941 } else {
9942 wdev = NULL;
9943 }
9944
9945 if (info->attrs[NL80211_ATTR_VENDOR_DATA]) {
9946 data = nla_data(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9947 len = nla_len(info->attrs[NL80211_ATTR_VENDOR_DATA]);
9948 }
9949
9950 rdev->cur_cmd_info = info;
9951 err = rdev->wiphy.vendor_commands[i].doit(&rdev->wiphy, wdev,
9952 data, len);
9953 rdev->cur_cmd_info = NULL;
9954 return err;
9955 }
9956
9957 return -EOPNOTSUPP;
9958}
9959
9960struct sk_buff *__cfg80211_alloc_reply_skb(struct wiphy *wiphy,
9961 enum nl80211_commands cmd,
9962 enum nl80211_attrs attr,
9963 int approxlen)
9964{
Zhao, Gangf26cbf42014-04-21 12:53:03 +08009965 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Bergad7e7182013-11-13 13:37:47 +01009966
9967 if (WARN_ON(!rdev->cur_cmd_info))
9968 return NULL;
9969
Ahmad Kholaif6c09e792015-02-26 15:26:53 +02009970 return __cfg80211_alloc_vendor_skb(rdev, NULL, approxlen,
Johannes Bergad7e7182013-11-13 13:37:47 +01009971 rdev->cur_cmd_info->snd_portid,
9972 rdev->cur_cmd_info->snd_seq,
Johannes Berg567ffc32013-12-18 14:43:31 +01009973 cmd, attr, NULL, GFP_KERNEL);
Johannes Bergad7e7182013-11-13 13:37:47 +01009974}
9975EXPORT_SYMBOL(__cfg80211_alloc_reply_skb);
9976
9977int cfg80211_vendor_cmd_reply(struct sk_buff *skb)
9978{
9979 struct cfg80211_registered_device *rdev = ((void **)skb->cb)[0];
9980 void *hdr = ((void **)skb->cb)[1];
9981 struct nlattr *data = ((void **)skb->cb)[2];
9982
Johannes Bergbd8c78e2014-07-30 14:55:26 +02009983 /* clear CB data for netlink core to own from now on */
9984 memset(skb->cb, 0, sizeof(skb->cb));
9985
Johannes Bergad7e7182013-11-13 13:37:47 +01009986 if (WARN_ON(!rdev->cur_cmd_info)) {
9987 kfree_skb(skb);
9988 return -EINVAL;
9989 }
9990
9991 nla_nest_end(skb, data);
9992 genlmsg_end(skb, hdr);
9993 return genlmsg_reply(skb, rdev->cur_cmd_info);
9994}
9995EXPORT_SYMBOL_GPL(cfg80211_vendor_cmd_reply);
9996
9997
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -08009998static int nl80211_set_qos_map(struct sk_buff *skb,
9999 struct genl_info *info)
10000{
10001 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10002 struct cfg80211_qos_map *qos_map = NULL;
10003 struct net_device *dev = info->user_ptr[1];
10004 u8 *pos, len, num_des, des_len, des;
10005 int ret;
10006
10007 if (!rdev->ops->set_qos_map)
10008 return -EOPNOTSUPP;
10009
10010 if (info->attrs[NL80211_ATTR_QOS_MAP]) {
10011 pos = nla_data(info->attrs[NL80211_ATTR_QOS_MAP]);
10012 len = nla_len(info->attrs[NL80211_ATTR_QOS_MAP]);
10013
10014 if (len % 2 || len < IEEE80211_QOS_MAP_LEN_MIN ||
10015 len > IEEE80211_QOS_MAP_LEN_MAX)
10016 return -EINVAL;
10017
10018 qos_map = kzalloc(sizeof(struct cfg80211_qos_map), GFP_KERNEL);
10019 if (!qos_map)
10020 return -ENOMEM;
10021
10022 num_des = (len - IEEE80211_QOS_MAP_LEN_MIN) >> 1;
10023 if (num_des) {
10024 des_len = num_des *
10025 sizeof(struct cfg80211_dscp_exception);
10026 memcpy(qos_map->dscp_exception, pos, des_len);
10027 qos_map->num_des = num_des;
10028 for (des = 0; des < num_des; des++) {
10029 if (qos_map->dscp_exception[des].up > 7) {
10030 kfree(qos_map);
10031 return -EINVAL;
10032 }
10033 }
10034 pos += des_len;
10035 }
10036 memcpy(qos_map->up, pos, IEEE80211_QOS_MAP_LEN_MIN);
10037 }
10038
10039 wdev_lock(dev->ieee80211_ptr);
10040 ret = nl80211_key_allowed(dev->ieee80211_ptr);
10041 if (!ret)
10042 ret = rdev_set_qos_map(rdev, dev, qos_map);
10043 wdev_unlock(dev->ieee80211_ptr);
10044
10045 kfree(qos_map);
10046 return ret;
10047}
10048
Johannes Berg960d01a2014-09-09 22:55:35 +030010049static int nl80211_add_tx_ts(struct sk_buff *skb, struct genl_info *info)
10050{
10051 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10052 struct net_device *dev = info->user_ptr[1];
10053 struct wireless_dev *wdev = dev->ieee80211_ptr;
10054 const u8 *peer;
10055 u8 tsid, up;
10056 u16 admitted_time = 0;
10057 int err;
10058
Johannes Berg723e73a2014-10-22 09:25:06 +020010059 if (!(rdev->wiphy.features & NL80211_FEATURE_SUPPORTS_WMM_ADMISSION))
Johannes Berg960d01a2014-09-09 22:55:35 +030010060 return -EOPNOTSUPP;
10061
10062 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC] ||
10063 !info->attrs[NL80211_ATTR_USER_PRIO])
10064 return -EINVAL;
10065
10066 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10067 if (tsid >= IEEE80211_NUM_TIDS)
10068 return -EINVAL;
10069
10070 up = nla_get_u8(info->attrs[NL80211_ATTR_USER_PRIO]);
10071 if (up >= IEEE80211_NUM_UPS)
10072 return -EINVAL;
10073
10074 /* WMM uses TIDs 0-7 even for TSPEC */
Johannes Berg723e73a2014-10-22 09:25:06 +020010075 if (tsid >= IEEE80211_FIRST_TSPEC_TSID) {
Johannes Berg960d01a2014-09-09 22:55:35 +030010076 /* TODO: handle 802.11 TSPEC/admission control
Johannes Berg723e73a2014-10-22 09:25:06 +020010077 * need more attributes for that (e.g. BA session requirement);
10078 * change the WMM adminssion test above to allow both then
Johannes Berg960d01a2014-09-09 22:55:35 +030010079 */
10080 return -EINVAL;
10081 }
10082
10083 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10084
10085 if (info->attrs[NL80211_ATTR_ADMITTED_TIME]) {
10086 admitted_time =
10087 nla_get_u16(info->attrs[NL80211_ATTR_ADMITTED_TIME]);
10088 if (!admitted_time)
10089 return -EINVAL;
10090 }
10091
10092 wdev_lock(wdev);
10093 switch (wdev->iftype) {
10094 case NL80211_IFTYPE_STATION:
10095 case NL80211_IFTYPE_P2P_CLIENT:
10096 if (wdev->current_bss)
10097 break;
10098 err = -ENOTCONN;
10099 goto out;
10100 default:
10101 err = -EOPNOTSUPP;
10102 goto out;
10103 }
10104
10105 err = rdev_add_tx_ts(rdev, dev, tsid, peer, up, admitted_time);
10106
10107 out:
10108 wdev_unlock(wdev);
10109 return err;
10110}
10111
10112static int nl80211_del_tx_ts(struct sk_buff *skb, struct genl_info *info)
10113{
10114 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10115 struct net_device *dev = info->user_ptr[1];
10116 struct wireless_dev *wdev = dev->ieee80211_ptr;
10117 const u8 *peer;
10118 u8 tsid;
10119 int err;
10120
10121 if (!info->attrs[NL80211_ATTR_TSID] || !info->attrs[NL80211_ATTR_MAC])
10122 return -EINVAL;
10123
10124 tsid = nla_get_u8(info->attrs[NL80211_ATTR_TSID]);
10125 peer = nla_data(info->attrs[NL80211_ATTR_MAC]);
10126
10127 wdev_lock(wdev);
10128 err = rdev_del_tx_ts(rdev, dev, tsid, peer);
10129 wdev_unlock(wdev);
10130
10131 return err;
10132}
10133
Arik Nemtsov1057d352014-11-19 12:54:26 +020010134static int nl80211_tdls_channel_switch(struct sk_buff *skb,
10135 struct genl_info *info)
10136{
10137 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10138 struct net_device *dev = info->user_ptr[1];
10139 struct wireless_dev *wdev = dev->ieee80211_ptr;
10140 struct cfg80211_chan_def chandef = {};
10141 const u8 *addr;
10142 u8 oper_class;
10143 int err;
10144
10145 if (!rdev->ops->tdls_channel_switch ||
10146 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10147 return -EOPNOTSUPP;
10148
10149 switch (dev->ieee80211_ptr->iftype) {
10150 case NL80211_IFTYPE_STATION:
10151 case NL80211_IFTYPE_P2P_CLIENT:
10152 break;
10153 default:
10154 return -EOPNOTSUPP;
10155 }
10156
10157 if (!info->attrs[NL80211_ATTR_MAC] ||
10158 !info->attrs[NL80211_ATTR_OPER_CLASS])
10159 return -EINVAL;
10160
10161 err = nl80211_parse_chandef(rdev, info, &chandef);
10162 if (err)
10163 return err;
10164
10165 /*
10166 * Don't allow wide channels on the 2.4Ghz band, as per IEEE802.11-2012
10167 * section 10.22.6.2.1. Disallow 5/10Mhz channels as well for now, the
10168 * specification is not defined for them.
10169 */
10170 if (chandef.chan->band == IEEE80211_BAND_2GHZ &&
10171 chandef.width != NL80211_CHAN_WIDTH_20_NOHT &&
10172 chandef.width != NL80211_CHAN_WIDTH_20)
10173 return -EINVAL;
10174
10175 /* we will be active on the TDLS link */
Arik Nemtsov923b3522015-07-08 15:41:44 +030010176 if (!cfg80211_reg_can_beacon_relax(&rdev->wiphy, &chandef,
10177 wdev->iftype))
Arik Nemtsov1057d352014-11-19 12:54:26 +020010178 return -EINVAL;
10179
10180 /* don't allow switching to DFS channels */
10181 if (cfg80211_chandef_dfs_required(wdev->wiphy, &chandef, wdev->iftype))
10182 return -EINVAL;
10183
10184 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10185 oper_class = nla_get_u8(info->attrs[NL80211_ATTR_OPER_CLASS]);
10186
10187 wdev_lock(wdev);
10188 err = rdev_tdls_channel_switch(rdev, dev, addr, oper_class, &chandef);
10189 wdev_unlock(wdev);
10190
10191 return err;
10192}
10193
10194static int nl80211_tdls_cancel_channel_switch(struct sk_buff *skb,
10195 struct genl_info *info)
10196{
10197 struct cfg80211_registered_device *rdev = info->user_ptr[0];
10198 struct net_device *dev = info->user_ptr[1];
10199 struct wireless_dev *wdev = dev->ieee80211_ptr;
10200 const u8 *addr;
10201
10202 if (!rdev->ops->tdls_channel_switch ||
10203 !rdev->ops->tdls_cancel_channel_switch ||
10204 !(rdev->wiphy.features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH))
10205 return -EOPNOTSUPP;
10206
10207 switch (dev->ieee80211_ptr->iftype) {
10208 case NL80211_IFTYPE_STATION:
10209 case NL80211_IFTYPE_P2P_CLIENT:
10210 break;
10211 default:
10212 return -EOPNOTSUPP;
10213 }
10214
10215 if (!info->attrs[NL80211_ATTR_MAC])
10216 return -EINVAL;
10217
10218 addr = nla_data(info->attrs[NL80211_ATTR_MAC]);
10219
10220 wdev_lock(wdev);
10221 rdev_tdls_cancel_channel_switch(rdev, dev, addr);
10222 wdev_unlock(wdev);
10223
10224 return 0;
10225}
10226
Johannes Berg4c476992010-10-04 21:36:35 +020010227#define NL80211_FLAG_NEED_WIPHY 0x01
10228#define NL80211_FLAG_NEED_NETDEV 0x02
10229#define NL80211_FLAG_NEED_RTNL 0x04
Johannes Berg41265712010-10-04 21:14:05 +020010230#define NL80211_FLAG_CHECK_NETDEV_UP 0x08
10231#define NL80211_FLAG_NEED_NETDEV_UP (NL80211_FLAG_NEED_NETDEV |\
10232 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg1bf614e2012-06-15 15:23:36 +020010233#define NL80211_FLAG_NEED_WDEV 0x10
Johannes Berg98104fde2012-06-16 00:19:54 +020010234/* If a netdev is associated, it must be UP, P2P must be started */
Johannes Berg1bf614e2012-06-15 15:23:36 +020010235#define NL80211_FLAG_NEED_WDEV_UP (NL80211_FLAG_NEED_WDEV |\
10236 NL80211_FLAG_CHECK_NETDEV_UP)
Johannes Berg5393b912014-09-10 15:00:16 +030010237#define NL80211_FLAG_CLEAR_SKB 0x20
Johannes Berg4c476992010-10-04 21:36:35 +020010238
Johannes Bergf84f7712013-11-14 17:14:45 +010010239static int nl80211_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010240 struct genl_info *info)
10241{
10242 struct cfg80211_registered_device *rdev;
Johannes Berg89a54e42012-06-15 14:33:17 +020010243 struct wireless_dev *wdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010244 struct net_device *dev;
Johannes Berg4c476992010-10-04 21:36:35 +020010245 bool rtnl = ops->internal_flags & NL80211_FLAG_NEED_RTNL;
10246
10247 if (rtnl)
10248 rtnl_lock();
10249
10250 if (ops->internal_flags & NL80211_FLAG_NEED_WIPHY) {
Johannes Berg4f7eff12012-06-15 14:14:22 +020010251 rdev = cfg80211_get_dev_from_info(genl_info_net(info), info);
Johannes Berg4c476992010-10-04 21:36:35 +020010252 if (IS_ERR(rdev)) {
10253 if (rtnl)
10254 rtnl_unlock();
10255 return PTR_ERR(rdev);
10256 }
10257 info->user_ptr[0] = rdev;
Johannes Berg1bf614e2012-06-15 15:23:36 +020010258 } else if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV ||
10259 ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
Johannes Berg5fe231e2013-05-08 21:45:15 +020010260 ASSERT_RTNL();
10261
Johannes Berg89a54e42012-06-15 14:33:17 +020010262 wdev = __cfg80211_wdev_from_attrs(genl_info_net(info),
10263 info->attrs);
10264 if (IS_ERR(wdev)) {
Johannes Berg4c476992010-10-04 21:36:35 +020010265 if (rtnl)
10266 rtnl_unlock();
Johannes Berg89a54e42012-06-15 14:33:17 +020010267 return PTR_ERR(wdev);
Johannes Berg4c476992010-10-04 21:36:35 +020010268 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010269
Johannes Berg89a54e42012-06-15 14:33:17 +020010270 dev = wdev->netdev;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080010271 rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg89a54e42012-06-15 14:33:17 +020010272
Johannes Berg1bf614e2012-06-15 15:23:36 +020010273 if (ops->internal_flags & NL80211_FLAG_NEED_NETDEV) {
10274 if (!dev) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010275 if (rtnl)
10276 rtnl_unlock();
10277 return -EINVAL;
10278 }
10279
10280 info->user_ptr[1] = dev;
10281 } else {
10282 info->user_ptr[1] = wdev;
Johannes Berg41265712010-10-04 21:14:05 +020010283 }
Johannes Berg89a54e42012-06-15 14:33:17 +020010284
Johannes Berg1bf614e2012-06-15 15:23:36 +020010285 if (dev) {
10286 if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP &&
10287 !netif_running(dev)) {
Johannes Berg1bf614e2012-06-15 15:23:36 +020010288 if (rtnl)
10289 rtnl_unlock();
10290 return -ENETDOWN;
10291 }
10292
10293 dev_hold(dev);
Johannes Berg98104fde2012-06-16 00:19:54 +020010294 } else if (ops->internal_flags & NL80211_FLAG_CHECK_NETDEV_UP) {
10295 if (!wdev->p2p_started) {
Johannes Berg98104fde2012-06-16 00:19:54 +020010296 if (rtnl)
10297 rtnl_unlock();
10298 return -ENETDOWN;
10299 }
Johannes Berg1bf614e2012-06-15 15:23:36 +020010300 }
10301
Johannes Berg4c476992010-10-04 21:36:35 +020010302 info->user_ptr[0] = rdev;
Johannes Berg4c476992010-10-04 21:36:35 +020010303 }
10304
10305 return 0;
10306}
10307
Johannes Bergf84f7712013-11-14 17:14:45 +010010308static void nl80211_post_doit(const struct genl_ops *ops, struct sk_buff *skb,
Johannes Berg4c476992010-10-04 21:36:35 +020010309 struct genl_info *info)
10310{
Johannes Berg1bf614e2012-06-15 15:23:36 +020010311 if (info->user_ptr[1]) {
10312 if (ops->internal_flags & NL80211_FLAG_NEED_WDEV) {
10313 struct wireless_dev *wdev = info->user_ptr[1];
10314
10315 if (wdev->netdev)
10316 dev_put(wdev->netdev);
10317 } else {
10318 dev_put(info->user_ptr[1]);
10319 }
10320 }
Johannes Berg5393b912014-09-10 15:00:16 +030010321
Johannes Berg4c476992010-10-04 21:36:35 +020010322 if (ops->internal_flags & NL80211_FLAG_NEED_RTNL)
10323 rtnl_unlock();
Johannes Berg5393b912014-09-10 15:00:16 +030010324
10325 /* If needed, clear the netlink message payload from the SKB
10326 * as it might contain key data that shouldn't stick around on
10327 * the heap after the SKB is freed. The netlink message header
10328 * is still needed for further processing, so leave it intact.
10329 */
10330 if (ops->internal_flags & NL80211_FLAG_CLEAR_SKB) {
10331 struct nlmsghdr *nlh = nlmsg_hdr(skb);
10332
10333 memset(nlmsg_data(nlh), 0, nlmsg_len(nlh));
10334 }
Johannes Berg4c476992010-10-04 21:36:35 +020010335}
10336
Johannes Berg4534de82013-11-14 17:14:46 +010010337static const struct genl_ops nl80211_ops[] = {
Johannes Berg55682962007-09-20 13:09:35 -040010338 {
10339 .cmd = NL80211_CMD_GET_WIPHY,
10340 .doit = nl80211_get_wiphy,
10341 .dumpit = nl80211_dump_wiphy,
Johannes Berg86e8cf92013-06-19 10:57:22 +020010342 .done = nl80211_dump_wiphy_done,
Johannes Berg55682962007-09-20 13:09:35 -040010343 .policy = nl80211_policy,
10344 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010345 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10346 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010347 },
10348 {
10349 .cmd = NL80211_CMD_SET_WIPHY,
10350 .doit = nl80211_set_wiphy,
10351 .policy = nl80211_policy,
10352 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010353 .internal_flags = NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010354 },
10355 {
10356 .cmd = NL80211_CMD_GET_INTERFACE,
10357 .doit = nl80211_get_interface,
10358 .dumpit = nl80211_dump_interface,
10359 .policy = nl80211_policy,
10360 /* can be retrieved by unprivileged users */
Johannes Berg5fe231e2013-05-08 21:45:15 +020010361 .internal_flags = NL80211_FLAG_NEED_WDEV |
10362 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010363 },
10364 {
10365 .cmd = NL80211_CMD_SET_INTERFACE,
10366 .doit = nl80211_set_interface,
10367 .policy = nl80211_policy,
10368 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010369 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10370 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010371 },
10372 {
10373 .cmd = NL80211_CMD_NEW_INTERFACE,
10374 .doit = nl80211_new_interface,
10375 .policy = nl80211_policy,
10376 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010377 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10378 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010379 },
10380 {
10381 .cmd = NL80211_CMD_DEL_INTERFACE,
10382 .doit = nl80211_del_interface,
10383 .policy = nl80211_policy,
10384 .flags = GENL_ADMIN_PERM,
Johannes Berg84efbb82012-06-16 00:00:26 +020010385 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010386 NL80211_FLAG_NEED_RTNL,
Johannes Berg55682962007-09-20 13:09:35 -040010387 },
Johannes Berg41ade002007-12-19 02:03:29 +010010388 {
10389 .cmd = NL80211_CMD_GET_KEY,
10390 .doit = nl80211_get_key,
10391 .policy = nl80211_policy,
10392 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010393 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010394 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010395 },
10396 {
10397 .cmd = NL80211_CMD_SET_KEY,
10398 .doit = nl80211_set_key,
10399 .policy = nl80211_policy,
10400 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010401 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010402 NL80211_FLAG_NEED_RTNL |
10403 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010404 },
10405 {
10406 .cmd = NL80211_CMD_NEW_KEY,
10407 .doit = nl80211_new_key,
10408 .policy = nl80211_policy,
10409 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010410 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010411 NL80211_FLAG_NEED_RTNL |
10412 NL80211_FLAG_CLEAR_SKB,
Johannes Berg41ade002007-12-19 02:03:29 +010010413 },
10414 {
10415 .cmd = NL80211_CMD_DEL_KEY,
10416 .doit = nl80211_del_key,
10417 .policy = nl80211_policy,
10418 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010419 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010420 NL80211_FLAG_NEED_RTNL,
Johannes Berg41ade002007-12-19 02:03:29 +010010421 },
Johannes Berged1b6cc2007-12-19 02:03:32 +010010422 {
10423 .cmd = NL80211_CMD_SET_BEACON,
10424 .policy = nl80211_policy,
10425 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010426 .doit = nl80211_set_beacon,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010427 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010428 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010429 },
10430 {
Johannes Berg88600202012-02-13 15:17:18 +010010431 .cmd = NL80211_CMD_START_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010432 .policy = nl80211_policy,
10433 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010434 .doit = nl80211_start_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010435 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010436 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010437 },
10438 {
Johannes Berg88600202012-02-13 15:17:18 +010010439 .cmd = NL80211_CMD_STOP_AP,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010440 .policy = nl80211_policy,
10441 .flags = GENL_ADMIN_PERM,
Johannes Berg88600202012-02-13 15:17:18 +010010442 .doit = nl80211_stop_ap,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010443 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010444 NL80211_FLAG_NEED_RTNL,
Johannes Berged1b6cc2007-12-19 02:03:32 +010010445 },
Johannes Berg5727ef12007-12-19 02:03:34 +010010446 {
10447 .cmd = NL80211_CMD_GET_STATION,
10448 .doit = nl80211_get_station,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010449 .dumpit = nl80211_dump_station,
Johannes Berg5727ef12007-12-19 02:03:34 +010010450 .policy = nl80211_policy,
Johannes Berg4c476992010-10-04 21:36:35 +020010451 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10452 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010453 },
10454 {
10455 .cmd = NL80211_CMD_SET_STATION,
10456 .doit = nl80211_set_station,
10457 .policy = nl80211_policy,
10458 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010459 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010460 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010461 },
10462 {
10463 .cmd = NL80211_CMD_NEW_STATION,
10464 .doit = nl80211_new_station,
10465 .policy = nl80211_policy,
10466 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010467 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010468 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010469 },
10470 {
10471 .cmd = NL80211_CMD_DEL_STATION,
10472 .doit = nl80211_del_station,
10473 .policy = nl80211_policy,
10474 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010475 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010476 NL80211_FLAG_NEED_RTNL,
Johannes Berg5727ef12007-12-19 02:03:34 +010010477 },
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010478 {
10479 .cmd = NL80211_CMD_GET_MPATH,
10480 .doit = nl80211_get_mpath,
10481 .dumpit = nl80211_dump_mpath,
10482 .policy = nl80211_policy,
10483 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010484 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010485 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010486 },
10487 {
Henning Rogge66be7d22014-09-12 08:58:49 +020010488 .cmd = NL80211_CMD_GET_MPP,
10489 .doit = nl80211_get_mpp,
10490 .dumpit = nl80211_dump_mpp,
10491 .policy = nl80211_policy,
10492 .flags = GENL_ADMIN_PERM,
10493 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10494 NL80211_FLAG_NEED_RTNL,
10495 },
10496 {
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010497 .cmd = NL80211_CMD_SET_MPATH,
10498 .doit = nl80211_set_mpath,
10499 .policy = nl80211_policy,
10500 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010501 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010502 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010503 },
10504 {
10505 .cmd = NL80211_CMD_NEW_MPATH,
10506 .doit = nl80211_new_mpath,
10507 .policy = nl80211_policy,
10508 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010509 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010510 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010511 },
10512 {
10513 .cmd = NL80211_CMD_DEL_MPATH,
10514 .doit = nl80211_del_mpath,
10515 .policy = nl80211_policy,
10516 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010517 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010518 NL80211_FLAG_NEED_RTNL,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010010519 },
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010520 {
10521 .cmd = NL80211_CMD_SET_BSS,
10522 .doit = nl80211_set_bss,
10523 .policy = nl80211_policy,
10524 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010525 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010526 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9f1ba902008-08-07 20:07:01 +030010527 },
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010528 {
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010529 .cmd = NL80211_CMD_GET_REG,
Arik Nemtsovad30ca22014-12-15 19:25:59 +020010530 .doit = nl80211_get_reg_do,
10531 .dumpit = nl80211_get_reg_dump,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010532 .policy = nl80211_policy,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010533 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezf1303472009-01-30 09:26:42 -080010534 /* can be retrieved by unprivileged users */
10535 },
10536 {
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010537 .cmd = NL80211_CMD_SET_REG,
10538 .doit = nl80211_set_reg,
10539 .policy = nl80211_policy,
10540 .flags = GENL_ADMIN_PERM,
Johannes Berg5fe231e2013-05-08 21:45:15 +020010541 .internal_flags = NL80211_FLAG_NEED_RTNL,
Luis R. Rodriguezb2e1b302008-09-09 23:19:48 -070010542 },
10543 {
10544 .cmd = NL80211_CMD_REQ_SET_REG,
10545 .doit = nl80211_req_set_reg,
10546 .policy = nl80211_policy,
10547 .flags = GENL_ADMIN_PERM,
10548 },
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010549 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010550 .cmd = NL80211_CMD_GET_MESH_CONFIG,
10551 .doit = nl80211_get_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010552 .policy = nl80211_policy,
10553 /* can be retrieved by unprivileged users */
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010554 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010555 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010556 },
10557 {
Javier Cardona24bdd9f2010-12-16 17:37:48 -080010558 .cmd = NL80211_CMD_SET_MESH_CONFIG,
10559 .doit = nl80211_update_mesh_config,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010560 .policy = nl80211_policy,
10561 .flags = GENL_ADMIN_PERM,
Johannes Berg29cbe682010-12-03 09:20:44 +010010562 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010563 NL80211_FLAG_NEED_RTNL,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -070010564 },
Jouni Malinen9aed3cc2009-01-13 16:03:29 +020010565 {
Johannes Berg2a519312009-02-10 21:25:55 +010010566 .cmd = NL80211_CMD_TRIGGER_SCAN,
10567 .doit = nl80211_trigger_scan,
10568 .policy = nl80211_policy,
10569 .flags = GENL_ADMIN_PERM,
Johannes Bergfd014282012-06-18 19:17:03 +020010570 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010571 NL80211_FLAG_NEED_RTNL,
Johannes Berg2a519312009-02-10 21:25:55 +010010572 },
10573 {
10574 .cmd = NL80211_CMD_GET_SCAN,
10575 .policy = nl80211_policy,
10576 .dumpit = nl80211_dump_scan,
10577 },
Jouni Malinen636a5d32009-03-19 13:39:22 +020010578 {
Luciano Coelho807f8a82011-05-11 17:09:35 +030010579 .cmd = NL80211_CMD_START_SCHED_SCAN,
10580 .doit = nl80211_start_sched_scan,
10581 .policy = nl80211_policy,
10582 .flags = GENL_ADMIN_PERM,
10583 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10584 NL80211_FLAG_NEED_RTNL,
10585 },
10586 {
10587 .cmd = NL80211_CMD_STOP_SCHED_SCAN,
10588 .doit = nl80211_stop_sched_scan,
10589 .policy = nl80211_policy,
10590 .flags = GENL_ADMIN_PERM,
10591 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10592 NL80211_FLAG_NEED_RTNL,
10593 },
10594 {
Jouni Malinen636a5d32009-03-19 13:39:22 +020010595 .cmd = NL80211_CMD_AUTHENTICATE,
10596 .doit = nl80211_authenticate,
10597 .policy = nl80211_policy,
10598 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010599 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010600 NL80211_FLAG_NEED_RTNL |
10601 NL80211_FLAG_CLEAR_SKB,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010602 },
10603 {
10604 .cmd = NL80211_CMD_ASSOCIATE,
10605 .doit = nl80211_associate,
10606 .policy = nl80211_policy,
10607 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010608 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010609 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010610 },
10611 {
10612 .cmd = NL80211_CMD_DEAUTHENTICATE,
10613 .doit = nl80211_deauthenticate,
10614 .policy = nl80211_policy,
10615 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010616 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010617 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010618 },
10619 {
10620 .cmd = NL80211_CMD_DISASSOCIATE,
10621 .doit = nl80211_disassociate,
10622 .policy = nl80211_policy,
10623 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010624 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010625 NL80211_FLAG_NEED_RTNL,
Jouni Malinen636a5d32009-03-19 13:39:22 +020010626 },
Johannes Berg04a773a2009-04-19 21:24:32 +020010627 {
10628 .cmd = NL80211_CMD_JOIN_IBSS,
10629 .doit = nl80211_join_ibss,
10630 .policy = nl80211_policy,
10631 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010632 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010633 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010634 },
10635 {
10636 .cmd = NL80211_CMD_LEAVE_IBSS,
10637 .doit = nl80211_leave_ibss,
10638 .policy = nl80211_policy,
10639 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010640 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010641 NL80211_FLAG_NEED_RTNL,
Johannes Berg04a773a2009-04-19 21:24:32 +020010642 },
Johannes Bergaff89a92009-07-01 21:26:51 +020010643#ifdef CONFIG_NL80211_TESTMODE
10644 {
10645 .cmd = NL80211_CMD_TESTMODE,
10646 .doit = nl80211_testmode_do,
Wey-Yi Guy71063f02011-05-20 09:05:54 -070010647 .dumpit = nl80211_testmode_dump,
Johannes Bergaff89a92009-07-01 21:26:51 +020010648 .policy = nl80211_policy,
10649 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010650 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10651 NL80211_FLAG_NEED_RTNL,
Johannes Bergaff89a92009-07-01 21:26:51 +020010652 },
10653#endif
Samuel Ortizb23aa672009-07-01 21:26:54 +020010654 {
10655 .cmd = NL80211_CMD_CONNECT,
10656 .doit = nl80211_connect,
10657 .policy = nl80211_policy,
10658 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010659 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010660 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010661 },
10662 {
10663 .cmd = NL80211_CMD_DISCONNECT,
10664 .doit = nl80211_disconnect,
10665 .policy = nl80211_policy,
10666 .flags = GENL_ADMIN_PERM,
Johannes Berg41265712010-10-04 21:14:05 +020010667 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010668 NL80211_FLAG_NEED_RTNL,
Samuel Ortizb23aa672009-07-01 21:26:54 +020010669 },
Johannes Berg463d0182009-07-14 00:33:35 +020010670 {
10671 .cmd = NL80211_CMD_SET_WIPHY_NETNS,
10672 .doit = nl80211_wiphy_netns,
10673 .policy = nl80211_policy,
10674 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010675 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10676 NL80211_FLAG_NEED_RTNL,
Johannes Berg463d0182009-07-14 00:33:35 +020010677 },
Holger Schurig61fa7132009-11-11 12:25:40 +010010678 {
10679 .cmd = NL80211_CMD_GET_SURVEY,
10680 .policy = nl80211_policy,
10681 .dumpit = nl80211_dump_survey,
10682 },
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010683 {
10684 .cmd = NL80211_CMD_SET_PMKSA,
10685 .doit = nl80211_setdel_pmksa,
10686 .policy = nl80211_policy,
10687 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010688 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010689 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010690 },
10691 {
10692 .cmd = NL80211_CMD_DEL_PMKSA,
10693 .doit = nl80211_setdel_pmksa,
10694 .policy = nl80211_policy,
10695 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010696 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010697 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010698 },
10699 {
10700 .cmd = NL80211_CMD_FLUSH_PMKSA,
10701 .doit = nl80211_flush_pmksa,
10702 .policy = nl80211_policy,
10703 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010704 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010705 NL80211_FLAG_NEED_RTNL,
Samuel Ortiz67fbb162009-11-24 23:59:15 +010010706 },
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010707 {
10708 .cmd = NL80211_CMD_REMAIN_ON_CHANNEL,
10709 .doit = nl80211_remain_on_channel,
10710 .policy = nl80211_policy,
10711 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010712 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010713 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010714 },
10715 {
10716 .cmd = NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
10717 .doit = nl80211_cancel_remain_on_channel,
10718 .policy = nl80211_policy,
10719 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010720 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010721 NL80211_FLAG_NEED_RTNL,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010010722 },
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010723 {
10724 .cmd = NL80211_CMD_SET_TX_BITRATE_MASK,
10725 .doit = nl80211_set_tx_bitrate_mask,
10726 .policy = nl80211_policy,
10727 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010728 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10729 NL80211_FLAG_NEED_RTNL,
Jouni Malinen13ae75b2009-12-29 12:59:45 +020010730 },
Jouni Malinen026331c2010-02-15 12:53:10 +020010731 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010732 .cmd = NL80211_CMD_REGISTER_FRAME,
10733 .doit = nl80211_register_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010734 .policy = nl80211_policy,
10735 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010736 .internal_flags = NL80211_FLAG_NEED_WDEV |
Johannes Berg4c476992010-10-04 21:36:35 +020010737 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010738 },
10739 {
Johannes Berg2e161f72010-08-12 15:38:38 +020010740 .cmd = NL80211_CMD_FRAME,
10741 .doit = nl80211_tx_mgmt,
Jouni Malinen026331c2010-02-15 12:53:10 +020010742 .policy = nl80211_policy,
10743 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010744 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Berg4c476992010-10-04 21:36:35 +020010745 NL80211_FLAG_NEED_RTNL,
Jouni Malinen026331c2010-02-15 12:53:10 +020010746 },
Kalle Valoffb9eb32010-02-17 17:58:10 +020010747 {
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010748 .cmd = NL80211_CMD_FRAME_WAIT_CANCEL,
10749 .doit = nl80211_tx_mgmt_cancel_wait,
10750 .policy = nl80211_policy,
10751 .flags = GENL_ADMIN_PERM,
Johannes Berg71bbc992012-06-15 15:30:18 +020010752 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
Johannes Bergf7ca38d2010-11-25 10:02:29 +010010753 NL80211_FLAG_NEED_RTNL,
10754 },
10755 {
Kalle Valoffb9eb32010-02-17 17:58:10 +020010756 .cmd = NL80211_CMD_SET_POWER_SAVE,
10757 .doit = nl80211_set_power_save,
10758 .policy = nl80211_policy,
10759 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010760 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10761 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010762 },
10763 {
10764 .cmd = NL80211_CMD_GET_POWER_SAVE,
10765 .doit = nl80211_get_power_save,
10766 .policy = nl80211_policy,
10767 /* can be retrieved by unprivileged users */
Johannes Berg4c476992010-10-04 21:36:35 +020010768 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10769 NL80211_FLAG_NEED_RTNL,
Kalle Valoffb9eb32010-02-17 17:58:10 +020010770 },
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010771 {
10772 .cmd = NL80211_CMD_SET_CQM,
10773 .doit = nl80211_set_cqm,
10774 .policy = nl80211_policy,
10775 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010776 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10777 NL80211_FLAG_NEED_RTNL,
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020010778 },
Johannes Bergf444de02010-05-05 15:25:02 +020010779 {
10780 .cmd = NL80211_CMD_SET_CHANNEL,
10781 .doit = nl80211_set_channel,
10782 .policy = nl80211_policy,
10783 .flags = GENL_ADMIN_PERM,
Johannes Berg4c476992010-10-04 21:36:35 +020010784 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10785 NL80211_FLAG_NEED_RTNL,
Johannes Bergf444de02010-05-05 15:25:02 +020010786 },
Bill Jordane8347eb2010-10-01 13:54:28 -040010787 {
10788 .cmd = NL80211_CMD_SET_WDS_PEER,
10789 .doit = nl80211_set_wds_peer,
10790 .policy = nl80211_policy,
10791 .flags = GENL_ADMIN_PERM,
Johannes Berg43b19952010-10-07 13:10:30 +020010792 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10793 NL80211_FLAG_NEED_RTNL,
Bill Jordane8347eb2010-10-01 13:54:28 -040010794 },
Johannes Berg29cbe682010-12-03 09:20:44 +010010795 {
10796 .cmd = NL80211_CMD_JOIN_MESH,
10797 .doit = nl80211_join_mesh,
10798 .policy = nl80211_policy,
10799 .flags = GENL_ADMIN_PERM,
10800 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10801 NL80211_FLAG_NEED_RTNL,
10802 },
10803 {
10804 .cmd = NL80211_CMD_LEAVE_MESH,
10805 .doit = nl80211_leave_mesh,
10806 .policy = nl80211_policy,
10807 .flags = GENL_ADMIN_PERM,
10808 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10809 NL80211_FLAG_NEED_RTNL,
10810 },
Rostislav Lisovy6e0bd6c2014-11-03 10:33:18 +010010811 {
10812 .cmd = NL80211_CMD_JOIN_OCB,
10813 .doit = nl80211_join_ocb,
10814 .policy = nl80211_policy,
10815 .flags = GENL_ADMIN_PERM,
10816 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10817 NL80211_FLAG_NEED_RTNL,
10818 },
10819 {
10820 .cmd = NL80211_CMD_LEAVE_OCB,
10821 .doit = nl80211_leave_ocb,
10822 .policy = nl80211_policy,
10823 .flags = GENL_ADMIN_PERM,
10824 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10825 NL80211_FLAG_NEED_RTNL,
10826 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010827#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +020010828 {
10829 .cmd = NL80211_CMD_GET_WOWLAN,
10830 .doit = nl80211_get_wowlan,
10831 .policy = nl80211_policy,
10832 /* can be retrieved by unprivileged users */
10833 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10834 NL80211_FLAG_NEED_RTNL,
10835 },
10836 {
10837 .cmd = NL80211_CMD_SET_WOWLAN,
10838 .doit = nl80211_set_wowlan,
10839 .policy = nl80211_policy,
10840 .flags = GENL_ADMIN_PERM,
10841 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10842 NL80211_FLAG_NEED_RTNL,
10843 },
Johannes Bergdfb89c52012-06-27 09:23:48 +020010844#endif
Johannes Berge5497d72011-07-05 16:35:40 +020010845 {
10846 .cmd = NL80211_CMD_SET_REKEY_OFFLOAD,
10847 .doit = nl80211_set_rekey_data,
10848 .policy = nl80211_policy,
10849 .flags = GENL_ADMIN_PERM,
10850 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg5393b912014-09-10 15:00:16 +030010851 NL80211_FLAG_NEED_RTNL |
10852 NL80211_FLAG_CLEAR_SKB,
Johannes Berge5497d72011-07-05 16:35:40 +020010853 },
Arik Nemtsov109086c2011-09-28 14:12:50 +030010854 {
10855 .cmd = NL80211_CMD_TDLS_MGMT,
10856 .doit = nl80211_tdls_mgmt,
10857 .policy = nl80211_policy,
10858 .flags = GENL_ADMIN_PERM,
10859 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10860 NL80211_FLAG_NEED_RTNL,
10861 },
10862 {
10863 .cmd = NL80211_CMD_TDLS_OPER,
10864 .doit = nl80211_tdls_oper,
10865 .policy = nl80211_policy,
10866 .flags = GENL_ADMIN_PERM,
10867 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10868 NL80211_FLAG_NEED_RTNL,
10869 },
Johannes Berg28946da2011-11-04 11:18:12 +010010870 {
10871 .cmd = NL80211_CMD_UNEXPECTED_FRAME,
10872 .doit = nl80211_register_unexpected_frame,
10873 .policy = nl80211_policy,
10874 .flags = GENL_ADMIN_PERM,
10875 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10876 NL80211_FLAG_NEED_RTNL,
10877 },
Johannes Berg7f6cf312011-11-04 11:18:15 +010010878 {
10879 .cmd = NL80211_CMD_PROBE_CLIENT,
10880 .doit = nl80211_probe_client,
10881 .policy = nl80211_policy,
10882 .flags = GENL_ADMIN_PERM,
Johannes Berg2b5f8b02012-04-02 10:51:55 +020010883 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
Johannes Berg7f6cf312011-11-04 11:18:15 +010010884 NL80211_FLAG_NEED_RTNL,
10885 },
Johannes Berg5e760232011-11-04 11:18:17 +010010886 {
10887 .cmd = NL80211_CMD_REGISTER_BEACONS,
10888 .doit = nl80211_register_beacons,
10889 .policy = nl80211_policy,
10890 .flags = GENL_ADMIN_PERM,
10891 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10892 NL80211_FLAG_NEED_RTNL,
10893 },
Simon Wunderlich1d9d9212011-11-18 14:20:43 +010010894 {
10895 .cmd = NL80211_CMD_SET_NOACK_MAP,
10896 .doit = nl80211_set_noack_map,
10897 .policy = nl80211_policy,
10898 .flags = GENL_ADMIN_PERM,
10899 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10900 NL80211_FLAG_NEED_RTNL,
10901 },
Johannes Berg98104fde2012-06-16 00:19:54 +020010902 {
10903 .cmd = NL80211_CMD_START_P2P_DEVICE,
10904 .doit = nl80211_start_p2p_device,
10905 .policy = nl80211_policy,
10906 .flags = GENL_ADMIN_PERM,
10907 .internal_flags = NL80211_FLAG_NEED_WDEV |
10908 NL80211_FLAG_NEED_RTNL,
10909 },
10910 {
10911 .cmd = NL80211_CMD_STOP_P2P_DEVICE,
10912 .doit = nl80211_stop_p2p_device,
10913 .policy = nl80211_policy,
10914 .flags = GENL_ADMIN_PERM,
10915 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10916 NL80211_FLAG_NEED_RTNL,
10917 },
Antonio Quartullif4e583c2012-11-02 13:27:48 +010010918 {
10919 .cmd = NL80211_CMD_SET_MCAST_RATE,
10920 .doit = nl80211_set_mcast_rate,
10921 .policy = nl80211_policy,
10922 .flags = GENL_ADMIN_PERM,
10923 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10924 NL80211_FLAG_NEED_RTNL,
10925 },
Vasanthakumar Thiagarajan77765ea2013-01-18 11:18:45 +053010926 {
10927 .cmd = NL80211_CMD_SET_MAC_ACL,
10928 .doit = nl80211_set_mac_acl,
10929 .policy = nl80211_policy,
10930 .flags = GENL_ADMIN_PERM,
10931 .internal_flags = NL80211_FLAG_NEED_NETDEV |
10932 NL80211_FLAG_NEED_RTNL,
10933 },
Simon Wunderlich04f39042013-02-08 18:16:19 +010010934 {
10935 .cmd = NL80211_CMD_RADAR_DETECT,
10936 .doit = nl80211_start_radar_detection,
10937 .policy = nl80211_policy,
10938 .flags = GENL_ADMIN_PERM,
10939 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10940 NL80211_FLAG_NEED_RTNL,
10941 },
Johannes Berg3713b4e2013-02-14 16:19:38 +010010942 {
10943 .cmd = NL80211_CMD_GET_PROTOCOL_FEATURES,
10944 .doit = nl80211_get_protocol_features,
10945 .policy = nl80211_policy,
10946 },
Jouni Malinen355199e2013-02-27 17:14:27 +020010947 {
10948 .cmd = NL80211_CMD_UPDATE_FT_IES,
10949 .doit = nl80211_update_ft_ies,
10950 .policy = nl80211_policy,
10951 .flags = GENL_ADMIN_PERM,
10952 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10953 NL80211_FLAG_NEED_RTNL,
10954 },
Arend van Spriel5de17982013-04-18 15:49:00 +020010955 {
10956 .cmd = NL80211_CMD_CRIT_PROTOCOL_START,
10957 .doit = nl80211_crit_protocol_start,
10958 .policy = nl80211_policy,
10959 .flags = GENL_ADMIN_PERM,
10960 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10961 NL80211_FLAG_NEED_RTNL,
10962 },
10963 {
10964 .cmd = NL80211_CMD_CRIT_PROTOCOL_STOP,
10965 .doit = nl80211_crit_protocol_stop,
10966 .policy = nl80211_policy,
10967 .flags = GENL_ADMIN_PERM,
10968 .internal_flags = NL80211_FLAG_NEED_WDEV_UP |
10969 NL80211_FLAG_NEED_RTNL,
Amitkumar Karwarbe29b992013-06-28 11:51:26 -070010970 },
10971 {
10972 .cmd = NL80211_CMD_GET_COALESCE,
10973 .doit = nl80211_get_coalesce,
10974 .policy = nl80211_policy,
10975 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10976 NL80211_FLAG_NEED_RTNL,
10977 },
10978 {
10979 .cmd = NL80211_CMD_SET_COALESCE,
10980 .doit = nl80211_set_coalesce,
10981 .policy = nl80211_policy,
10982 .flags = GENL_ADMIN_PERM,
10983 .internal_flags = NL80211_FLAG_NEED_WIPHY |
10984 NL80211_FLAG_NEED_RTNL,
Simon Wunderlich16ef1fe2013-07-11 16:09:05 +020010985 },
10986 {
10987 .cmd = NL80211_CMD_CHANNEL_SWITCH,
10988 .doit = nl80211_channel_switch,
10989 .policy = nl80211_policy,
10990 .flags = GENL_ADMIN_PERM,
10991 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
10992 NL80211_FLAG_NEED_RTNL,
10993 },
Johannes Bergad7e7182013-11-13 13:37:47 +010010994 {
10995 .cmd = NL80211_CMD_VENDOR,
10996 .doit = nl80211_vendor_cmd,
10997 .policy = nl80211_policy,
10998 .flags = GENL_ADMIN_PERM,
10999 .internal_flags = NL80211_FLAG_NEED_WIPHY |
11000 NL80211_FLAG_NEED_RTNL,
11001 },
Kyeyoon Parkfa9ffc72013-12-16 23:01:30 -080011002 {
11003 .cmd = NL80211_CMD_SET_QOS_MAP,
11004 .doit = nl80211_set_qos_map,
11005 .policy = nl80211_policy,
11006 .flags = GENL_ADMIN_PERM,
11007 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11008 NL80211_FLAG_NEED_RTNL,
11009 },
Johannes Berg960d01a2014-09-09 22:55:35 +030011010 {
11011 .cmd = NL80211_CMD_ADD_TX_TS,
11012 .doit = nl80211_add_tx_ts,
11013 .policy = nl80211_policy,
11014 .flags = GENL_ADMIN_PERM,
11015 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11016 NL80211_FLAG_NEED_RTNL,
11017 },
11018 {
11019 .cmd = NL80211_CMD_DEL_TX_TS,
11020 .doit = nl80211_del_tx_ts,
11021 .policy = nl80211_policy,
11022 .flags = GENL_ADMIN_PERM,
11023 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11024 NL80211_FLAG_NEED_RTNL,
11025 },
Arik Nemtsov1057d352014-11-19 12:54:26 +020011026 {
11027 .cmd = NL80211_CMD_TDLS_CHANNEL_SWITCH,
11028 .doit = nl80211_tdls_channel_switch,
11029 .policy = nl80211_policy,
11030 .flags = GENL_ADMIN_PERM,
11031 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11032 NL80211_FLAG_NEED_RTNL,
11033 },
11034 {
11035 .cmd = NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH,
11036 .doit = nl80211_tdls_cancel_channel_switch,
11037 .policy = nl80211_policy,
11038 .flags = GENL_ADMIN_PERM,
11039 .internal_flags = NL80211_FLAG_NEED_NETDEV_UP |
11040 NL80211_FLAG_NEED_RTNL,
11041 },
Johannes Berg55682962007-09-20 13:09:35 -040011042};
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011043
Johannes Berg55682962007-09-20 13:09:35 -040011044/* notification functions */
11045
Johannes Berg3bb20552014-05-26 13:52:25 +020011046void nl80211_notify_wiphy(struct cfg80211_registered_device *rdev,
11047 enum nl80211_commands cmd)
Johannes Berg55682962007-09-20 13:09:35 -040011048{
11049 struct sk_buff *msg;
Johannes Berg86e8cf92013-06-19 10:57:22 +020011050 struct nl80211_dump_wiphy_state state = {};
Johannes Berg55682962007-09-20 13:09:35 -040011051
Johannes Berg3bb20552014-05-26 13:52:25 +020011052 WARN_ON(cmd != NL80211_CMD_NEW_WIPHY &&
11053 cmd != NL80211_CMD_DEL_WIPHY);
11054
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011055 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011056 if (!msg)
11057 return;
11058
Johannes Berg3bb20552014-05-26 13:52:25 +020011059 if (nl80211_send_wiphy(rdev, cmd, msg, 0, 0, 0, &state) < 0) {
Johannes Berg55682962007-09-20 13:09:35 -040011060 nlmsg_free(msg);
11061 return;
11062 }
11063
Johannes Berg68eb5502013-11-19 15:19:38 +010011064 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011065 NL80211_MCGRP_CONFIG, GFP_KERNEL);
Johannes Berg55682962007-09-20 13:09:35 -040011066}
11067
Johannes Berg362a4152009-05-24 16:43:15 +020011068static int nl80211_add_scan_req(struct sk_buff *msg,
11069 struct cfg80211_registered_device *rdev)
11070{
11071 struct cfg80211_scan_request *req = rdev->scan_req;
11072 struct nlattr *nest;
11073 int i;
11074
11075 if (WARN_ON(!req))
11076 return 0;
11077
11078 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_SSIDS);
11079 if (!nest)
11080 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011081 for (i = 0; i < req->n_ssids; i++) {
11082 if (nla_put(msg, i, req->ssids[i].ssid_len, req->ssids[i].ssid))
11083 goto nla_put_failure;
11084 }
Johannes Berg362a4152009-05-24 16:43:15 +020011085 nla_nest_end(msg, nest);
11086
11087 nest = nla_nest_start(msg, NL80211_ATTR_SCAN_FREQUENCIES);
11088 if (!nest)
11089 goto nla_put_failure;
David S. Miller9360ffd2012-03-29 04:41:26 -040011090 for (i = 0; i < req->n_channels; i++) {
11091 if (nla_put_u32(msg, i, req->channels[i]->center_freq))
11092 goto nla_put_failure;
11093 }
Johannes Berg362a4152009-05-24 16:43:15 +020011094 nla_nest_end(msg, nest);
11095
David S. Miller9360ffd2012-03-29 04:41:26 -040011096 if (req->ie &&
11097 nla_put(msg, NL80211_ATTR_IE, req->ie_len, req->ie))
11098 goto nla_put_failure;
Johannes Berg362a4152009-05-24 16:43:15 +020011099
Johannes Bergae917c92013-10-25 11:05:22 +020011100 if (req->flags &&
11101 nla_put_u32(msg, NL80211_ATTR_SCAN_FLAGS, req->flags))
11102 goto nla_put_failure;
Sam Lefflered4737712012-10-11 21:03:31 -070011103
Johannes Berg362a4152009-05-24 16:43:15 +020011104 return 0;
11105 nla_put_failure:
11106 return -ENOBUFS;
11107}
11108
Johannes Berga538e2d2009-06-16 19:56:42 +020011109static int nl80211_send_scan_msg(struct sk_buff *msg,
11110 struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011111 struct wireless_dev *wdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011112 u32 portid, u32 seq, int flags,
Johannes Berga538e2d2009-06-16 19:56:42 +020011113 u32 cmd)
Johannes Berg2a519312009-02-10 21:25:55 +010011114{
11115 void *hdr;
11116
Eric W. Biederman15e47302012-09-07 20:12:54 +000011117 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Johannes Berg2a519312009-02-10 21:25:55 +010011118 if (!hdr)
11119 return -1;
11120
David S. Miller9360ffd2012-03-29 04:41:26 -040011121 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Bergfd014282012-06-18 19:17:03 +020011122 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11123 wdev->netdev->ifindex)) ||
11124 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
David S. Miller9360ffd2012-03-29 04:41:26 -040011125 goto nla_put_failure;
Johannes Berg2a519312009-02-10 21:25:55 +010011126
Johannes Berg362a4152009-05-24 16:43:15 +020011127 /* ignore errors and send incomplete event anyway */
11128 nl80211_add_scan_req(msg, rdev);
Johannes Berg2a519312009-02-10 21:25:55 +010011129
Johannes Berg053c0952015-01-16 22:09:00 +010011130 genlmsg_end(msg, hdr);
11131 return 0;
Johannes Berg2a519312009-02-10 21:25:55 +010011132
11133 nla_put_failure:
11134 genlmsg_cancel(msg, hdr);
11135 return -EMSGSIZE;
11136}
11137
Luciano Coelho807f8a82011-05-11 17:09:35 +030011138static int
11139nl80211_send_sched_scan_msg(struct sk_buff *msg,
11140 struct cfg80211_registered_device *rdev,
11141 struct net_device *netdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000011142 u32 portid, u32 seq, int flags, u32 cmd)
Luciano Coelho807f8a82011-05-11 17:09:35 +030011143{
11144 void *hdr;
11145
Eric W. Biederman15e47302012-09-07 20:12:54 +000011146 hdr = nl80211hdr_put(msg, portid, seq, flags, cmd);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011147 if (!hdr)
11148 return -1;
11149
David S. Miller9360ffd2012-03-29 04:41:26 -040011150 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11151 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
11152 goto nla_put_failure;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011153
Johannes Berg053c0952015-01-16 22:09:00 +010011154 genlmsg_end(msg, hdr);
11155 return 0;
Luciano Coelho807f8a82011-05-11 17:09:35 +030011156
11157 nla_put_failure:
11158 genlmsg_cancel(msg, hdr);
11159 return -EMSGSIZE;
11160}
11161
Johannes Berga538e2d2009-06-16 19:56:42 +020011162void nl80211_send_scan_start(struct cfg80211_registered_device *rdev,
Johannes Bergfd014282012-06-18 19:17:03 +020011163 struct wireless_dev *wdev)
Johannes Berga538e2d2009-06-16 19:56:42 +020011164{
11165 struct sk_buff *msg;
11166
Thomas Graf58050fc2012-06-28 03:57:45 +000011167 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011168 if (!msg)
11169 return;
11170
Johannes Bergfd014282012-06-18 19:17:03 +020011171 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Berga538e2d2009-06-16 19:56:42 +020011172 NL80211_CMD_TRIGGER_SCAN) < 0) {
11173 nlmsg_free(msg);
11174 return;
11175 }
11176
Johannes Berg68eb5502013-11-19 15:19:38 +010011177 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011178 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berga538e2d2009-06-16 19:56:42 +020011179}
11180
Johannes Bergf9d15d12014-01-22 11:14:19 +020011181struct sk_buff *nl80211_build_scan_msg(struct cfg80211_registered_device *rdev,
11182 struct wireless_dev *wdev, bool aborted)
Johannes Berg2a519312009-02-10 21:25:55 +010011183{
11184 struct sk_buff *msg;
11185
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011186 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011187 if (!msg)
Johannes Bergf9d15d12014-01-22 11:14:19 +020011188 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011189
Johannes Bergfd014282012-06-18 19:17:03 +020011190 if (nl80211_send_scan_msg(msg, rdev, wdev, 0, 0, 0,
Johannes Bergf9d15d12014-01-22 11:14:19 +020011191 aborted ? NL80211_CMD_SCAN_ABORTED :
11192 NL80211_CMD_NEW_SCAN_RESULTS) < 0) {
Johannes Berg2a519312009-02-10 21:25:55 +010011193 nlmsg_free(msg);
Johannes Bergf9d15d12014-01-22 11:14:19 +020011194 return NULL;
Johannes Berg2a519312009-02-10 21:25:55 +010011195 }
11196
Johannes Bergf9d15d12014-01-22 11:14:19 +020011197 return msg;
Johannes Berg2a519312009-02-10 21:25:55 +010011198}
11199
Johannes Bergf9d15d12014-01-22 11:14:19 +020011200void nl80211_send_scan_result(struct cfg80211_registered_device *rdev,
11201 struct sk_buff *msg)
Johannes Berg2a519312009-02-10 21:25:55 +010011202{
Johannes Berg2a519312009-02-10 21:25:55 +010011203 if (!msg)
11204 return;
11205
Johannes Berg68eb5502013-11-19 15:19:38 +010011206 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011207 NL80211_MCGRP_SCAN, GFP_KERNEL);
Johannes Berg2a519312009-02-10 21:25:55 +010011208}
11209
Luciano Coelho807f8a82011-05-11 17:09:35 +030011210void nl80211_send_sched_scan_results(struct cfg80211_registered_device *rdev,
11211 struct net_device *netdev)
11212{
11213 struct sk_buff *msg;
11214
11215 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11216 if (!msg)
11217 return;
11218
11219 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0,
11220 NL80211_CMD_SCHED_SCAN_RESULTS) < 0) {
11221 nlmsg_free(msg);
11222 return;
11223 }
11224
Johannes Berg68eb5502013-11-19 15:19:38 +010011225 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011226 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011227}
11228
11229void nl80211_send_sched_scan(struct cfg80211_registered_device *rdev,
11230 struct net_device *netdev, u32 cmd)
11231{
11232 struct sk_buff *msg;
11233
Thomas Graf58050fc2012-06-28 03:57:45 +000011234 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011235 if (!msg)
11236 return;
11237
11238 if (nl80211_send_sched_scan_msg(msg, rdev, netdev, 0, 0, 0, cmd) < 0) {
11239 nlmsg_free(msg);
11240 return;
11241 }
11242
Johannes Berg68eb5502013-11-19 15:19:38 +010011243 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011244 NL80211_MCGRP_SCAN, GFP_KERNEL);
Luciano Coelho807f8a82011-05-11 17:09:35 +030011245}
11246
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011247static bool nl80211_reg_change_event_fill(struct sk_buff *msg,
11248 struct regulatory_request *request)
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011249{
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011250 /* Userspace can always count this one always being set */
David S. Miller9360ffd2012-03-29 04:41:26 -040011251 if (nla_put_u8(msg, NL80211_ATTR_REG_INITIATOR, request->initiator))
11252 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011253
David S. Miller9360ffd2012-03-29 04:41:26 -040011254 if (request->alpha2[0] == '0' && request->alpha2[1] == '0') {
11255 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11256 NL80211_REGDOM_TYPE_WORLD))
11257 goto nla_put_failure;
11258 } else if (request->alpha2[0] == '9' && request->alpha2[1] == '9') {
11259 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11260 NL80211_REGDOM_TYPE_CUSTOM_WORLD))
11261 goto nla_put_failure;
11262 } else if ((request->alpha2[0] == '9' && request->alpha2[1] == '8') ||
11263 request->intersect) {
11264 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11265 NL80211_REGDOM_TYPE_INTERSECTION))
11266 goto nla_put_failure;
11267 } else {
11268 if (nla_put_u8(msg, NL80211_ATTR_REG_TYPE,
11269 NL80211_REGDOM_TYPE_COUNTRY) ||
11270 nla_put_string(msg, NL80211_ATTR_REG_ALPHA2,
11271 request->alpha2))
11272 goto nla_put_failure;
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011273 }
11274
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011275 if (request->wiphy_idx != WIPHY_IDX_INVALID) {
11276 struct wiphy *wiphy = wiphy_idx_to_wiphy(request->wiphy_idx);
11277
11278 if (wiphy &&
11279 nla_put_u32(msg, NL80211_ATTR_WIPHY, request->wiphy_idx))
11280 goto nla_put_failure;
Arik Nemtsov1bdd7162014-12-15 19:26:01 +020011281
11282 if (wiphy &&
11283 wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED &&
11284 nla_put_flag(msg, NL80211_ATTR_WIPHY_SELF_MANAGED_REG))
11285 goto nla_put_failure;
Arik Nemtsovad30ca22014-12-15 19:25:59 +020011286 }
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011287
Jonathan Doronb0d7aa52014-12-15 19:26:00 +020011288 return true;
11289
11290nla_put_failure:
11291 return false;
11292}
11293
11294/*
11295 * This can happen on global regulatory changes or device specific settings
11296 * based on custom regulatory domains.
11297 */
11298void nl80211_common_reg_change_event(enum nl80211_commands cmd_id,
11299 struct regulatory_request *request)
11300{
11301 struct sk_buff *msg;
11302 void *hdr;
11303
11304 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
11305 if (!msg)
11306 return;
11307
11308 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd_id);
11309 if (!hdr) {
11310 nlmsg_free(msg);
11311 return;
11312 }
11313
11314 if (nl80211_reg_change_event_fill(msg, request) == false)
11315 goto nla_put_failure;
11316
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011317 genlmsg_end(msg, hdr);
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011318
Johannes Bergbc43b282009-07-25 10:54:13 +020011319 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011320 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011321 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Bergbc43b282009-07-25 10:54:13 +020011322 rcu_read_unlock();
Luis R. Rodriguez73d54c92009-03-09 22:07:42 -040011323
11324 return;
11325
11326nla_put_failure:
11327 genlmsg_cancel(msg, hdr);
11328 nlmsg_free(msg);
11329}
11330
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011331static void nl80211_send_mlme_event(struct cfg80211_registered_device *rdev,
11332 struct net_device *netdev,
11333 const u8 *buf, size_t len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011334 enum nl80211_commands cmd, gfp_t gfp,
11335 int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011336{
11337 struct sk_buff *msg;
11338 void *hdr;
11339
Johannes Berge6d6e342009-07-01 21:26:47 +020011340 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011341 if (!msg)
11342 return;
11343
11344 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11345 if (!hdr) {
11346 nlmsg_free(msg);
11347 return;
11348 }
11349
David S. Miller9360ffd2012-03-29 04:41:26 -040011350 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11351 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11352 nla_put(msg, NL80211_ATTR_FRAME, len, buf))
11353 goto nla_put_failure;
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011354
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011355 if (uapsd_queues >= 0) {
11356 struct nlattr *nla_wmm =
11357 nla_nest_start(msg, NL80211_ATTR_STA_WME);
11358 if (!nla_wmm)
11359 goto nla_put_failure;
11360
11361 if (nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
11362 uapsd_queues))
11363 goto nla_put_failure;
11364
11365 nla_nest_end(msg, nla_wmm);
11366 }
11367
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011368 genlmsg_end(msg, hdr);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011369
Johannes Berg68eb5502013-11-19 15:19:38 +010011370 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011371 NL80211_MCGRP_MLME, gfp);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011372 return;
11373
11374 nla_put_failure:
11375 genlmsg_cancel(msg, hdr);
11376 nlmsg_free(msg);
11377}
11378
11379void nl80211_send_rx_auth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011380 struct net_device *netdev, const u8 *buf,
11381 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011382{
11383 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011384 NL80211_CMD_AUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011385}
11386
11387void nl80211_send_rx_assoc(struct cfg80211_registered_device *rdev,
11388 struct net_device *netdev, const u8 *buf,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011389 size_t len, gfp_t gfp, int uapsd_queues)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011390{
Johannes Berge6d6e342009-07-01 21:26:47 +020011391 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011392 NL80211_CMD_ASSOCIATE, gfp, uapsd_queues);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011393}
11394
Jouni Malinen53b46b82009-03-27 20:53:56 +020011395void nl80211_send_deauth(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011396 struct net_device *netdev, const u8 *buf,
11397 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011398{
11399 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011400 NL80211_CMD_DEAUTHENTICATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011401}
11402
Jouni Malinen53b46b82009-03-27 20:53:56 +020011403void nl80211_send_disassoc(struct cfg80211_registered_device *rdev,
11404 struct net_device *netdev, const u8 *buf,
Johannes Berge6d6e342009-07-01 21:26:47 +020011405 size_t len, gfp_t gfp)
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011406{
11407 nl80211_send_mlme_event(rdev, netdev, buf, len,
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011408 NL80211_CMD_DISASSOCIATE, gfp, -1);
Jouni Malinen6039f6d2009-03-19 13:39:21 +020011409}
11410
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011411void cfg80211_rx_unprot_mlme_mgmt(struct net_device *dev, const u8 *buf,
11412 size_t len)
Jouni Malinencf4e5942010-12-16 00:52:40 +020011413{
Johannes Berg947add32013-02-22 22:05:20 +010011414 struct wireless_dev *wdev = dev->ieee80211_ptr;
11415 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011416 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011417 const struct ieee80211_mgmt *mgmt = (void *)buf;
11418 u32 cmd;
Jouni Malinencf4e5942010-12-16 00:52:40 +020011419
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011420 if (WARN_ON(len < 2))
11421 return;
11422
11423 if (ieee80211_is_deauth(mgmt->frame_control))
11424 cmd = NL80211_CMD_UNPROT_DEAUTHENTICATE;
11425 else
11426 cmd = NL80211_CMD_UNPROT_DISASSOCIATE;
11427
11428 trace_cfg80211_rx_unprot_mlme_mgmt(dev, buf, len);
Eliad Pellerb0b6aa22014-09-09 17:09:45 +030011429 nl80211_send_mlme_event(rdev, dev, buf, len, cmd, GFP_ATOMIC, -1);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011430}
Johannes Berg6ff57cf2013-05-16 00:55:00 +020011431EXPORT_SYMBOL(cfg80211_rx_unprot_mlme_mgmt);
Jouni Malinencf4e5942010-12-16 00:52:40 +020011432
Luis R. Rodriguez1b06bb42009-05-02 00:34:48 -040011433static void nl80211_send_mlme_timeout(struct cfg80211_registered_device *rdev,
11434 struct net_device *netdev, int cmd,
Johannes Berge6d6e342009-07-01 21:26:47 +020011435 const u8 *addr, gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011436{
11437 struct sk_buff *msg;
11438 void *hdr;
11439
Johannes Berge6d6e342009-07-01 21:26:47 +020011440 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011441 if (!msg)
11442 return;
11443
11444 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11445 if (!hdr) {
11446 nlmsg_free(msg);
11447 return;
11448 }
11449
David S. Miller9360ffd2012-03-29 04:41:26 -040011450 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11451 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11452 nla_put_flag(msg, NL80211_ATTR_TIMED_OUT) ||
11453 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11454 goto nla_put_failure;
Jouni Malinen1965c852009-04-22 21:38:25 +030011455
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011456 genlmsg_end(msg, hdr);
Jouni Malinen1965c852009-04-22 21:38:25 +030011457
Johannes Berg68eb5502013-11-19 15:19:38 +010011458 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011459 NL80211_MCGRP_MLME, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011460 return;
11461
11462 nla_put_failure:
11463 genlmsg_cancel(msg, hdr);
11464 nlmsg_free(msg);
11465}
11466
11467void nl80211_send_auth_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011468 struct net_device *netdev, const u8 *addr,
11469 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011470{
11471 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_AUTHENTICATE,
Johannes Berge6d6e342009-07-01 21:26:47 +020011472 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011473}
11474
11475void nl80211_send_assoc_timeout(struct cfg80211_registered_device *rdev,
Johannes Berge6d6e342009-07-01 21:26:47 +020011476 struct net_device *netdev, const u8 *addr,
11477 gfp_t gfp)
Jouni Malinen1965c852009-04-22 21:38:25 +030011478{
Johannes Berge6d6e342009-07-01 21:26:47 +020011479 nl80211_send_mlme_timeout(rdev, netdev, NL80211_CMD_ASSOCIATE,
11480 addr, gfp);
Jouni Malinen1965c852009-04-22 21:38:25 +030011481}
11482
Samuel Ortizb23aa672009-07-01 21:26:54 +020011483void nl80211_send_connect_result(struct cfg80211_registered_device *rdev,
11484 struct net_device *netdev, const u8 *bssid,
11485 const u8 *req_ie, size_t req_ie_len,
11486 const u8 *resp_ie, size_t resp_ie_len,
11487 u16 status, gfp_t gfp)
11488{
11489 struct sk_buff *msg;
11490 void *hdr;
11491
Thomas Graf58050fc2012-06-28 03:57:45 +000011492 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011493 if (!msg)
11494 return;
11495
11496 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONNECT);
11497 if (!hdr) {
11498 nlmsg_free(msg);
11499 return;
11500 }
11501
David S. Miller9360ffd2012-03-29 04:41:26 -040011502 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11503 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11504 (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid)) ||
11505 nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status) ||
11506 (req_ie &&
11507 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11508 (resp_ie &&
11509 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11510 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011511
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011512 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011513
Johannes Berg68eb5502013-11-19 15:19:38 +010011514 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011515 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011516 return;
11517
11518 nla_put_failure:
11519 genlmsg_cancel(msg, hdr);
11520 nlmsg_free(msg);
11521
11522}
11523
11524void nl80211_send_roamed(struct cfg80211_registered_device *rdev,
11525 struct net_device *netdev, const u8 *bssid,
11526 const u8 *req_ie, size_t req_ie_len,
11527 const u8 *resp_ie, size_t resp_ie_len, gfp_t gfp)
11528{
11529 struct sk_buff *msg;
11530 void *hdr;
11531
Thomas Graf58050fc2012-06-28 03:57:45 +000011532 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011533 if (!msg)
11534 return;
11535
11536 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_ROAM);
11537 if (!hdr) {
11538 nlmsg_free(msg);
11539 return;
11540 }
11541
David S. Miller9360ffd2012-03-29 04:41:26 -040011542 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11543 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11544 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid) ||
11545 (req_ie &&
11546 nla_put(msg, NL80211_ATTR_REQ_IE, req_ie_len, req_ie)) ||
11547 (resp_ie &&
11548 nla_put(msg, NL80211_ATTR_RESP_IE, resp_ie_len, resp_ie)))
11549 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011550
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011551 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011552
Johannes Berg68eb5502013-11-19 15:19:38 +010011553 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011554 NL80211_MCGRP_MLME, gfp);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011555 return;
11556
11557 nla_put_failure:
11558 genlmsg_cancel(msg, hdr);
11559 nlmsg_free(msg);
11560
11561}
11562
11563void nl80211_send_disconnected(struct cfg80211_registered_device *rdev,
11564 struct net_device *netdev, u16 reason,
Johannes Berg667503dd2009-07-07 03:56:11 +020011565 const u8 *ie, size_t ie_len, bool from_ap)
Samuel Ortizb23aa672009-07-01 21:26:54 +020011566{
11567 struct sk_buff *msg;
11568 void *hdr;
11569
Thomas Graf58050fc2012-06-28 03:57:45 +000011570 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011571 if (!msg)
11572 return;
11573
11574 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_DISCONNECT);
11575 if (!hdr) {
11576 nlmsg_free(msg);
11577 return;
11578 }
11579
David S. Miller9360ffd2012-03-29 04:41:26 -040011580 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11581 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11582 (from_ap && reason &&
11583 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason)) ||
11584 (from_ap &&
11585 nla_put_flag(msg, NL80211_ATTR_DISCONNECTED_BY_AP)) ||
11586 (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie)))
11587 goto nla_put_failure;
Samuel Ortizb23aa672009-07-01 21:26:54 +020011588
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011589 genlmsg_end(msg, hdr);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011590
Johannes Berg68eb5502013-11-19 15:19:38 +010011591 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011592 NL80211_MCGRP_MLME, GFP_KERNEL);
Samuel Ortizb23aa672009-07-01 21:26:54 +020011593 return;
11594
11595 nla_put_failure:
11596 genlmsg_cancel(msg, hdr);
11597 nlmsg_free(msg);
11598
11599}
11600
Johannes Berg04a773a2009-04-19 21:24:32 +020011601void nl80211_send_ibss_bssid(struct cfg80211_registered_device *rdev,
11602 struct net_device *netdev, const u8 *bssid,
11603 gfp_t gfp)
11604{
11605 struct sk_buff *msg;
11606 void *hdr;
11607
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011608 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011609 if (!msg)
11610 return;
11611
11612 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_JOIN_IBSS);
11613 if (!hdr) {
11614 nlmsg_free(msg);
11615 return;
11616 }
11617
David S. Miller9360ffd2012-03-29 04:41:26 -040011618 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11619 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11620 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
11621 goto nla_put_failure;
Johannes Berg04a773a2009-04-19 21:24:32 +020011622
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011623 genlmsg_end(msg, hdr);
Johannes Berg04a773a2009-04-19 21:24:32 +020011624
Johannes Berg68eb5502013-11-19 15:19:38 +010011625 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011626 NL80211_MCGRP_MLME, gfp);
Johannes Berg04a773a2009-04-19 21:24:32 +020011627 return;
11628
11629 nla_put_failure:
11630 genlmsg_cancel(msg, hdr);
11631 nlmsg_free(msg);
11632}
11633
Johannes Berg947add32013-02-22 22:05:20 +010011634void cfg80211_notify_new_peer_candidate(struct net_device *dev, const u8 *addr,
11635 const u8* ie, u8 ie_len, gfp_t gfp)
Javier Cardonac93b5e72011-04-07 15:08:34 -070011636{
Johannes Berg947add32013-02-22 22:05:20 +010011637 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011638 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011639 struct sk_buff *msg;
11640 void *hdr;
11641
Johannes Berg947add32013-02-22 22:05:20 +010011642 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_MESH_POINT))
11643 return;
11644
11645 trace_cfg80211_notify_new_peer_candidate(dev, addr);
11646
Javier Cardonac93b5e72011-04-07 15:08:34 -070011647 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11648 if (!msg)
11649 return;
11650
11651 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NEW_PEER_CANDIDATE);
11652 if (!hdr) {
11653 nlmsg_free(msg);
11654 return;
11655 }
11656
David S. Miller9360ffd2012-03-29 04:41:26 -040011657 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010011658 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11659 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011660 (ie_len && ie &&
11661 nla_put(msg, NL80211_ATTR_IE, ie_len , ie)))
11662 goto nla_put_failure;
Javier Cardonac93b5e72011-04-07 15:08:34 -070011663
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011664 genlmsg_end(msg, hdr);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011665
Johannes Berg68eb5502013-11-19 15:19:38 +010011666 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011667 NL80211_MCGRP_MLME, gfp);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011668 return;
11669
11670 nla_put_failure:
11671 genlmsg_cancel(msg, hdr);
11672 nlmsg_free(msg);
11673}
Johannes Berg947add32013-02-22 22:05:20 +010011674EXPORT_SYMBOL(cfg80211_notify_new_peer_candidate);
Javier Cardonac93b5e72011-04-07 15:08:34 -070011675
Jouni Malinena3b8b052009-03-27 21:59:49 +020011676void nl80211_michael_mic_failure(struct cfg80211_registered_device *rdev,
11677 struct net_device *netdev, const u8 *addr,
11678 enum nl80211_key_type key_type, int key_id,
Johannes Berge6d6e342009-07-01 21:26:47 +020011679 const u8 *tsc, gfp_t gfp)
Jouni Malinena3b8b052009-03-27 21:59:49 +020011680{
11681 struct sk_buff *msg;
11682 void *hdr;
11683
Johannes Berge6d6e342009-07-01 21:26:47 +020011684 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011685 if (!msg)
11686 return;
11687
11688 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_MICHAEL_MIC_FAILURE);
11689 if (!hdr) {
11690 nlmsg_free(msg);
11691 return;
11692 }
11693
David S. Miller9360ffd2012-03-29 04:41:26 -040011694 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11695 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
11696 (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
11697 nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, key_type) ||
11698 (key_id != -1 &&
11699 nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_id)) ||
11700 (tsc && nla_put(msg, NL80211_ATTR_KEY_SEQ, 6, tsc)))
11701 goto nla_put_failure;
Jouni Malinena3b8b052009-03-27 21:59:49 +020011702
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011703 genlmsg_end(msg, hdr);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011704
Johannes Berg68eb5502013-11-19 15:19:38 +010011705 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011706 NL80211_MCGRP_MLME, gfp);
Jouni Malinena3b8b052009-03-27 21:59:49 +020011707 return;
11708
11709 nla_put_failure:
11710 genlmsg_cancel(msg, hdr);
11711 nlmsg_free(msg);
11712}
11713
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011714void nl80211_send_beacon_hint_event(struct wiphy *wiphy,
11715 struct ieee80211_channel *channel_before,
11716 struct ieee80211_channel *channel_after)
11717{
11718 struct sk_buff *msg;
11719 void *hdr;
11720 struct nlattr *nl_freq;
11721
Pablo Neira Ayusofd2120c2009-05-19 15:27:55 -070011722 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011723 if (!msg)
11724 return;
11725
11726 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_REG_BEACON_HINT);
11727 if (!hdr) {
11728 nlmsg_free(msg);
11729 return;
11730 }
11731
11732 /*
11733 * Since we are applying the beacon hint to a wiphy we know its
11734 * wiphy_idx is valid
11735 */
David S. Miller9360ffd2012-03-29 04:41:26 -040011736 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, get_wiphy_idx(wiphy)))
11737 goto nla_put_failure;
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011738
11739 /* Before */
11740 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_BEFORE);
11741 if (!nl_freq)
11742 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011743 if (nl80211_msg_put_channel(msg, channel_before, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011744 goto nla_put_failure;
11745 nla_nest_end(msg, nl_freq);
11746
11747 /* After */
11748 nl_freq = nla_nest_start(msg, NL80211_ATTR_FREQ_AFTER);
11749 if (!nl_freq)
11750 goto nla_put_failure;
Johannes Bergcdc89b92013-02-18 23:54:36 +010011751 if (nl80211_msg_put_channel(msg, channel_after, false))
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011752 goto nla_put_failure;
11753 nla_nest_end(msg, nl_freq);
11754
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011755 genlmsg_end(msg, hdr);
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011756
Johannes Berg463d0182009-07-14 00:33:35 +020011757 rcu_read_lock();
Johannes Berg68eb5502013-11-19 15:19:38 +010011758 genlmsg_multicast_allns(&nl80211_fam, msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011759 NL80211_MCGRP_REGULATORY, GFP_ATOMIC);
Johannes Berg463d0182009-07-14 00:33:35 +020011760 rcu_read_unlock();
Luis R. Rodriguez6bad8762009-04-02 14:08:09 -040011761
11762 return;
11763
11764nla_put_failure:
11765 genlmsg_cancel(msg, hdr);
11766 nlmsg_free(msg);
11767}
11768
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011769static void nl80211_send_remain_on_chan_event(
11770 int cmd, struct cfg80211_registered_device *rdev,
Johannes Berg71bbc992012-06-15 15:30:18 +020011771 struct wireless_dev *wdev, u64 cookie,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011772 struct ieee80211_channel *chan,
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011773 unsigned int duration, gfp_t gfp)
11774{
11775 struct sk_buff *msg;
11776 void *hdr;
11777
11778 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
11779 if (!msg)
11780 return;
11781
11782 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
11783 if (!hdr) {
11784 nlmsg_free(msg);
11785 return;
11786 }
11787
David S. Miller9360ffd2012-03-29 04:41:26 -040011788 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020011789 (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
11790 wdev->netdev->ifindex)) ||
Johannes Berg00f53352012-07-17 11:53:12 +020011791 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011792 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, chan->center_freq) ||
Johannes Berg42d97a52012-11-08 18:31:02 +010011793 nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE,
11794 NL80211_CHAN_NO_HT) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040011795 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie))
11796 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011797
David S. Miller9360ffd2012-03-29 04:41:26 -040011798 if (cmd == NL80211_CMD_REMAIN_ON_CHANNEL &&
11799 nla_put_u32(msg, NL80211_ATTR_DURATION, duration))
11800 goto nla_put_failure;
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011801
Johannes Berg3b7b72e2011-10-22 19:05:51 +020011802 genlmsg_end(msg, hdr);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011803
Johannes Berg68eb5502013-11-19 15:19:38 +010011804 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011805 NL80211_MCGRP_MLME, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011806 return;
11807
11808 nla_put_failure:
11809 genlmsg_cancel(msg, hdr);
11810 nlmsg_free(msg);
11811}
11812
Johannes Berg947add32013-02-22 22:05:20 +010011813void cfg80211_ready_on_channel(struct wireless_dev *wdev, u64 cookie,
11814 struct ieee80211_channel *chan,
11815 unsigned int duration, gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011816{
Johannes Berg947add32013-02-22 22:05:20 +010011817 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011818 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011819
11820 trace_cfg80211_ready_on_channel(wdev, cookie, chan, duration);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011821 nl80211_send_remain_on_chan_event(NL80211_CMD_REMAIN_ON_CHANNEL,
Johannes Berg71bbc992012-06-15 15:30:18 +020011822 rdev, wdev, cookie, chan,
Johannes Berg42d97a52012-11-08 18:31:02 +010011823 duration, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011824}
Johannes Berg947add32013-02-22 22:05:20 +010011825EXPORT_SYMBOL(cfg80211_ready_on_channel);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011826
Johannes Berg947add32013-02-22 22:05:20 +010011827void cfg80211_remain_on_channel_expired(struct wireless_dev *wdev, u64 cookie,
11828 struct ieee80211_channel *chan,
11829 gfp_t gfp)
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011830{
Johannes Berg947add32013-02-22 22:05:20 +010011831 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011832 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010011833
11834 trace_cfg80211_ready_on_channel_expired(wdev, cookie, chan);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011835 nl80211_send_remain_on_chan_event(NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL,
Johannes Berg42d97a52012-11-08 18:31:02 +010011836 rdev, wdev, cookie, chan, 0, gfp);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011837}
Johannes Berg947add32013-02-22 22:05:20 +010011838EXPORT_SYMBOL(cfg80211_remain_on_channel_expired);
Jouni Malinen9588bbd2009-12-23 13:15:41 +010011839
Johannes Berg947add32013-02-22 22:05:20 +010011840void cfg80211_new_sta(struct net_device *dev, const u8 *mac_addr,
11841 struct station_info *sinfo, gfp_t gfp)
Johannes Berg98b62182009-12-23 13:15:44 +010011842{
Johannes Berg947add32013-02-22 22:05:20 +010011843 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011844 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg98b62182009-12-23 13:15:44 +010011845 struct sk_buff *msg;
11846
Johannes Berg947add32013-02-22 22:05:20 +010011847 trace_cfg80211_new_sta(dev, mac_addr, sinfo);
11848
Thomas Graf58050fc2012-06-28 03:57:45 +000011849 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011850 if (!msg)
11851 return;
11852
Johannes Bergcf5ead82014-11-14 17:14:00 +010011853 if (nl80211_send_station(msg, NL80211_CMD_NEW_STATION, 0, 0, 0,
John W. Linville66266b32012-03-15 13:25:41 -040011854 rdev, dev, mac_addr, sinfo) < 0) {
Johannes Berg98b62182009-12-23 13:15:44 +010011855 nlmsg_free(msg);
11856 return;
11857 }
11858
Johannes Berg68eb5502013-11-19 15:19:38 +010011859 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011860 NL80211_MCGRP_MLME, gfp);
Johannes Berg98b62182009-12-23 13:15:44 +010011861}
Johannes Berg947add32013-02-22 22:05:20 +010011862EXPORT_SYMBOL(cfg80211_new_sta);
Johannes Berg98b62182009-12-23 13:15:44 +010011863
Johannes Bergcf5ead82014-11-14 17:14:00 +010011864void cfg80211_del_sta_sinfo(struct net_device *dev, const u8 *mac_addr,
11865 struct station_info *sinfo, gfp_t gfp)
Jouni Malinenec15e682011-03-23 15:29:52 +020011866{
Johannes Berg947add32013-02-22 22:05:20 +010011867 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011868 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinenec15e682011-03-23 15:29:52 +020011869 struct sk_buff *msg;
Johannes Bergcf5ead82014-11-14 17:14:00 +010011870 struct station_info empty_sinfo = {};
11871
11872 if (!sinfo)
11873 sinfo = &empty_sinfo;
Jouni Malinenec15e682011-03-23 15:29:52 +020011874
Johannes Berg947add32013-02-22 22:05:20 +010011875 trace_cfg80211_del_sta(dev, mac_addr);
11876
Thomas Graf58050fc2012-06-28 03:57:45 +000011877 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011878 if (!msg)
11879 return;
11880
Johannes Bergcf5ead82014-11-14 17:14:00 +010011881 if (nl80211_send_station(msg, NL80211_CMD_DEL_STATION, 0, 0, 0,
Johannes Berg57007122015-01-16 21:05:02 +010011882 rdev, dev, mac_addr, sinfo) < 0) {
Jouni Malinenec15e682011-03-23 15:29:52 +020011883 nlmsg_free(msg);
11884 return;
11885 }
11886
Johannes Berg68eb5502013-11-19 15:19:38 +010011887 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011888 NL80211_MCGRP_MLME, gfp);
Jouni Malinenec15e682011-03-23 15:29:52 +020011889}
Johannes Bergcf5ead82014-11-14 17:14:00 +010011890EXPORT_SYMBOL(cfg80211_del_sta_sinfo);
Jouni Malinenec15e682011-03-23 15:29:52 +020011891
Johannes Berg947add32013-02-22 22:05:20 +010011892void cfg80211_conn_failed(struct net_device *dev, const u8 *mac_addr,
11893 enum nl80211_connect_failed_reason reason,
11894 gfp_t gfp)
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011895{
Johannes Berg947add32013-02-22 22:05:20 +010011896 struct wiphy *wiphy = dev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011897 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011898 struct sk_buff *msg;
11899 void *hdr;
11900
11901 msg = nlmsg_new(NLMSG_GOODSIZE, gfp);
11902 if (!msg)
11903 return;
11904
11905 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CONN_FAILED);
11906 if (!hdr) {
11907 nlmsg_free(msg);
11908 return;
11909 }
11910
11911 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11912 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac_addr) ||
11913 nla_put_u32(msg, NL80211_ATTR_CONN_FAILED_REASON, reason))
11914 goto nla_put_failure;
11915
11916 genlmsg_end(msg, hdr);
11917
Johannes Berg68eb5502013-11-19 15:19:38 +010011918 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010011919 NL80211_MCGRP_MLME, gfp);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011920 return;
11921
11922 nla_put_failure:
11923 genlmsg_cancel(msg, hdr);
11924 nlmsg_free(msg);
11925}
Johannes Berg947add32013-02-22 22:05:20 +010011926EXPORT_SYMBOL(cfg80211_conn_failed);
Pandiyarajan Pitchaimuthued44a952012-09-18 16:50:49 +053011927
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011928static bool __nl80211_unexpected_frame(struct net_device *dev, u8 cmd,
11929 const u8 *addr, gfp_t gfp)
Johannes Berg28946da2011-11-04 11:18:12 +010011930{
11931 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080011932 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg28946da2011-11-04 11:18:12 +010011933 struct sk_buff *msg;
11934 void *hdr;
Eric W. Biederman15e47302012-09-07 20:12:54 +000011935 u32 nlportid = ACCESS_ONCE(wdev->ap_unexpected_nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011936
Eric W. Biederman15e47302012-09-07 20:12:54 +000011937 if (!nlportid)
Johannes Berg28946da2011-11-04 11:18:12 +010011938 return false;
11939
11940 msg = nlmsg_new(100, gfp);
11941 if (!msg)
11942 return true;
11943
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011944 hdr = nl80211hdr_put(msg, 0, 0, 0, cmd);
Johannes Berg28946da2011-11-04 11:18:12 +010011945 if (!hdr) {
11946 nlmsg_free(msg);
11947 return true;
11948 }
11949
David S. Miller9360ffd2012-03-29 04:41:26 -040011950 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
11951 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
11952 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
11953 goto nla_put_failure;
Johannes Berg28946da2011-11-04 11:18:12 +010011954
Johannes Berg9c90a9f2013-06-04 12:46:03 +020011955 genlmsg_end(msg, hdr);
Eric W. Biederman15e47302012-09-07 20:12:54 +000011956 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Johannes Berg28946da2011-11-04 11:18:12 +010011957 return true;
11958
11959 nla_put_failure:
11960 genlmsg_cancel(msg, hdr);
11961 nlmsg_free(msg);
11962 return true;
11963}
11964
Johannes Berg947add32013-02-22 22:05:20 +010011965bool cfg80211_rx_spurious_frame(struct net_device *dev,
11966 const u8 *addr, gfp_t gfp)
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011967{
Johannes Berg947add32013-02-22 22:05:20 +010011968 struct wireless_dev *wdev = dev->ieee80211_ptr;
11969 bool ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011970
Johannes Berg947add32013-02-22 22:05:20 +010011971 trace_cfg80211_rx_spurious_frame(dev, addr);
11972
11973 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11974 wdev->iftype != NL80211_IFTYPE_P2P_GO)) {
11975 trace_cfg80211_return_bool(false);
11976 return false;
11977 }
11978 ret = __nl80211_unexpected_frame(dev, NL80211_CMD_UNEXPECTED_FRAME,
11979 addr, gfp);
11980 trace_cfg80211_return_bool(ret);
11981 return ret;
Johannes Bergb92ab5d2011-11-04 11:18:19 +010011982}
Johannes Berg947add32013-02-22 22:05:20 +010011983EXPORT_SYMBOL(cfg80211_rx_spurious_frame);
11984
11985bool cfg80211_rx_unexpected_4addr_frame(struct net_device *dev,
11986 const u8 *addr, gfp_t gfp)
11987{
11988 struct wireless_dev *wdev = dev->ieee80211_ptr;
11989 bool ret;
11990
11991 trace_cfg80211_rx_unexpected_4addr_frame(dev, addr);
11992
11993 if (WARN_ON(wdev->iftype != NL80211_IFTYPE_AP &&
11994 wdev->iftype != NL80211_IFTYPE_P2P_GO &&
11995 wdev->iftype != NL80211_IFTYPE_AP_VLAN)) {
11996 trace_cfg80211_return_bool(false);
11997 return false;
11998 }
11999 ret = __nl80211_unexpected_frame(dev,
12000 NL80211_CMD_UNEXPECTED_4ADDR_FRAME,
12001 addr, gfp);
12002 trace_cfg80211_return_bool(ret);
12003 return ret;
12004}
12005EXPORT_SYMBOL(cfg80211_rx_unexpected_4addr_frame);
Johannes Bergb92ab5d2011-11-04 11:18:19 +010012006
Johannes Berg2e161f72010-08-12 15:38:38 +020012007int nl80211_send_mgmt(struct cfg80211_registered_device *rdev,
Eric W. Biederman15e47302012-09-07 20:12:54 +000012008 struct wireless_dev *wdev, u32 nlportid,
Johannes Berg804483e2012-03-05 22:18:41 +010012009 int freq, int sig_dbm,
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012010 const u8 *buf, size_t len, u32 flags, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012011{
Johannes Berg71bbc992012-06-15 15:30:18 +020012012 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012013 struct sk_buff *msg;
12014 void *hdr;
Jouni Malinen026331c2010-02-15 12:53:10 +020012015
12016 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12017 if (!msg)
12018 return -ENOMEM;
12019
Johannes Berg2e161f72010-08-12 15:38:38 +020012020 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
Jouni Malinen026331c2010-02-15 12:53:10 +020012021 if (!hdr) {
12022 nlmsg_free(msg);
12023 return -ENOMEM;
12024 }
12025
David S. Miller9360ffd2012-03-29 04:41:26 -040012026 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012027 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12028 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012029 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012030 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
12031 (sig_dbm &&
12032 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
Vladimir Kondratiev19504cf2013-08-15 14:51:28 +030012033 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12034 (flags &&
12035 nla_put_u32(msg, NL80211_ATTR_RXMGMT_FLAGS, flags)))
David S. Miller9360ffd2012-03-29 04:41:26 -040012036 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012037
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012038 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012039
Eric W. Biederman15e47302012-09-07 20:12:54 +000012040 return genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
Jouni Malinen026331c2010-02-15 12:53:10 +020012041
12042 nla_put_failure:
12043 genlmsg_cancel(msg, hdr);
12044 nlmsg_free(msg);
12045 return -ENOBUFS;
12046}
12047
Johannes Berg947add32013-02-22 22:05:20 +010012048void cfg80211_mgmt_tx_status(struct wireless_dev *wdev, u64 cookie,
12049 const u8 *buf, size_t len, bool ack, gfp_t gfp)
Jouni Malinen026331c2010-02-15 12:53:10 +020012050{
Johannes Berg947add32013-02-22 22:05:20 +010012051 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012052 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +020012053 struct net_device *netdev = wdev->netdev;
Jouni Malinen026331c2010-02-15 12:53:10 +020012054 struct sk_buff *msg;
12055 void *hdr;
12056
Johannes Berg947add32013-02-22 22:05:20 +010012057 trace_cfg80211_mgmt_tx_status(wdev, cookie, ack);
12058
Jouni Malinen026331c2010-02-15 12:53:10 +020012059 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12060 if (!msg)
12061 return;
12062
Johannes Berg2e161f72010-08-12 15:38:38 +020012063 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME_TX_STATUS);
Jouni Malinen026331c2010-02-15 12:53:10 +020012064 if (!hdr) {
12065 nlmsg_free(msg);
12066 return;
12067 }
12068
David S. Miller9360ffd2012-03-29 04:41:26 -040012069 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg71bbc992012-06-15 15:30:18 +020012070 (netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12071 netdev->ifindex)) ||
Ilan Peera8384902013-05-08 16:35:55 +030012072 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)) ||
David S. Miller9360ffd2012-03-29 04:41:26 -040012073 nla_put(msg, NL80211_ATTR_FRAME, len, buf) ||
12074 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12075 (ack && nla_put_flag(msg, NL80211_ATTR_ACK)))
12076 goto nla_put_failure;
Jouni Malinen026331c2010-02-15 12:53:10 +020012077
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012078 genlmsg_end(msg, hdr);
Jouni Malinen026331c2010-02-15 12:53:10 +020012079
Johannes Berg68eb5502013-11-19 15:19:38 +010012080 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012081 NL80211_MCGRP_MLME, gfp);
Jouni Malinen026331c2010-02-15 12:53:10 +020012082 return;
12083
12084 nla_put_failure:
12085 genlmsg_cancel(msg, hdr);
12086 nlmsg_free(msg);
12087}
Johannes Berg947add32013-02-22 22:05:20 +010012088EXPORT_SYMBOL(cfg80211_mgmt_tx_status);
Jouni Malinen026331c2010-02-15 12:53:10 +020012089
Johannes Berg5b97f492014-11-26 12:37:43 +010012090static struct sk_buff *cfg80211_prepare_cqm(struct net_device *dev,
12091 const char *mac, gfp_t gfp)
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012092{
Johannes Berg947add32013-02-22 22:05:20 +010012093 struct wireless_dev *wdev = dev->ieee80211_ptr;
Johannes Berg5b97f492014-11-26 12:37:43 +010012094 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
12095 struct sk_buff *msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12096 void **cb;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012097
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012098 if (!msg)
Johannes Berg5b97f492014-11-26 12:37:43 +010012099 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012100
Johannes Berg5b97f492014-11-26 12:37:43 +010012101 cb = (void **)msg->cb;
12102
12103 cb[0] = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_NOTIFY_CQM);
12104 if (!cb[0]) {
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012105 nlmsg_free(msg);
Johannes Berg5b97f492014-11-26 12:37:43 +010012106 return NULL;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012107 }
12108
David S. Miller9360ffd2012-03-29 04:41:26 -040012109 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
Johannes Berg947add32013-02-22 22:05:20 +010012110 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex))
David S. Miller9360ffd2012-03-29 04:41:26 -040012111 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012112
Johannes Berg5b97f492014-11-26 12:37:43 +010012113 if (mac && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, mac))
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012114 goto nla_put_failure;
12115
Johannes Berg5b97f492014-11-26 12:37:43 +010012116 cb[1] = nla_nest_start(msg, NL80211_ATTR_CQM);
12117 if (!cb[1])
12118 goto nla_put_failure;
12119
12120 cb[2] = rdev;
12121
12122 return msg;
12123 nla_put_failure:
12124 nlmsg_free(msg);
12125 return NULL;
12126}
12127
12128static void cfg80211_send_cqm(struct sk_buff *msg, gfp_t gfp)
12129{
12130 void **cb = (void **)msg->cb;
12131 struct cfg80211_registered_device *rdev = cb[2];
12132
12133 nla_nest_end(msg, cb[1]);
12134 genlmsg_end(msg, cb[0]);
12135
12136 memset(msg->cb, 0, sizeof(msg->cb));
12137
12138 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
12139 NL80211_MCGRP_MLME, gfp);
12140}
12141
12142void cfg80211_cqm_rssi_notify(struct net_device *dev,
12143 enum nl80211_cqm_rssi_threshold_event rssi_event,
12144 gfp_t gfp)
12145{
12146 struct sk_buff *msg;
12147
12148 trace_cfg80211_cqm_rssi_notify(dev, rssi_event);
12149
Johannes Berg98f03342014-11-26 12:42:02 +010012150 if (WARN_ON(rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW &&
12151 rssi_event != NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH))
12152 return;
12153
Johannes Berg5b97f492014-11-26 12:37:43 +010012154 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12155 if (!msg)
12156 return;
12157
David S. Miller9360ffd2012-03-29 04:41:26 -040012158 if (nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THRESHOLD_EVENT,
12159 rssi_event))
12160 goto nla_put_failure;
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012161
Johannes Berg5b97f492014-11-26 12:37:43 +010012162 cfg80211_send_cqm(msg, gfp);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012163
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012164 return;
12165
12166 nla_put_failure:
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012167 nlmsg_free(msg);
12168}
Johannes Berg947add32013-02-22 22:05:20 +010012169EXPORT_SYMBOL(cfg80211_cqm_rssi_notify);
Juuso Oikarinend6dc1a32010-03-23 09:02:33 +020012170
Johannes Berg5b97f492014-11-26 12:37:43 +010012171void cfg80211_cqm_txe_notify(struct net_device *dev,
12172 const u8 *peer, u32 num_packets,
12173 u32 rate, u32 intvl, gfp_t gfp)
12174{
12175 struct sk_buff *msg;
12176
12177 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12178 if (!msg)
12179 return;
12180
12181 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_PKTS, num_packets))
12182 goto nla_put_failure;
12183
12184 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_RATE, rate))
12185 goto nla_put_failure;
12186
12187 if (nla_put_u32(msg, NL80211_ATTR_CQM_TXE_INTVL, intvl))
12188 goto nla_put_failure;
12189
12190 cfg80211_send_cqm(msg, gfp);
12191 return;
12192
12193 nla_put_failure:
12194 nlmsg_free(msg);
12195}
12196EXPORT_SYMBOL(cfg80211_cqm_txe_notify);
12197
12198void cfg80211_cqm_pktloss_notify(struct net_device *dev,
12199 const u8 *peer, u32 num_packets, gfp_t gfp)
12200{
12201 struct sk_buff *msg;
12202
12203 trace_cfg80211_cqm_pktloss_notify(dev, peer, num_packets);
12204
12205 msg = cfg80211_prepare_cqm(dev, peer, gfp);
12206 if (!msg)
12207 return;
12208
12209 if (nla_put_u32(msg, NL80211_ATTR_CQM_PKT_LOSS_EVENT, num_packets))
12210 goto nla_put_failure;
12211
12212 cfg80211_send_cqm(msg, gfp);
12213 return;
12214
12215 nla_put_failure:
12216 nlmsg_free(msg);
12217}
12218EXPORT_SYMBOL(cfg80211_cqm_pktloss_notify);
12219
Johannes Berg98f03342014-11-26 12:42:02 +010012220void cfg80211_cqm_beacon_loss_notify(struct net_device *dev, gfp_t gfp)
12221{
12222 struct sk_buff *msg;
12223
12224 msg = cfg80211_prepare_cqm(dev, NULL, gfp);
12225 if (!msg)
12226 return;
12227
12228 if (nla_put_flag(msg, NL80211_ATTR_CQM_BEACON_LOSS_EVENT))
12229 goto nla_put_failure;
12230
12231 cfg80211_send_cqm(msg, gfp);
12232 return;
12233
12234 nla_put_failure:
12235 nlmsg_free(msg);
12236}
12237EXPORT_SYMBOL(cfg80211_cqm_beacon_loss_notify);
12238
Johannes Berg947add32013-02-22 22:05:20 +010012239static void nl80211_gtk_rekey_notify(struct cfg80211_registered_device *rdev,
12240 struct net_device *netdev, const u8 *bssid,
12241 const u8 *replay_ctr, gfp_t gfp)
Johannes Berge5497d72011-07-05 16:35:40 +020012242{
12243 struct sk_buff *msg;
12244 struct nlattr *rekey_attr;
12245 void *hdr;
12246
Thomas Graf58050fc2012-06-28 03:57:45 +000012247 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012248 if (!msg)
12249 return;
12250
12251 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_REKEY_OFFLOAD);
12252 if (!hdr) {
12253 nlmsg_free(msg);
12254 return;
12255 }
12256
David S. Miller9360ffd2012-03-29 04:41:26 -040012257 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12258 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12259 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))
12260 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012261
12262 rekey_attr = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA);
12263 if (!rekey_attr)
12264 goto nla_put_failure;
12265
David S. Miller9360ffd2012-03-29 04:41:26 -040012266 if (nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR,
12267 NL80211_REPLAY_CTR_LEN, replay_ctr))
12268 goto nla_put_failure;
Johannes Berge5497d72011-07-05 16:35:40 +020012269
12270 nla_nest_end(msg, rekey_attr);
12271
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012272 genlmsg_end(msg, hdr);
Johannes Berge5497d72011-07-05 16:35:40 +020012273
Johannes Berg68eb5502013-11-19 15:19:38 +010012274 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012275 NL80211_MCGRP_MLME, gfp);
Johannes Berge5497d72011-07-05 16:35:40 +020012276 return;
12277
12278 nla_put_failure:
12279 genlmsg_cancel(msg, hdr);
12280 nlmsg_free(msg);
12281}
12282
Johannes Berg947add32013-02-22 22:05:20 +010012283void cfg80211_gtk_rekey_notify(struct net_device *dev, const u8 *bssid,
12284 const u8 *replay_ctr, gfp_t gfp)
12285{
12286 struct wireless_dev *wdev = dev->ieee80211_ptr;
12287 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012288 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012289
12290 trace_cfg80211_gtk_rekey_notify(dev, bssid);
12291 nl80211_gtk_rekey_notify(rdev, dev, bssid, replay_ctr, gfp);
12292}
12293EXPORT_SYMBOL(cfg80211_gtk_rekey_notify);
12294
12295static void
12296nl80211_pmksa_candidate_notify(struct cfg80211_registered_device *rdev,
12297 struct net_device *netdev, int index,
12298 const u8 *bssid, bool preauth, gfp_t gfp)
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012299{
12300 struct sk_buff *msg;
12301 struct nlattr *attr;
12302 void *hdr;
12303
Thomas Graf58050fc2012-06-28 03:57:45 +000012304 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012305 if (!msg)
12306 return;
12307
12308 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PMKSA_CANDIDATE);
12309 if (!hdr) {
12310 nlmsg_free(msg);
12311 return;
12312 }
12313
David S. Miller9360ffd2012-03-29 04:41:26 -040012314 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12315 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12316 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012317
12318 attr = nla_nest_start(msg, NL80211_ATTR_PMKSA_CANDIDATE);
12319 if (!attr)
12320 goto nla_put_failure;
12321
David S. Miller9360ffd2012-03-29 04:41:26 -040012322 if (nla_put_u32(msg, NL80211_PMKSA_CANDIDATE_INDEX, index) ||
12323 nla_put(msg, NL80211_PMKSA_CANDIDATE_BSSID, ETH_ALEN, bssid) ||
12324 (preauth &&
12325 nla_put_flag(msg, NL80211_PMKSA_CANDIDATE_PREAUTH)))
12326 goto nla_put_failure;
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012327
12328 nla_nest_end(msg, attr);
12329
Johannes Berg3b7b72e2011-10-22 19:05:51 +020012330 genlmsg_end(msg, hdr);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012331
Johannes Berg68eb5502013-11-19 15:19:38 +010012332 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012333 NL80211_MCGRP_MLME, gfp);
Jouni Malinenc9df56b2011-09-16 18:56:23 +030012334 return;
12335
12336 nla_put_failure:
12337 genlmsg_cancel(msg, hdr);
12338 nlmsg_free(msg);
12339}
12340
Johannes Berg947add32013-02-22 22:05:20 +010012341void cfg80211_pmksa_candidate_notify(struct net_device *dev, int index,
12342 const u8 *bssid, bool preauth, gfp_t gfp)
12343{
12344 struct wireless_dev *wdev = dev->ieee80211_ptr;
12345 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012346 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012347
12348 trace_cfg80211_pmksa_candidate_notify(dev, index, bssid, preauth);
12349 nl80211_pmksa_candidate_notify(rdev, dev, index, bssid, preauth, gfp);
12350}
12351EXPORT_SYMBOL(cfg80211_pmksa_candidate_notify);
12352
12353static void nl80211_ch_switch_notify(struct cfg80211_registered_device *rdev,
12354 struct net_device *netdev,
12355 struct cfg80211_chan_def *chandef,
Luciano Coelhof8d75522014-11-07 14:31:35 +020012356 gfp_t gfp,
12357 enum nl80211_commands notif,
12358 u8 count)
Thomas Pedersen53145262012-04-06 13:35:47 -070012359{
12360 struct sk_buff *msg;
12361 void *hdr;
12362
Thomas Graf58050fc2012-06-28 03:57:45 +000012363 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012364 if (!msg)
12365 return;
12366
Luciano Coelhof8d75522014-11-07 14:31:35 +020012367 hdr = nl80211hdr_put(msg, 0, 0, 0, notif);
Thomas Pedersen53145262012-04-06 13:35:47 -070012368 if (!hdr) {
12369 nlmsg_free(msg);
12370 return;
12371 }
12372
Johannes Berg683b6d32012-11-08 21:25:48 +010012373 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex))
12374 goto nla_put_failure;
12375
12376 if (nl80211_send_chandef(msg, chandef))
John W. Linville7eab0f62012-04-12 14:25:14 -040012377 goto nla_put_failure;
Thomas Pedersen53145262012-04-06 13:35:47 -070012378
Luciano Coelhof8d75522014-11-07 14:31:35 +020012379 if ((notif == NL80211_CMD_CH_SWITCH_STARTED_NOTIFY) &&
12380 (nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, count)))
12381 goto nla_put_failure;
12382
Thomas Pedersen53145262012-04-06 13:35:47 -070012383 genlmsg_end(msg, hdr);
12384
Johannes Berg68eb5502013-11-19 15:19:38 +010012385 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012386 NL80211_MCGRP_MLME, gfp);
Thomas Pedersen53145262012-04-06 13:35:47 -070012387 return;
12388
12389 nla_put_failure:
12390 genlmsg_cancel(msg, hdr);
12391 nlmsg_free(msg);
12392}
12393
Johannes Berg947add32013-02-22 22:05:20 +010012394void cfg80211_ch_switch_notify(struct net_device *dev,
12395 struct cfg80211_chan_def *chandef)
Thomas Pedersen84f10702012-07-12 16:17:33 -070012396{
Johannes Berg947add32013-02-22 22:05:20 +010012397 struct wireless_dev *wdev = dev->ieee80211_ptr;
12398 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012399 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg947add32013-02-22 22:05:20 +010012400
Simon Wunderliche487eae2013-11-21 18:19:51 +010012401 ASSERT_WDEV_LOCK(wdev);
Johannes Berg947add32013-02-22 22:05:20 +010012402
Simon Wunderliche487eae2013-11-21 18:19:51 +010012403 trace_cfg80211_ch_switch_notify(dev, chandef);
Johannes Berg947add32013-02-22 22:05:20 +010012404
Michal Kazior9e0e2962014-01-29 14:22:27 +010012405 wdev->chandef = *chandef;
Janusz Dziedzic96f55f12014-01-24 14:29:21 +010012406 wdev->preset_chandef = *chandef;
Luciano Coelhof8d75522014-11-07 14:31:35 +020012407 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12408 NL80211_CMD_CH_SWITCH_NOTIFY, 0);
Johannes Berg947add32013-02-22 22:05:20 +010012409}
12410EXPORT_SYMBOL(cfg80211_ch_switch_notify);
12411
Luciano Coelhof8d75522014-11-07 14:31:35 +020012412void cfg80211_ch_switch_started_notify(struct net_device *dev,
12413 struct cfg80211_chan_def *chandef,
12414 u8 count)
12415{
12416 struct wireless_dev *wdev = dev->ieee80211_ptr;
12417 struct wiphy *wiphy = wdev->wiphy;
12418 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
12419
12420 trace_cfg80211_ch_switch_started_notify(dev, chandef);
12421
12422 nl80211_ch_switch_notify(rdev, dev, chandef, GFP_KERNEL,
12423 NL80211_CMD_CH_SWITCH_STARTED_NOTIFY, count);
12424}
12425EXPORT_SYMBOL(cfg80211_ch_switch_started_notify);
12426
Thomas Pedersen84f10702012-07-12 16:17:33 -070012427void
Simon Wunderlich04f39042013-02-08 18:16:19 +010012428nl80211_radar_notify(struct cfg80211_registered_device *rdev,
Janusz Dziedzicd2859df2013-11-06 13:55:51 +010012429 const struct cfg80211_chan_def *chandef,
Simon Wunderlich04f39042013-02-08 18:16:19 +010012430 enum nl80211_radar_event event,
12431 struct net_device *netdev, gfp_t gfp)
12432{
12433 struct sk_buff *msg;
12434 void *hdr;
12435
12436 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12437 if (!msg)
12438 return;
12439
12440 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_RADAR_DETECT);
12441 if (!hdr) {
12442 nlmsg_free(msg);
12443 return;
12444 }
12445
12446 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx))
12447 goto nla_put_failure;
12448
12449 /* NOP and radar events don't need a netdev parameter */
12450 if (netdev) {
12451 struct wireless_dev *wdev = netdev->ieee80211_ptr;
12452
12453 if (nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12454 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12455 goto nla_put_failure;
12456 }
12457
12458 if (nla_put_u32(msg, NL80211_ATTR_RADAR_EVENT, event))
12459 goto nla_put_failure;
12460
12461 if (nl80211_send_chandef(msg, chandef))
12462 goto nla_put_failure;
12463
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012464 genlmsg_end(msg, hdr);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012465
Johannes Berg68eb5502013-11-19 15:19:38 +010012466 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012467 NL80211_MCGRP_MLME, gfp);
Simon Wunderlich04f39042013-02-08 18:16:19 +010012468 return;
12469
12470 nla_put_failure:
12471 genlmsg_cancel(msg, hdr);
12472 nlmsg_free(msg);
12473}
12474
Johannes Berg7f6cf312011-11-04 11:18:15 +010012475void cfg80211_probe_status(struct net_device *dev, const u8 *addr,
12476 u64 cookie, bool acked, gfp_t gfp)
12477{
12478 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012479 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012480 struct sk_buff *msg;
12481 void *hdr;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012482
Beni Lev4ee3e062012-08-27 12:49:39 +030012483 trace_cfg80211_probe_status(dev, addr, cookie, acked);
12484
Thomas Graf58050fc2012-06-28 03:57:45 +000012485 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
Beni Lev4ee3e062012-08-27 12:49:39 +030012486
Johannes Berg7f6cf312011-11-04 11:18:15 +010012487 if (!msg)
12488 return;
12489
12490 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_PROBE_CLIENT);
12491 if (!hdr) {
12492 nlmsg_free(msg);
12493 return;
12494 }
12495
David S. Miller9360ffd2012-03-29 04:41:26 -040012496 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12497 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12498 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
12499 nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie) ||
12500 (acked && nla_put_flag(msg, NL80211_ATTR_ACK)))
12501 goto nla_put_failure;
Johannes Berg7f6cf312011-11-04 11:18:15 +010012502
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012503 genlmsg_end(msg, hdr);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012504
Johannes Berg68eb5502013-11-19 15:19:38 +010012505 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012506 NL80211_MCGRP_MLME, gfp);
Johannes Berg7f6cf312011-11-04 11:18:15 +010012507 return;
12508
12509 nla_put_failure:
12510 genlmsg_cancel(msg, hdr);
12511 nlmsg_free(msg);
12512}
12513EXPORT_SYMBOL(cfg80211_probe_status);
12514
Johannes Berg5e760232011-11-04 11:18:17 +010012515void cfg80211_report_obss_beacon(struct wiphy *wiphy,
12516 const u8 *frame, size_t len,
Ben Greear37c73b52012-10-26 14:49:25 -070012517 int freq, int sig_dbm)
Johannes Berg5e760232011-11-04 11:18:17 +010012518{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012519 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg5e760232011-11-04 11:18:17 +010012520 struct sk_buff *msg;
12521 void *hdr;
Ben Greear37c73b52012-10-26 14:49:25 -070012522 struct cfg80211_beacon_registration *reg;
Johannes Berg5e760232011-11-04 11:18:17 +010012523
Beni Lev4ee3e062012-08-27 12:49:39 +030012524 trace_cfg80211_report_obss_beacon(wiphy, frame, len, freq, sig_dbm);
12525
Ben Greear37c73b52012-10-26 14:49:25 -070012526 spin_lock_bh(&rdev->beacon_registrations_lock);
12527 list_for_each_entry(reg, &rdev->beacon_registrations, list) {
12528 msg = nlmsg_new(len + 100, GFP_ATOMIC);
12529 if (!msg) {
12530 spin_unlock_bh(&rdev->beacon_registrations_lock);
12531 return;
12532 }
Johannes Berg5e760232011-11-04 11:18:17 +010012533
Ben Greear37c73b52012-10-26 14:49:25 -070012534 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FRAME);
12535 if (!hdr)
12536 goto nla_put_failure;
Johannes Berg5e760232011-11-04 11:18:17 +010012537
Ben Greear37c73b52012-10-26 14:49:25 -070012538 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12539 (freq &&
12540 nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
12541 (sig_dbm &&
12542 nla_put_u32(msg, NL80211_ATTR_RX_SIGNAL_DBM, sig_dbm)) ||
12543 nla_put(msg, NL80211_ATTR_FRAME, len, frame))
12544 goto nla_put_failure;
12545
12546 genlmsg_end(msg, hdr);
12547
12548 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, reg->nlportid);
Johannes Berg5e760232011-11-04 11:18:17 +010012549 }
Ben Greear37c73b52012-10-26 14:49:25 -070012550 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg5e760232011-11-04 11:18:17 +010012551 return;
12552
12553 nla_put_failure:
Ben Greear37c73b52012-10-26 14:49:25 -070012554 spin_unlock_bh(&rdev->beacon_registrations_lock);
12555 if (hdr)
12556 genlmsg_cancel(msg, hdr);
Johannes Berg5e760232011-11-04 11:18:17 +010012557 nlmsg_free(msg);
12558}
12559EXPORT_SYMBOL(cfg80211_report_obss_beacon);
12560
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012561#ifdef CONFIG_PM
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012562static int cfg80211_net_detect_results(struct sk_buff *msg,
12563 struct cfg80211_wowlan_wakeup *wakeup)
12564{
12565 struct cfg80211_wowlan_nd_info *nd = wakeup->net_detect;
12566 struct nlattr *nl_results, *nl_match, *nl_freqs;
12567 int i, j;
12568
12569 nl_results = nla_nest_start(
12570 msg, NL80211_WOWLAN_TRIG_NET_DETECT_RESULTS);
12571 if (!nl_results)
12572 return -EMSGSIZE;
12573
12574 for (i = 0; i < nd->n_matches; i++) {
12575 struct cfg80211_wowlan_nd_match *match = nd->matches[i];
12576
12577 nl_match = nla_nest_start(msg, i);
12578 if (!nl_match)
12579 break;
12580
12581 /* The SSID attribute is optional in nl80211, but for
12582 * simplicity reasons it's always present in the
12583 * cfg80211 structure. If a driver can't pass the
12584 * SSID, that needs to be changed. A zero length SSID
12585 * is still a valid SSID (wildcard), so it cannot be
12586 * used for this purpose.
12587 */
12588 if (nla_put(msg, NL80211_ATTR_SSID, match->ssid.ssid_len,
12589 match->ssid.ssid)) {
12590 nla_nest_cancel(msg, nl_match);
12591 goto out;
12592 }
12593
12594 if (match->n_channels) {
12595 nl_freqs = nla_nest_start(
12596 msg, NL80211_ATTR_SCAN_FREQUENCIES);
12597 if (!nl_freqs) {
12598 nla_nest_cancel(msg, nl_match);
12599 goto out;
12600 }
12601
12602 for (j = 0; j < match->n_channels; j++) {
Samuel Tan5528fae82015-02-09 21:29:15 +020012603 if (nla_put_u32(msg, j, match->channels[j])) {
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012604 nla_nest_cancel(msg, nl_freqs);
12605 nla_nest_cancel(msg, nl_match);
12606 goto out;
12607 }
12608 }
12609
12610 nla_nest_end(msg, nl_freqs);
12611 }
12612
12613 nla_nest_end(msg, nl_match);
12614 }
12615
12616out:
12617 nla_nest_end(msg, nl_results);
12618 return 0;
12619}
12620
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012621void cfg80211_report_wowlan_wakeup(struct wireless_dev *wdev,
12622 struct cfg80211_wowlan_wakeup *wakeup,
12623 gfp_t gfp)
12624{
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012625 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012626 struct sk_buff *msg;
12627 void *hdr;
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012628 int size = 200;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012629
12630 trace_cfg80211_report_wowlan_wakeup(wdev->wiphy, wdev, wakeup);
12631
12632 if (wakeup)
12633 size += wakeup->packet_present_len;
12634
12635 msg = nlmsg_new(size, gfp);
12636 if (!msg)
12637 return;
12638
12639 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_SET_WOWLAN);
12640 if (!hdr)
12641 goto free_msg;
12642
12643 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12644 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12645 goto free_msg;
12646
12647 if (wdev->netdev && nla_put_u32(msg, NL80211_ATTR_IFINDEX,
12648 wdev->netdev->ifindex))
12649 goto free_msg;
12650
12651 if (wakeup) {
12652 struct nlattr *reasons;
12653
12654 reasons = nla_nest_start(msg, NL80211_ATTR_WOWLAN_TRIGGERS);
Johannes Berg7fa322c2013-10-25 11:16:58 +020012655 if (!reasons)
12656 goto free_msg;
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012657
12658 if (wakeup->disconnect &&
12659 nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT))
12660 goto free_msg;
12661 if (wakeup->magic_pkt &&
12662 nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT))
12663 goto free_msg;
12664 if (wakeup->gtk_rekey_failure &&
12665 nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE))
12666 goto free_msg;
12667 if (wakeup->eap_identity_req &&
12668 nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST))
12669 goto free_msg;
12670 if (wakeup->four_way_handshake &&
12671 nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE))
12672 goto free_msg;
12673 if (wakeup->rfkill_release &&
12674 nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))
12675 goto free_msg;
12676
12677 if (wakeup->pattern_idx >= 0 &&
12678 nla_put_u32(msg, NL80211_WOWLAN_TRIG_PKT_PATTERN,
12679 wakeup->pattern_idx))
12680 goto free_msg;
12681
Johannes Bergae917c92013-10-25 11:05:22 +020012682 if (wakeup->tcp_match &&
12683 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_MATCH))
12684 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012685
Johannes Bergae917c92013-10-25 11:05:22 +020012686 if (wakeup->tcp_connlost &&
12687 nla_put_flag(msg, NL80211_WOWLAN_TRIG_WAKEUP_TCP_CONNLOST))
12688 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012689
Johannes Bergae917c92013-10-25 11:05:22 +020012690 if (wakeup->tcp_nomoretokens &&
12691 nla_put_flag(msg,
12692 NL80211_WOWLAN_TRIG_WAKEUP_TCP_NOMORETOKENS))
12693 goto free_msg;
Johannes Berg2a0e0472013-01-23 22:57:40 +010012694
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012695 if (wakeup->packet) {
12696 u32 pkt_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211;
12697 u32 len_attr = NL80211_WOWLAN_TRIG_WAKEUP_PKT_80211_LEN;
12698
12699 if (!wakeup->packet_80211) {
12700 pkt_attr =
12701 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023;
12702 len_attr =
12703 NL80211_WOWLAN_TRIG_WAKEUP_PKT_8023_LEN;
12704 }
12705
12706 if (wakeup->packet_len &&
12707 nla_put_u32(msg, len_attr, wakeup->packet_len))
12708 goto free_msg;
12709
12710 if (nla_put(msg, pkt_attr, wakeup->packet_present_len,
12711 wakeup->packet))
12712 goto free_msg;
12713 }
12714
Luciano Coelho8cd4d452014-09-17 11:55:28 +030012715 if (wakeup->net_detect &&
12716 cfg80211_net_detect_results(msg, wakeup))
12717 goto free_msg;
12718
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012719 nla_nest_end(msg, reasons);
12720 }
12721
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012722 genlmsg_end(msg, hdr);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012723
Johannes Berg68eb5502013-11-19 15:19:38 +010012724 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012725 NL80211_MCGRP_MLME, gfp);
Johannes Bergcd8f7cb2013-01-22 12:34:29 +010012726 return;
12727
12728 free_msg:
12729 nlmsg_free(msg);
12730}
12731EXPORT_SYMBOL(cfg80211_report_wowlan_wakeup);
12732#endif
12733
Jouni Malinen3475b092012-11-16 22:49:57 +020012734void cfg80211_tdls_oper_request(struct net_device *dev, const u8 *peer,
12735 enum nl80211_tdls_operation oper,
12736 u16 reason_code, gfp_t gfp)
12737{
12738 struct wireless_dev *wdev = dev->ieee80211_ptr;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012739 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
Jouni Malinen3475b092012-11-16 22:49:57 +020012740 struct sk_buff *msg;
12741 void *hdr;
Jouni Malinen3475b092012-11-16 22:49:57 +020012742
12743 trace_cfg80211_tdls_oper_request(wdev->wiphy, dev, peer, oper,
12744 reason_code);
12745
12746 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12747 if (!msg)
12748 return;
12749
12750 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_TDLS_OPER);
12751 if (!hdr) {
12752 nlmsg_free(msg);
12753 return;
12754 }
12755
12756 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12757 nla_put_u32(msg, NL80211_ATTR_IFINDEX, dev->ifindex) ||
12758 nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, oper) ||
12759 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer) ||
12760 (reason_code > 0 &&
12761 nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code)))
12762 goto nla_put_failure;
12763
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012764 genlmsg_end(msg, hdr);
Jouni Malinen3475b092012-11-16 22:49:57 +020012765
Johannes Berg68eb5502013-11-19 15:19:38 +010012766 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012767 NL80211_MCGRP_MLME, gfp);
Jouni Malinen3475b092012-11-16 22:49:57 +020012768 return;
12769
12770 nla_put_failure:
12771 genlmsg_cancel(msg, hdr);
12772 nlmsg_free(msg);
12773}
12774EXPORT_SYMBOL(cfg80211_tdls_oper_request);
12775
Jouni Malinen026331c2010-02-15 12:53:10 +020012776static int nl80211_netlink_notify(struct notifier_block * nb,
12777 unsigned long state,
12778 void *_notify)
12779{
12780 struct netlink_notify *notify = _notify;
12781 struct cfg80211_registered_device *rdev;
12782 struct wireless_dev *wdev;
Ben Greear37c73b52012-10-26 14:49:25 -070012783 struct cfg80211_beacon_registration *reg, *tmp;
Jouni Malinen026331c2010-02-15 12:53:10 +020012784
12785 if (state != NETLINK_URELEASE)
12786 return NOTIFY_DONE;
12787
12788 rcu_read_lock();
12789
Johannes Berg5e760232011-11-04 11:18:17 +010012790 list_for_each_entry_rcu(rdev, &cfg80211_rdev_list, list) {
Johannes Berg78f22b62014-03-24 17:57:27 +010012791 bool schedule_destroy_work = false;
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012792 bool schedule_scan_stop = false;
12793 struct cfg80211_sched_scan_request *sched_scan_req =
12794 rcu_dereference(rdev->sched_scan_req);
12795
12796 if (sched_scan_req && notify->portid &&
12797 sched_scan_req->owner_nlportid == notify->portid)
12798 schedule_scan_stop = true;
Johannes Berg78f22b62014-03-24 17:57:27 +010012799
12800 list_for_each_entry_rcu(wdev, &rdev->wdev_list, list) {
Eric W. Biederman15e47302012-09-07 20:12:54 +000012801 cfg80211_mlme_unregister_socket(wdev, notify->portid);
Ben Greear37c73b52012-10-26 14:49:25 -070012802
Johannes Berg78f22b62014-03-24 17:57:27 +010012803 if (wdev->owner_nlportid == notify->portid)
12804 schedule_destroy_work = true;
12805 }
12806
Ben Greear37c73b52012-10-26 14:49:25 -070012807 spin_lock_bh(&rdev->beacon_registrations_lock);
12808 list_for_each_entry_safe(reg, tmp, &rdev->beacon_registrations,
12809 list) {
12810 if (reg->nlportid == notify->portid) {
12811 list_del(&reg->list);
12812 kfree(reg);
12813 break;
12814 }
12815 }
12816 spin_unlock_bh(&rdev->beacon_registrations_lock);
Johannes Berg78f22b62014-03-24 17:57:27 +010012817
12818 if (schedule_destroy_work) {
12819 struct cfg80211_iface_destroy *destroy;
12820
12821 destroy = kzalloc(sizeof(*destroy), GFP_ATOMIC);
12822 if (destroy) {
12823 destroy->nlportid = notify->portid;
12824 spin_lock(&rdev->destroy_list_lock);
12825 list_add(&destroy->list, &rdev->destroy_list);
12826 spin_unlock(&rdev->destroy_list_lock);
12827 schedule_work(&rdev->destroy_work);
12828 }
Jukka Rissanen93a1e862014-12-15 13:25:39 +020012829 } else if (schedule_scan_stop) {
12830 sched_scan_req->owner_nlportid = 0;
12831
12832 if (rdev->ops->sched_scan_stop &&
12833 rdev->wiphy.flags & WIPHY_FLAG_SUPPORTS_SCHED_SCAN)
12834 schedule_work(&rdev->sched_scan_stop_wk);
Johannes Berg78f22b62014-03-24 17:57:27 +010012835 }
Johannes Berg5e760232011-11-04 11:18:17 +010012836 }
Jouni Malinen026331c2010-02-15 12:53:10 +020012837
12838 rcu_read_unlock();
12839
Ilan peer05050752015-03-04 00:32:06 -050012840 /*
12841 * It is possible that the user space process that is controlling the
12842 * indoor setting disappeared, so notify the regulatory core.
12843 */
12844 regulatory_netlink_notify(notify->portid);
Zhao, Gang6784c7d2014-04-21 12:53:04 +080012845 return NOTIFY_OK;
Jouni Malinen026331c2010-02-15 12:53:10 +020012846}
12847
12848static struct notifier_block nl80211_netlink_notifier = {
12849 .notifier_call = nl80211_netlink_notify,
12850};
12851
Jouni Malinen355199e2013-02-27 17:14:27 +020012852void cfg80211_ft_event(struct net_device *netdev,
12853 struct cfg80211_ft_event_params *ft_event)
12854{
12855 struct wiphy *wiphy = netdev->ieee80211_ptr->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012856 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Jouni Malinen355199e2013-02-27 17:14:27 +020012857 struct sk_buff *msg;
12858 void *hdr;
Jouni Malinen355199e2013-02-27 17:14:27 +020012859
12860 trace_cfg80211_ft_event(wiphy, netdev, ft_event);
12861
12862 if (!ft_event->target_ap)
12863 return;
12864
12865 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12866 if (!msg)
12867 return;
12868
12869 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_FT_EVENT);
Johannes Bergae917c92013-10-25 11:05:22 +020012870 if (!hdr)
12871 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012872
Johannes Bergae917c92013-10-25 11:05:22 +020012873 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12874 nla_put_u32(msg, NL80211_ATTR_IFINDEX, netdev->ifindex) ||
12875 nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, ft_event->target_ap))
12876 goto out;
12877
12878 if (ft_event->ies &&
12879 nla_put(msg, NL80211_ATTR_IE, ft_event->ies_len, ft_event->ies))
12880 goto out;
12881 if (ft_event->ric_ies &&
12882 nla_put(msg, NL80211_ATTR_IE_RIC, ft_event->ric_ies_len,
12883 ft_event->ric_ies))
12884 goto out;
Jouni Malinen355199e2013-02-27 17:14:27 +020012885
Johannes Berg9c90a9f2013-06-04 12:46:03 +020012886 genlmsg_end(msg, hdr);
Jouni Malinen355199e2013-02-27 17:14:27 +020012887
Johannes Berg68eb5502013-11-19 15:19:38 +010012888 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(&rdev->wiphy), msg, 0,
Johannes Berg2a94fe42013-11-19 15:19:39 +010012889 NL80211_MCGRP_MLME, GFP_KERNEL);
Johannes Bergae917c92013-10-25 11:05:22 +020012890 return;
12891 out:
12892 nlmsg_free(msg);
Jouni Malinen355199e2013-02-27 17:14:27 +020012893}
12894EXPORT_SYMBOL(cfg80211_ft_event);
12895
Arend van Spriel5de17982013-04-18 15:49:00 +020012896void cfg80211_crit_proto_stopped(struct wireless_dev *wdev, gfp_t gfp)
12897{
12898 struct cfg80211_registered_device *rdev;
12899 struct sk_buff *msg;
12900 void *hdr;
12901 u32 nlportid;
12902
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012903 rdev = wiphy_to_rdev(wdev->wiphy);
Arend van Spriel5de17982013-04-18 15:49:00 +020012904 if (!rdev->crit_proto_nlportid)
12905 return;
12906
12907 nlportid = rdev->crit_proto_nlportid;
12908 rdev->crit_proto_nlportid = 0;
12909
12910 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, gfp);
12911 if (!msg)
12912 return;
12913
12914 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_CRIT_PROTOCOL_STOP);
12915 if (!hdr)
12916 goto nla_put_failure;
12917
12918 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12919 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12920 goto nla_put_failure;
12921
12922 genlmsg_end(msg, hdr);
12923
12924 genlmsg_unicast(wiphy_net(&rdev->wiphy), msg, nlportid);
12925 return;
12926
12927 nla_put_failure:
12928 if (hdr)
12929 genlmsg_cancel(msg, hdr);
12930 nlmsg_free(msg);
12931
12932}
12933EXPORT_SYMBOL(cfg80211_crit_proto_stopped);
12934
Johannes Berg348baf02014-01-24 14:06:29 +010012935void nl80211_send_ap_stopped(struct wireless_dev *wdev)
12936{
12937 struct wiphy *wiphy = wdev->wiphy;
Zhao, Gangf26cbf42014-04-21 12:53:03 +080012938 struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
Johannes Berg348baf02014-01-24 14:06:29 +010012939 struct sk_buff *msg;
12940 void *hdr;
12941
12942 msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL);
12943 if (!msg)
12944 return;
12945
12946 hdr = nl80211hdr_put(msg, 0, 0, 0, NL80211_CMD_STOP_AP);
12947 if (!hdr)
12948 goto out;
12949
12950 if (nla_put_u32(msg, NL80211_ATTR_WIPHY, rdev->wiphy_idx) ||
12951 nla_put_u32(msg, NL80211_ATTR_IFINDEX, wdev->netdev->ifindex) ||
12952 nla_put_u64(msg, NL80211_ATTR_WDEV, wdev_id(wdev)))
12953 goto out;
12954
12955 genlmsg_end(msg, hdr);
12956
12957 genlmsg_multicast_netns(&nl80211_fam, wiphy_net(wiphy), msg, 0,
12958 NL80211_MCGRP_MLME, GFP_KERNEL);
12959 return;
12960 out:
12961 nlmsg_free(msg);
12962}
12963
Johannes Berg55682962007-09-20 13:09:35 -040012964/* initialisation/exit functions */
12965
12966int nl80211_init(void)
12967{
Michał Mirosław0d63cbb2009-05-21 10:34:06 +000012968 int err;
Johannes Berg55682962007-09-20 13:09:35 -040012969
Johannes Berg2a94fe42013-11-19 15:19:39 +010012970 err = genl_register_family_with_ops_groups(&nl80211_fam, nl80211_ops,
12971 nl80211_mcgrps);
Johannes Berg55682962007-09-20 13:09:35 -040012972 if (err)
12973 return err;
12974
Jouni Malinen026331c2010-02-15 12:53:10 +020012975 err = netlink_register_notifier(&nl80211_netlink_notifier);
12976 if (err)
12977 goto err_out;
12978
Johannes Berg55682962007-09-20 13:09:35 -040012979 return 0;
12980 err_out:
12981 genl_unregister_family(&nl80211_fam);
12982 return err;
12983}
12984
12985void nl80211_exit(void)
12986{
Jouni Malinen026331c2010-02-15 12:53:10 +020012987 netlink_unregister_notifier(&nl80211_netlink_notifier);
Johannes Berg55682962007-09-20 13:09:35 -040012988 genl_unregister_family(&nl80211_fam);
12989}